利用工具部署redis集群
作者:互联网
1安装redis(本例已安装可忽略)
[root@db01 ~]# yum makecache fast [root@db01 ~]# yum install rubygems [root@db01 ~]# gem sources --remove https://rubygems.org/ [root@db01 ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ [root@db01 ~]# gem update - system [root@db01 ~]# gem install redis -v 3.3.5
2分别在三台机器中kill掉之前手动配置的redis集群(测试环境):
[root@db01 ~]# pkill redis [root@db01 ~]# pkill redis [root@db01 ~]# rm -rf /data/redis_cluster/redis_6380/* [root@db01 ~]# rm -rf /data/redis_cluster/redis_6381/* [root@db01 ~]#
3分别在三台机器中启动所有单节点redis
[root@db01 ~]# sh redis_shell.sh start 6380 [root@db01 ~]# sh redis_shell.sh start 6381
4使用工具一键搭建集群
[root@db01 ~]# cd /opt/redis_cluster/redis/src/ [root@db01 src]# ./redis-trib.rb create --replicas 1 10.0.0.201:6380 10.0.0.202:6380 10.0.0.203:6380 10.0.0.201:6381 10.0.0.202:6381 10.0.0.203:6381
5修复使用工具搭建集群的一个bug:
#db03的6381复制的不是db01的6380,这是一个bug,按照下列的语句执行的结果是:
db01的6381复制的是db02的6380
db02的6381复制的是db01的6380
db03的6381复制的是db02的6380
这违背了我们前面设计的架构
[root@db01 ~]# sh redis_shell.sh login 6380 10.0.0.201:6380> cluster nodes e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5 10.0.0.203:6380 master - 0 1618335912245 3 connected 10923-16383 9e6565d8f0a8ed0d6d56437dcf4b58cbb17a3c0f 10.0.0.202:6380 master - 0 1618335915275 2 connected 5461-10922 a31deef0baf970cef6c798f1e320fb4ba5543daf 10.0.0.203:6381 slave e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5 0 1618335916283 6 connected c37e5f309b2d07012f2efb11053c517b5f51eba0 10.0.0.202:6381 slave 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01 0 1618335913257 5 connected 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01 10.0.0.201:6380 myself,master - 0 0 1 connected 0-5460 8cea03a478990dc7e6d21f1b671c70dd921fcdb2 10.0.0.201:6381 slave 9e6565d8f0a8ed0d6d56437dcf4b58cbb17a3c0f 0 1618335917291 4 connected 10.0.0.201:6380>
[root@db01 ~]# redis-cli -c -h db02 -p 6381 cluster replicate e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5 OK [root@db01 ~]# redis-cli -c -h db03 -p 6381 cluster replicate 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01 OK [root@db01 ~]# sh redis_shell.sh login 6380 10.0.0.201:6380> cluster nodes e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5 10.0.0.203:6380 master - 0 1618337145162 3 connected 10923-16383 9e6565d8f0a8ed0d6d56437dcf4b58cbb17a3c0f 10.0.0.202:6380 master - 0 1618337142635 2 connected 5461-10922 a31deef0baf970cef6c798f1e320fb4ba5543daf 10.0.0.203:6381 slave 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01 0 1618337143645 6 connected c37e5f309b2d07012f2efb11053c517b5f51eba0 10.0.0.202:6381 slave e92cd97d2c06d2cc02547bcd7ac64b9f6fb44fb5 0 1618337144655 5 connected 3a9aeeeb4ac0c76a5ba3c66bb917161348582c01 10.0.0.201:6380 myself,master - 0 0 1 connected 0-5460 8cea03a478990dc7e6d21f1b671c70dd921fcdb2 10.0.0.201:6381 slave 9e6565d8f0a8ed0d6d56437dcf4b58cbb17a3c0f 0 1618337145665 4 connected 10.0.0.201:6380>
6检查集群的完整性:
[root@db01 ~]# cd /opt/redis_cluster/redis/src [root@db01 src]# ./redis-trib.rb check 10.0.0.201:6380
7检查槽位是否都在合理的误差范围内:
[root@db01 src]# ./redis-trib.rb rebalance 10.0.0.201:6380
标签:10.0,部署,redis,集群,6380,6381,db01,root 来源: https://www.cnblogs.com/tyjs09/p/14654239.html