Redis集群原理与容器化部署( 五 )


同样的配置复制6份 , 修改为端口号相关的东西 , 比如端口号 , 进程ID文件 , 集群节点名称等 。可以使用以上配置批量替换
vi编辑器中执行
# 将7001替换成7002 /g表示全部替换 :%s/7001/7002/g
启动Redis
cd /opt/redis/redis_cluster/redis1/ && ./bin/redis-server redis.conf cd /opt/redis/redis_cluster/redis2/ && ./bin/redis-server redis.conf cd /opt/redis/redis_cluster/redis3/ && ./bin/redis-server redis.conf cd /opt/redis/redis_cluster/redis4/ && ./bin/redis-server redis.conf cd /opt/redis/redis_cluster/redis5/ && ./bin/redis-server redis.conf cd /opt/redis/redis_cluster/redis6/ && ./bin/redis-server redis.conf
查看redis启动情况
[root@VM-0-5-centos redis6]# ps -ef |grep redis root 1485 1 0 22:22 ? 00:00:00 ./bin/redis-server *:7001 [cluster] root 1604 1 0 22:22 ? 00:00:00 ./bin/redis-server *:7002 [cluster] root 1606 1 0 22:22 ? 00:00:00 ./bin/redis-server *:7003 [cluster] root 1611 1 0 22:22 ? 00:00:00 ./bin/redis-server *:7004 [cluster] root 1617 1 0 22:22 ? 00:00:00 ./bin/redis-server *:7005 [cluster] root 1630 1 0 22:22 ? 00:00:00 ./bin/redis-server *:7006 [cluster]
开启防火墙
firewall-cmd --zone=public --add-port=7001/tcp --permanent firewall-cmd --zone=public --add-port=7002/tcp --permanent firewall-cmd --zone=public --add-port=7003/tcp --permanent firewall-cmd --zone=public --add-port=7004/tcp --permanent firewall-cmd --zone=public --add-port=7005/tcp --permanent firewall-cmd --zone=public --add-port=7006/tcp --permanent firewall-cmd --zone=public --add-port=17001/tcp --permanent firewall-cmd --zone=public --add-port=17002/tcp --permanent firewall-cmd --zone=public --add-port=17003/tcp --permanent firewall-cmd --zone=public --add-port=17004/tcp --permanent firewall-cmd --zone=public --add-port=17005/tcp --permanent firewall-cmd --zone=public --add-port=17006/tcp --permanent systemctl restart firewalld.service
放行云服务器的防火墙端口(7001-7006 , 17001-17006)于本机公网IP

Redis集群原理与容器化部署

文章插图
 
开启集群(公网IP,指定密码)
/opt/redis/redis_cluster/redis1/bin/redis-cli --cluster create162.14.74.11:7001162.14.74.11:7002162.14.74.11:7003162.14.74.11:7004162.14.74.11:7005162.14.74.11:7006--cluster-replicas 1 -a abcAbc123.
  • 1、 --cluster-replicas表示副本数量为1 , 六台Redis实例 , 复本为1 , 也就是三主三从 。
  • 2、 -a表示指定密码
 
加入集群结果
[root@VM-0-5-centos redis6]# /opt/redis/redis_cluster/redis1/bin/redis-cli --cluster create> 162.14.74.11:7001> 162.14.74.11:7002> 162.14.74.11:7003> 162.14.74.11:7004> 162.14.74.11:7005> 162.14.74.11:7006> --cluster-replicas 1 -a abcAbc123. Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 162.14.74.11:7004 to 162.14.74.11:7001 Adding replica 162.14.74.11:7005 to 162.14.74.11:7002 Adding replica 162.14.74.11:7006 to 162.14.74.11:7003 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: 95bb2b273537ec44879178d80fec968a4a02d151 162.14.74.11:7001 slots:[0-5460] (5461 slots) master M: 840c4b75f4603e1e1baa3189154adc9c2dc9abc7 162.14.74.11:7002 slots:[5461-10922] (5462 slots) master M: 478f97fc6bc954daadc1aeed49bd90b5b8f921a9 162.14.74.11:7003 slots:[10923-16383] (5461 slots) master S: b7cefab8fbce66cf7784b52a18c1d07fbc485e8d 162.14.74.11:7004 replicates 95bb2b273537ec44879178d80fec968a4a02d151 S: 9d6cc857350689586336dfd6d82f0fbb41dd8450 162.14.74.11:7005 replicates 840c4b75f4603e1e1baa3189154adc9c2dc9abc7 S: 830c13e63211ef4c4dc2668581895f78b45ff06c 162.14.74.11:7006 replicates 478f97fc6bc954daadc1aeed49bd90b5b8f921a9 Can I set the above configuration? (type 'yes' to accept): yes # 这里输入yes >>> Nodes configuration updated >>> Assign a different config epoch to each node >>> Sending CLUSTER MEET messages to join the cluster Waiting for the cluster to join .... >>> Performing Cluster Check (using node 162.14.74.11:7001) M: 95bb2b273537ec44879178d80fec968a4a02d151 162.14.74.11:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 830c13e63211ef4c4dc2668581895f78b45ff06c 162.14.74.11:7006 slots: (0 slots) slave replicates 478f97fc6bc954daadc1aeed49bd90b5b8f921a9 M: 478f97fc6bc954daadc1aeed49bd90b5b8f921a9 162.14.74.11:7003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) M: 840c4b75f4603e1e1baa3189154adc9c2dc9abc7 162.14.74.11:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: b7cefab8fbce66cf7784b52a18c1d07fbc485e8d 162.14.74.11:7004 slots: (0 slots) slave replicates 95bb2b273537ec44879178d80fec968a4a02d151 S: 9d6cc857350689586336dfd6d82f0fbb41dd8450 162.14.74.11:7005 slots: (0 slots) slave replicates 840c4b75f4603e1e1baa3189154adc9c2dc9abc7 [OK] All nodes agree about slots configuration. # 加入集群成功 >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.


推荐阅读