redis集羣搭建中遇到的一些問題

redis單機模式啓動後,修改完配置文件,使用如下命令建立redis集羣:html

sudo ./src/redis-trib.rb create --replicas 1 ip1:6379 ip2:6379 ip3:6379

結果報錯:node

>>> Creating cluster
[ERR] Sorry, can't connect to node ip1:6379

在網上查找資料發現,可能有如下幾種緣由:redis

1.ruby的版本過低。sql

2.關閉redis的保護模式。緩存

3.redis的配置文件中bind的ip須要時外網ip,127.0.0.1不行,確保外網能telnet通。ruby

4.在將redis寫入註冊表時,開啓了redis的密碼模式,也會致使這個問題,須要關閉密碼模式。bash

以上幾種方法對應完了,這個錯誤就沒有了。服務器

 

接着報了第二個錯:app

[ERR] Node ip2:6379 is not configured as a cluster node.

緣由是第二臺redis服務器沒有開啓集羣模式,修改第二臺服務器的redis的配置文件:nosql

cluster-enabled yes

appendonly yes

 

 

修改完了以後,重啓第二臺redis服務時報了這個錯:

14652:M 21 Feb 18:26:50.758 # Sorry, the cluster configuration file nodes.conf is already used by a different Redis Cluster node.
Please make sure that different nodes use different cluster configuration files.

改變這臺redis的配置文件指向的nodes.conf文件便可。

 

再記錄幾個redis下經常使用的命令:

#查看redis版本
./src/redis-server -v   

#啓動redis服務
sudo ./src/redis-server ./redis.config

#中止redis服務的兩種方式:
#第一種:
sudo ./src/redis-cli -h 127.0.0.1 -p 6379 shutdown
#第二種:
#進入redis-cli,而後用shutdown命令中止

#查看集羣狀況:
redis-cli -h ip -p 6379 cluster nodes

#查看集羣信息:
172.30.1.160:6379> cluster nodes

#添加節點:
redis-trib.rb add-node --slave --master-id 08525dd167adbfe4b11b8b8e598efde2de11f31e slaveIp:6380 masterIp:6379 

 

 

redis集羣會常常出錯,使用cluster nodes命令和redis-trid.rb check命令查詢到的集羣狀態信息不對,刪掉節點以後,在集羣狀態信息中還有記錄,各類辦法都沒辦法解決問題,好在是實驗環境,就幹掉整個集羣,從新裝了。集羣的緩存信息會存在三種文件裏:node.conf配置文件,dump.rdb,appendonly.aof。刪掉三個文件,從新建立集羣便可。 

 

 

建立集羣中還報過這個錯誤,刪除了三種緩存文件仍是不行,最後登入每一個節點用flushall和cluster reset命令解決了。

/usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis/client.rb:113:in `call': ERR Slot 12182 is already busy (Redis::CommandError)
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2556:in `method_missing'
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib64/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2555:in `method_missing'
from ./src/redis-trib.rb:212:in `flush_node_config'
from ./src/redis-trib.rb:776:in `flush_nodes_config'
from ./src/redis-trib.rb:775:in `each'
from ./src/redis-trib.rb:775:in `flush_nodes_config'
from ./src/redis-trib.rb:1296:in `create_cluster_cmd'
from ./src/redis-trib.rb:1696:in `send'
from ./src/redis-trib.rb:1696

 

建立集羣的時候,一直卡在Waiting for the cluster to join.....這一步,先刪除三種文件:node.conf配置文件,dump.rdb,appendonly.aof;再把iptables關閉:sudo service iptables stop

 

轉載請標明出處: http://www.cnblogs.com/gaojiang/p/6427693.html 

 

 

再附幾個查找資料過程當中發現幾篇比較好的帖子:

從集羣的原理到搭建,講的比較透徹:

http://shift-alt-ctrl.iteye.com/blog/2284890

主要講了對redis集羣的一些操做命令:

http://blog.51yip.com/nosql/1726.html

分析了搭建集羣可能出錯的緣由:

https://my.oschina.net/u/2277929/blog/727734

相關文章
相關標籤/搜索