目标在三台机器上搭建三主三从的集群,每个主对应一个从
ip:192.168.192.133 192.168.192.139 192.168.192.189
1,在每个机器上安装redis
mkdir -p /home/soft/download-package/ cd /home/soft/download-package/ wget https://download.redis.io/releases/redis-6.2.1.tar.gz tar -zxvf redis-6.2.1.tar.gz mv redis-6.2.1 /usr/local cd /usr/local/redis-6.2.1 make make install PREFIX=/usr/local/redis-6.2.1
2,每个机器上新建集群文件夹,其它2个机器 为 20003 20004 20005 20006
mkdir cluster cd cluster mkdir 20001 mkdir 20002
3,生成配置文件
daemonize yes pidfile /usr/local/redis-6.2.1/cluster/20001/20001.pid port 20001 tcp-backlog 511 bind 0.0.0.0 timeout 0 tcp-keepalive 0 loglevel notice logfile "20001.log" databases 16 save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename 20001.rdb dir /usr/local/redis-6.2.1/cluster/20001 slave-serve-stale-data yes slave-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 masterauth mypasswd requirepass mypasswd appendonly yes appendfilename "20001.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes # 是否开启集群 cluster-enabled yes # 集群配置文件(启动后自动生成) cluster-config-file nodes-20001.conf # 集群节点ping、pong超时时间 cluster-node-timeout 5000
配置文件拷贝到其它节点,执行下面的命令替换文件中的内容,最后生成6个文件
sed -i 's/20001/20003/g' /usr/local/redis-6.2.1/cluster/20003/redis.conf
4,在三个机器上启动6个节点
/usr/local/redis-6.2.1/src/redis-server /usr/local/redis-6.2.1/cluster/20001/redis.conf
5,创建集群
/usr/local/redis-6.2.1/src/redis-cli --cluster create -a mypasswd 192.168.192.133:20001 192.168.192.139:20003 192.168.192.189:20005 192.168.192.139:20004 192.168.192.189:20006 192.168.192.133:20002 --cluster-replicas 1
6,查看集群状态
/usr/local/redis-6.2.1/src/redis-cli -h 192.168.192.133 -a mypasswd -p 20001 cluster nodes
出现如下结果说明集群搭建成功了