Redis Cluster 六台服务器 搭建集群,你没看错,是六台服务器,不是一台机器两个redis

搭建redis Cluster集群

我准备了六台服务器

下面放代码

 10.206.32.16-----redis1
 10.206.32.9-----redis2
 10.206.32.14-----redis3
 10.206.32.10-----redis4
 10.206.32.13-----redis5
 10.206.32.11-----redis6




#初始化(六台机器都做)
systemctl   stop  firewalld
systemctl disable firewalld
setenforce 0
cd /etc/yum.repos.d/
rm -rf *
sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum -y install bash-completion  bash-completion-extras wget lsof  vim sl ntpdate
yum install centos-release-scl-rh -y
yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
 yum install rh-ruby23  -y   
 scl  enable  rh-ruby23 bash 
ruby -v
 gem install redis
 
 #安装redis
 wget https://download.redis.io/releases/redis-6.2.4.tar.gz?_ga=2.43682149.1149194186.1623136063-856859871.1623136063
 mv redis-6.2.4.tar.gz?_ga=2.43682149.1149194186.1623136063-856859871.1623136063 redis-6.2.4.tar.gz  
 tar xf redis-6.2.4.tar.gz
 mv redis-6.2.4  /redis
 cd /redis
 make
 mkdir data
 
 mkdir /etc/redis/
 cd /redis
 cp redis.conf /etc/redis/6379.conf
 
 
 
 #准备systemctl 关联  编译安装的 redis
 

vim /etc/init.d/redis

#!/bin/bash
# chkconfig: 2345 10 90  
# description: Start and Stop redis 
REDISPORT=6379
EXEC=/redis/src/redis-server
CLIEXEC=/redis/src/redis-cli

PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"

case "$1" in
    start)
                $EXEC $CONF &
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE) 
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

#将redis脚本加入chkconfig开机启动:
chmod +x redis
chkconfig --add redis
chkconfig redis on

试一下systemctl可不可以管理redis
systemctl start redis 
lsof -i:6379
没起来,就得排错了
脚本没问题了,关闭redis,再编辑文件!!!!!!!!!!!!!!!!!!

#修改配置文件
vim /etc/redis/6379.conf

bind 192.168.3.41
daemonize yes              
tcp-backlog 511
tcp-keepalive 0
loglevel notice                        
databases 16                         
dir /data/application/redis/data        
appendonly yes         
appendfilename "appendonly.aof"          
appendfsync everysec                    
no-appendfsync-on-rewrite yes           
auto-aof-rewrite-percentage 100         
auto-aof-rewrite-min-size 64mb               
#上面的是修改配置文件,如果配置文件内容和我要修改的值一样,就不管他



#下面的大部分被注释了,删掉注释

cluster-enabled yes  
cluster-config-file nodes-6379.conf  
cluster-node-timeout 5000  
cluster-replica-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage yes 


修改完毕
六台redis服务全部启动


/redis-cli  --cluster create 10.206.32.16:6379 10.206.32.9:6379 10.206.32.14:6379 10.206.32.10:6379 10.206.32.13:6379 10.206.32.11:6379 --cluster-replicas 1
创建集群

yes 确认



./redis-cli -h 10.206.32.16 -c -p 6379
cluster info   查看集群信息

./redis-cli --cluster check 10.206.32.16:6379 
检查集群状态



测试连接数据库查询数据:
[root@redis1 src]# ./redis-cli -h 192.168.3.41 -c -p 7000
192.168.3.41:7000> cluster meet 127.0.0.1 7000
OK
192.168.3.41:7000>



Redis Cluster槽的范围是0~16383。
固定槽位

你可能感兴趣的:(linux,redis,centos)