1. 程式人生 > >redis叢集搭建及問題的決方法(一)

redis叢集搭建及問題的決方法(一)

一、叢集搭建主要配置如下:

P61 bind 127.0.0.1//預設ip為127.0.0.1改為其他節點機器可訪問 的ip 註釋掉bind;可以監聽連線當前服務的所有-h 後的ip;例如;綁定了 127.0.0.1,但是登入時使用-h 10.9.17.153 P80 protected-mode no //yes修改為no P84 port 8000 //埠8000-8005 P128 daemonize yes //後臺執行 P150 pidfile /var/run/redis_8000.pid P163 logfile 8000/redis.log P237 dump dump8000.rdb P593 appendonly yes P597 appendfilename “appendonly.aof” P721 cluster-enabled yes P729 cluster-config-file nodes_8000.conf P735 cluster-node-timeout 15000 //請求超時 預設15秒,可 自行設定

二、搭建完成後依次啟動各個例項

redis-server 8000/redis.conf redis-server 8001/redis.conf redis-server 8002/redis.conf redis-server 8003/redis.conf redis-server 8004/redis.conf redis-server 8005/redis.conf

三、檢查啟動結果:

[[email protected] redis-3.2.11]# ps -ef|grep 800 root 19360 1 0 23:19 ? 00:00:01 redis-server *:8001 [cluster] root 19364 1 0 23:19 ? 00:00:01 redis-server *:8002 [cluster] root 19368 1 0 23:19 ? 00:00:01 redis-server *:8003 [cluster] root 19372 1 0 23:19 ? 00:00:01 redis-server *:8004 [cluster] root 19378 1 0 23:19 ? 00:00:01 redis-server *:8005 [cluster] root 19433 1 0 23:30 ? 00:00:01 redis-server *:8000 [cluster]

四、以上啟動後並不是一個真正的叢集,以下開始建立叢集

在redis的根目錄下的src目錄下執行***/redis-3.2.11/src,報錯資訊如下 [[email protected] src]# ./redis-trib.rb create 10.211.55.5:8000 10.211.55.5:8001 10.211.55.5:8002

Creating cluster Performing hash slots allocation on 3 nodes… Using 3 masters: 10.211.55.5:8000 10.211.55.5:8001 10.211.55.5:8002 M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 slots:0-5460 (5461 slots) master M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 slots:5461-10922 (5462 slots) master M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 slots:10923-16383 (5461 slots) master Can I set the above configuration? (type ‘yes’ to accept): yes /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis/client.rb:119:in call': ERR Slot 1180 is already busy (Redis::CommandError) from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:2854:in

block in method_missing’ from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:45:in block in synchronize' from /usr/local/lib/ruby/2.3.0/monitor.rb:214:inmon_synchronize’ from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:45:in synchronize' from /usr/local/lib/ruby/gems/2.3.0/gems/redis-4.0.2/lib/redis.rb:2853:inmethod_missing’ from ./redis-trib.rb:212:in flush_node_config' from ./redis-trib.rb:776:inblock in flush_nodes_config’ from ./redis-trib.rb:775:in each' from ./redis-trib.rb:775:inflush_nodes_config’ from ./redis-trib.rb:1296:in create_cluster_cmd' from ./redis-trib.rb:1701:in

五、針對以上問題的解決方法:

所有redis伺服器都執行以下命令:

$redis-cli -p 埠號 $flushall $cluster reset soft $exit

六、解決後再次建立,就成功了

[[email protected] src]# ./redis-trib.rb create 10.211.55.5:8000 10.211.55.5:8001 10.211.55.5:8002

Creating cluster Performing hash slots allocation on 3 nodes… Using 3 masters: 10.211.55.5:8000 10.211.55.5:8001 10.211.55.5:8002 M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 slots:0-5460 (5461 slots) master M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 slots:5461-10922 (5462 slots) master M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 slots:10923-16383 (5461 slots) master 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.211.55.5:8000) M: 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 slots:0-5460 (5461 slots) master 0 additional replica(s) M: 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 slots:5461-10922 (5462 slots) master 0 additional replica(s) M: da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 slots:10923-16383 (5461 slots) master 0 additional replica(s) [OK] All nodes agree about slots configuration.

Check for open slots… Check slots coverage… [OK] All 16384 slots covered.

**

七、檢視叢集狀態

** [[email protected] src]# redis-cli -c -p 8000 127.0.0.1:8000> cluster info cluster_state:ok cluster_slots_assigned:16384 cluster_slots_ok:16384 cluster_slots_pfail:0 cluster_slots_fail:0 cluster_known_nodes:3 cluster_size:3 cluster_current_epoch:3 cluster_my_epoch:1 cluster_stats_messages_sent:2059 cluster_stats_messages_received:2059

cluster_current_epoch:6 代表當前叢集的最新邏輯計算時間,數字 越大,表示操作或者配置越新,整個叢集的這個值是保持一致的 cluster_my_epoch:1代表當前節點的邏輯計算時間

八、檢視槽道分配情況和叢集節點資訊

127.0.0.1:8000> cluster nodes 8ce851252f32fcab268e77d3b3ed976d57d2f498 10.211.55.5:8000 myself,master - 0 0 1 connected 0-5460 6f4a31fc322725fc4ed453a588f344fed4f261bf 10.211.55.5:8001 master - 0 1538582282356 2 connected 5461-10922 da7d09090520a0e6287ea12fe7f48225d6665f68 10.211.55.5:8002 master - 0 1538582283359 3 connected 10923-16383

以上只掛載了主節點,關於從節點的掛載步驟和方法見本人的下一篇部落格文章。