0.环境介绍
Linux采用CentOS7 64位
主节点:
192.168.25.137:7000
192.168.25.138:7000
192.168.25.139:7000
从节点
192.168.25.137:7001
192.168.25.138:7001
192.168.25.139:7001
1.现处于的状态
1.redis 安装配置完成,修改了端口,修改
daemonize yes
cluster-enabled yes2.安装了ruby的运行环境
yum install ruby
yum install rubygems3.安装了ruby脚本运行使用的包
Windows环境下下载redis-3.0.0.gem,并上传至服务器
gem install redis-3.0.0.gem4.拷贝了redis-trib.rb到目标文件下
此时此刻在192.168.25.137
上执行ruby脚本搭建集群
./redis-trib.rb create --replicas 1 192.168.25.137:7000 192.168.25.138:7000 192.168.25.139:7000 192.168.25.137:7001 192.168.25.138:7001 192.168.25.139:7001
报错
>>> Creating cluster
Connecting to node 192.168.25.137:7000: OK
/usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:182: warning: wrong element type nil at 0 (expected array)
/usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:182: warning: ignoring wrong elements is deprecated, remove them explicitly
/usr/local/share/gems/gems/redis-3.0.0/lib/redis.rb:182: warning: this causes ArgumentError in the next release
。。。
。。。
。。。
Connecting to node 192.168.25.138:7000: [ERR] Sorry, can't connect to node 192.168.25.138:7000
2.主机间无法通信问题
Connecting to node 192.168.25.138:7000: [ERR] Sorry, can't connect to node 192.168.25.138:7000
测试192.168.25.137是否可以连接192.168.25.138:7000
[root@localhost redis_cluster]# telnet 192.168.25.138 7000
-bash: telnet: command not found
说明没有安装telnet
2.1安装telnet
1)首先检测安装了什么
[root@localhost redis_cluster]# rpm -qa telnet-server
[root@localhost redis_cluster]#
说明什么都没有装
2)安装telnet-server,telnet
先安装telnet-server
[root@localhost redis_cluster]# yum install telnet-server
再安装telnet
[root@localhost redis_cluster]# yum install telnet
3)重启xinetd
由于telnet服务也是由xinetd守护的,所以安装完telnet-server,要启动telnet服务就必须重新启动xinetd
[root@localhost redis_cluster]# systemctl restart xinetd.service
Failed to issue method call: Unit xinetd.service failed to load: No such file or directory.
[root@localhost redis_cluster]#
安装xinetd
[root@localhost redis_cluster]# yum install xinetd
[root@localhost redis_cluster]# telnet 192.168.25.138 7000
Trying 192.168.25.138...
telnet: connect to address 192.168.25.138: No route to host
[root@localhost redis_cluster]#
测试结果:192.168.25.137确实不可以连接192.168.25.138:7000
2.2检查防火墙
[root@localhost redis_cluster]# firewall-cmd --state
not running
防火墙没开,那就不存在端口被限制的情况
经多方查找,重新启动防火墙,然后再次关闭防火墙,即可
[root@localhost redis_cluster]# telnet 192.168.25.138 7000
Trying 192.168.25.138...
Connected to 192.168.25.138.
Escape character is '^]'.
^]
telnet> q
Connection closed.
[root@localhost redis_cluster]#
3.接下来的步骤
3.1在192.168.25.137
上执行ruby脚本搭建集群
./redis-trib.rb create --replicas 1 192.168.25.137:7000 192.168.25.138:7000 192.168.25.139:7000 192.168.25.137:7001 192.168.25.138:7001 192.168.25.139:7001
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.25.137:7000
192.168.25.138:7000
192.168.25.139:7000
Adding replica 192.168.25.138:7001 to 192.168.25.137:7000
Adding replica 192.168.25.137:7001 to 192.168.25.138:7000
Adding replica 192.168.25.139:7001 to 192.168.25.139:7000
M: 51cc4c3af645fc900c4a8bc575985b02682ec5fd 192.168.25.137:7000
slots:0-5460 (5461 slots) master
M: a047bdebca2e0c59848674cc06af269111c22876 192.168.25.138:7000
slots:5461-10922 (5462 slots) master
M: 1c5c95884c210e8da711554ce60f8e38a21262ac 192.168.25.139:7000
slots:10923-16383 (5461 slots) master
S: f886fcf843e0cde7e6418dff509db31c0c905294 192.168.25.138:7001
replicates 51cc4c3af645fc900c4a8bc575985b02682ec5fd
S: 0185165fdb8f043cbecb7c88354e7ee038df89de 192.168.25.137:7001
replicates a047bdebca2e0c59848674cc06af269111c22876
S: 3bf36d099c13d545b6b2e7c66c3c9b2520cb07a4 192.168.25.139:7001
replicates 1c5c95884c210e8da711554ce60f8e38a21262ac
Can I set the above configuration? (type 'yes' to accept): 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 192.168.25.137:7000)
M: 51cc4c3af645fc900c4a8bc575985b02682ec5fd 192.168.25.137:7000
slots:0-5460 (5461 slots) master
M: a047bdebca2e0c59848674cc06af269111c22876 192.168.25.138:7000
slots:5461-10922 (5462 slots) master
M: 1c5c95884c210e8da711554ce60f8e38a21262ac 192.168.25.139:7000
slots:10923-16383 (5461 slots) master
M: f886fcf843e0cde7e6418dff509db31c0c905294 192.168.25.138:7001
slots: (0 slots) master
replicates 51cc4c3af645fc900c4a8bc575985b02682ec5fd
M: 0185165fdb8f043cbecb7c88354e7ee038df89de 192.168.25.137:7001
slots: (0 slots) master
replicates a047bdebca2e0c59848674cc06af269111c22876
M: 3bf36d099c13d545b6b2e7c66c3c9b2520cb07a4 192.168.25.139:7001
slots: (0 slots) master
replicates 1c5c95884c210e8da711554ce60f8e38a21262ac
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@localhost redis_cluster]# ll
3.2 使用Redis-cli连接集群
[root@localhost redis]# ./redis-cli -h 192.168.25.138 -p 7000 -c
192.168.25.138:7000> set a 1
-> Redirected to slot [15495] located at 192.168.25.139:7000
OK
192.168.25.139:7000> set b 2
-> Redirected to slot [3300] located at 192.168.25.137:7000
OK
192.168.25.137:7000> set c 3
-> Redirected to slot [7365] located at 192.168.25.138:7000
OK
192.168.25.138:7000> set d 4
-> Redirected to slot [11298] located at 192.168.25.139:7000
OK
192.168.25.139:7000> keys *
1) "a"
2) "d"
192.168.25.139:7000> set f 12
-> Redirected to slot [3168] located at 192.168.25.137:7000
OK
192.168.25.137:7000> keys *
1) "f"
2) "b"
192.168.25.137:7000> quit
[root@localhost redis]#