redis(1.21)redis6.0安装

2021/7/16 19:09:58

本文主要是介绍redis(1.21)redis6.0安装,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

【1】一键安装(基于集群)

如果要装单实例,请注释掉集群参数

#!/bin/bash
source /etc/profile
usage(){
    echo $1
    echo '$#': $#
    echo "for example: sh install_redis.sh -f redis-6.2.4.tar.gz -p 6380 -d /data/redis/
-h usage
-f redis file tar.gz
-d datadir
-p port
"
}

while getopts :f:d:p:h opt
do
        case "$opt" in
                h) usage && exit ;;
                f) redis_file=$OPTARG ;;
                p) port=$OPTARG ;;
                d) datadir=$OPTARG ;;
                *) usage && exit;;
        esac
done

if [ ! $port ];then
   port=6379
fi

if [ `netstat -ano|grep ${port}|wc -l` -gt 0 ];then
echo "the port have already been used:${port}"
netstat -ano|grep ${port}
exit
fi


echo -n "check gcc......"
gcc -v >/dev/null 2>&1
if [ ! $? -eq 0  ];then
echo "None"
echo "yum -y install gcc 1>/dev/null 2>gcc_error.log......"
yum -y install gcc 1>/dev/null 2>gcc_error.log
#yum -y install tcl
fi
echo "ok"

if [ ! $datadir ];then
datadir=/data/redis/
fi

if [ ! $redis_file ] || [ ! -f $redis_file ];then
echo 'redis file option not input'
usage && exit
fi

#------------------ redis安装 ---------------------

mkdir -p ${datadir}${port}_redis
dir=`echo ${redis_file} |awk -F'.tar' '{print $1}'`

if [ ! -d $dir ];then
  tar -zxf $redis_file
  dir=`echo ${redis_file} |awk -F'.tar' '{print $1}'`
  cd $dir

  echo -n " making redis....... make 1>/dev/null 2>make_error.log"
  make 1>/dev/null 2>make_error.log
  if [ ! $? -eq 0  ];then
   echo "make  error"
   exit
  fi
  # make MALLOC=libc
  echo "ok"
  cd ./src
  make PREFIX=$datadir install 

elif [ ! -f "${dir}/src/redis-cli" ];then 
  cd $dir
    make
  if [ ! $? -eq 0  ];then
   echo "make  error"
   exit
  fi
  make PREFIX=$datadir install
  # make MALLOC=libc  
elif [ ! -f "${datadir}bin/redis-cli" ];then
 cd $dir
 make PREFIX=$datadir install
fi

if [ `echo ${PATH}|grep ${datadir}bin|wc -l` -eq 0 ];then
echo "export PATH=${PATH}:/data/redis/bin" >> /etc/profile
source /etc/profile
fi

if [ -f "${datadir}${port}_redis/${port}_redis.conf" ];then
echo "redis config file:${datadir}${port}_redis/${port}_redis.conf is already exists!Please check the file info."
exit
fi

#------------配置文件 /data/redis/redis_6379/redis_6379.conf----------
cat <<eof>>${datadir}${port}_redis/${port}_redis.conf
#network
protected-mode no
port ${port}

#general
daemonize yes
pidfile ${datadir}${port}_redis/${port}_redis.pid
supervised no
loglevel notice
logfile "${datadir}${port}_redis/${port}_redis.log"
syslog-enabled no
databases 16

#SNAPSHOTTING
save 86400 1
stop-writes-on-bgsave-error no
rdbcompression yes
dbfilename dump.rdb
dir ${datadir}${port}_redis/

requirepass 123456
masterauth 123456
#rename-command FLUSHALL 1123123_FLUSHALL
#rename-command FLUSHDB  1124124_FLUSHDB
#rename-command CONFIG   1123123_CONFIG

#replication
#slaveof 180.153.250.135 ${port}
#slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100

#io thread
io-threads 4
# 开启 4 个 IO 线程
io-threads-do-reads yes
#读请求解析也是用 IO 线程


#limit
maxclients 10000
maxmemory 100gb
maxmemory-policy allkeys-lru

#append only mode
appendonly yes
appendfsync no
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100

#cluster
cluster-enabled yes
    #-- 允许实例加入集群
cluster-config-file nodes-${port}.conf
    #-- 每个加入群集的实例都会有一个
cluster-node-timeout 15000
    #-- ms,节点响应超时
cluster-replica-validity-factor 10
    #-- 这个系数是 超时事件* 它 + 集群心跳检查时间;
cluster-require-full-coverage yes
    # --当为no时: 如果请求过来发现集群无法处理(比如某个主实例挂了又没有副本顶上,造成缺失部分hash槽),则可以重新分配hash槽 覆盖原有数据; yes 则必须所有hash槽 ok 状态集群才能访问                                         
cluster-migration-barrier 1 
    # -- 迁移壁垒,即当某个主实例下没有副本,同时又有某个主实例下有超过1个以上的副本,则至少保留一个副本,多的则可以迁移到没有副本的实例下做副本
cluster-replica-no-failover no
    # -- 副本是否故障转移,如果为 yes 则副本无法顶替主实例自动故障转移(可以手动)
cluster-allow-reads-when-down no 
    # --6.0参数,当集群不可用时,是否允许节点读写
eof


#--------------配置、启动、连接、核验-------------
redis-server ${datadir}${port}_redis/${port}_redis.conf
sleep 3
ps -ef|grep redis-server|grep -v grep

if [ `cat /etc/rc.local|grep "redis-server ${datadir}${port}_redis/${port}_redis.conf"|wc -l` -eq 0  ];then
echo "redis-server ${datadir}${port}_redis/${port}_redis.conf">>/etc/rc.local
fi

 



这篇关于redis(1.21)redis6.0安装的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程