記錄下安裝redis集羣的問題,避免以後再瞎找解決方案
錯誤
創建redis集羣時報錯
[root@Prd- redis]# ./redis-trib.rb create --replicas 1 10.240.47.190:7000 10.240.47.190:7001 10.240.47.190:7002 10.240.47.190:7003 10.240.47.190:7004 10.240.47.190:7005
>>> Creating cluster
[ERR] Sorry, can't connect to node 10.240.47.190:7000
原因
原因是redis-trib.rb create執行時調用ruby的執行沒能連上redis服務。
仔細分析,連不上redis服務會有哪幾類原因:
- 網絡原因:防火牆之類的
- redis服務本身啓動失敗,服務不存在
- redis啓動成功了但還是連不上,那可能是權限問題,比如redis有個密碼
- redis啓動成功,仍然連不上,連接工具的問題?比如ruby版本啥的或者驅動?
- 。。。
解決
照着這幾個思路去查吧,見鬼打鬼,見坑填坑,堅韌不拔!
防火牆問題
查看防火牆狀態 /etc/init.d/iptables status
臨時關閉防火牆 /etc/init.d/iptables stop
永久關閉防火牆 chkconfig --level 2345 iptables off
或者 chkconfig iptables off
redis服務本身問題
配置:
(1)bind:bind本機ip,或者多幾個ip。而不是127.0.0.1、localhost
(2)protected mode 設爲no
(3)舊版本redis 把默認的redis密碼註釋 # requirepass xxxxxx (個人是新版本4.x無此問題也推薦用此版本)
ruby工具問題
直接嘗試安裝最新版就行
yum install ruby
yum install rubygems
集羣創建工具問題
最後一步有需要執行個命令:
./redis-trib.rb create --replicas 1 10.240.47.190:7000 10.240.47.190:7001 10.240.47.190:7002 10.240.47.190:7003 10.240.47.190:7004 10.240.47.190:7005
那麼可能出問題,驅動上,不知是否記得需要個gem驅動
安裝redis管理工具
- 下載ruby環境下Redis的驅動,考慮到兼容性,這裏下載的是3.2.2版本:https://rubygems.org/gems/redis/versions/3.2.2
注意:下載在頁面右下角相關連接一項中
- 把
redis-3.2.2.gem
上傳至服務器進行安裝,這裏放到redis-cluster中 - 安裝
[root@mini2 bin]# gem install redis-3.2.2.gem
Successfully installed redis-3.2.2
Parsing documentation for redis-3.2.2
Installing ri documentation for redis-3.2.2
1 gem installed
然後執行gem install redis
[root@Prd- data]# gem install redis
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Done installing documentation for redis after 1 seconds
1 gem installed
安裝成功
來展示下解決這個問題安裝成功後的結果。(個人是因爲gem install redis命令沒執行。。。)
[root@Prd- redis]# cd src
[root@Prd- src]# ./redis-trib.rb create --replicas 1 10.240.47.190:7000 10.240.47.190:7001 10.240.47.190:7002 10.240.47.190:7003 10.240.47.190:7004 10.240.47.190:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
10.240.47.190:7000
10.240.47.190:7001
10.240.47.190:7002
Adding replica 10.240.47.190:7003 to 10.240.47.190:7000
Adding replica 10.240.47.190:7004 to 10.240.47.190:7001
Adding replica 10.240.47.190:7005 to 10.240.47.190:7002
M: b017bcf537c29d97e5cbd43dda146500c5044542 10.240.47.190:7000
slots:0-5460 (5461 slots) master
M: 64b621b6822830c18d02c4e5c6f1cc028f147f08 10.240.47.190:7001
slots:5461-10922 (5462 slots) master
M: 462bc242c534b9b735b4f0b176a4df0b41203893 10.240.47.190:7002
slots:10923-16383 (5461 slots) master
S: ec561eca4b1a97d53b0e64fe6bb8d6ba711e008b 10.240.47.190:7003
replicates b017bcf537c29d97e5cbd43dda146500c5044542
S: d04fe737e348e23d9b11d94b65ec00fdd4ee01f2 10.240.47.190:7004
replicates 64b621b6822830c18d02c4e5c6f1cc028f147f08
S: 1706c08144813aade2450ff9288e66c4164ac205 10.240.47.190:7005
replicates 462bc242c534b9b735b4f0b176a4df0b41203893
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 10.240.47.190:7000)
M: b017bcf537c29d97e5cbd43dda146500c5044542 10.240.47.190:7000
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: ec561eca4b1a97d53b0e64fe6bb8d6ba711e008b 10.240.47.190:7003
slots: (0 slots) slave
replicates b017bcf537c29d97e5cbd43dda146500c5044542
S: 1706c08144813aade2450ff9288e66c4164ac205 10.240.47.190:7005
slots: (0 slots) slave
replicates 462bc242c534b9b735b4f0b176a4df0b41203893
S: d04fe737e348e23d9b11d94b65ec00fdd4ee01f2 10.240.47.190:7004
slots: (0 slots) slave
replicates 64b621b6822830c18d02c4e5c6f1cc028f147f08
M: 64b621b6822830c18d02c4e5c6f1cc028f147f08 10.240.47.190:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 462bc242c534b9b735b4f0b176a4df0b41203893 10.240.47.190:7002
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[root@Prd- src]# redis-cli -h 10.240.47.190 -p 7003 -c
10.240.47.190:7003> set a a
-> Redirected to slot [15495] located at 10.240.47.190:7002
OK
10.240.47.190:7002> get a
"a"
10.240.47.190:7002>