您好,登錄后才能下訂單哦!
用redis-trib.rb搭建集群【常用方法】
redis-trib.rb 是采用Ruby實(shí)現(xiàn)的redis集群管理工具;
內(nèi)部通過Cluster相關(guān)命令進(jìn)行簡化集群創(chuàng)建、檢查、槽喬伊和均衡等常見運(yùn)維操作;
使用之前需要安裝Ruby依賴環(huán)境
https://cache.ruby-lang.org/pub/ruby/2.3/【下載網(wǎng)址】 -- 下載ruby --- cd /soft/tools wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.4.tar.gz -- 安裝ruby --- tar zxf ruby-2.3.4.tar.gz cd ruby-2.3.4 ./configure --prefix=/soft/ruby-2.3.4 make make install ln -s /soft/ruby-2.3.4 /soft/ruby cd /soft/ruby cp bin/ruby /usr/local/bin/ cp bin/gem /usr/local/bin/ [root@lbl ruby]# ll /usr/local/bin/{ruby,gem} -rwxr-xr-x. 1 root root 548 Apr 21 00:42 /usr/local/bin/gem -rwxr-xr-x. 1 root root 22306743 Apr 21 00:42 /usr/local/bin/ruby -- 安裝rubygem redis依賴 --- wget http://rubygems.org/downloads/redis-3.3.0.gem gem install -l redis-3.3.0.gem gem list --check redis gem -- 安裝redis-rb管理工具 --- [root@test ruby]# cp /soft/tools/redis-3.2.0/src/redis-trib.rb /usr/local/bin/ [root@test ruby]# ll /usr/local/bin/{ruby,gem,*.rb} -rwxr-xr-x. 1 root root 548 Apr 16 10:05 /usr/local/bin/gem -rwxr-xr-x. 1 root root 60578 Apr 16 10:07 /usr/local/bin/redis-trib.rb -rwxr-xr-x. 1 root root 22306727 Apr 16 10:05 /usr/local/bin/ruby
-- 主節(jié)點(diǎn) redis-server /soft/redis/cluster/7000/redis.conf & redis-server /soft/redis/cluster/7100/redis.conf & redis-server /soft/redis/cluster/7200/redis.conf & -- 從節(jié)點(diǎn) redis-server /soft/redis/cluster/7001/redis.conf & redis-server /soft/redis/cluster/7101/redis.conf & redis-server /soft/redis/cluster/7201/redis.conf &
啟動好6個節(jié)點(diǎn)之后,使用redis-trib.rb create命令完成節(jié)點(diǎn)握手和槽分配過程:
注意:指定 主從節(jié)點(diǎn)時,前三個為主節(jié)點(diǎn);后三個為對應(yīng)從節(jié)點(diǎn)
[root@test cluster]# redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7100 127.0.0.1:7101 127.0.0.1:7200 127.0.0.1:7300 >>> Creating cluster >>> Performing hash slots allocation on 6 nodes... Using 3 masters: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7100 Adding replica 127.0.0.1:7101 to 127.0.0.1:7000 Adding replica 127.0.0.1:7200 to 127.0.0.1:7001 Adding replica 127.0.0.1:7300 to 127.0.0.1:7100 M: b70ce6df43039cd8ef2004a031851668dfe51982 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: 3300b8f899d7f369d7095025954f2069857801c0 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 085d2851ef195428786f7df14a2c00fedb6ccec9 127.0.0.1:7100 slots:10923-16383 (5461 slots) master S: 97cf943c9fac35520fdd9426e344f7b7cc390fb8 127.0.0.1:7101 replicates b70ce6df43039cd8ef2004a031851668dfe51982 S: e2fae64bbac1fc28d66c4cb21c5be95be4ba8953 127.0.0.1:7200 replicates 3300b8f899d7f369d7095025954f2069857801c0 S: 5207520b05fd05240a56d132bf90fa4e9dde97cb 127.0.0.1:7300 replicates 085d2851ef195428786f7df14a2c00fedb6ccec9 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 127.0.0.1:7000) M: b70ce6df43039cd8ef2004a031851668dfe51982 127.0.0.1:7000 slots:0-5460 (5461 slots) master M: 3300b8f899d7f369d7095025954f2069857801c0 127.0.0.1:7001 slots:5461-10922 (5462 slots) master M: 085d2851ef195428786f7df14a2c00fedb6ccec9 127.0.0.1:7100 slots:10923-16383 (5461 slots) master M: 97cf943c9fac35520fdd9426e344f7b7cc390fb8 127.0.0.1:7101 slots: (0 slots) master replicates b70ce6df43039cd8ef2004a031851668dfe51982 M: e2fae64bbac1fc28d66c4cb21c5be95be4ba8953 127.0.0.1:7200 slots: (0 slots) master replicates 3300b8f899d7f369d7095025954f2069857801c0 M: 5207520b05fd05240a56d132bf90fa4e9dde97cb 127.0.0.1:7300 slots: (0 slots) master replicates 085d2851ef195428786f7df14a2c00fedb6ccec9 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.
集群完整性是指所有的槽都分配到了存活的主節(jié)點(diǎn)上,只要16384個槽中有一個沒有分配給節(jié)點(diǎn)則表示集群不完整;
可以使用redis-trib.rb check命令檢測之前創(chuàng)建的兩個集群是否成功,check命令只需要給出集群中任意一個節(jié)點(diǎn)地址就可以完成整個集群的檢查工作;
-- 命令如下: -- redis-trib.rb check 127.0.0.1:7000 redis-trib.rb check 127.0.0.1:7100 -- 輸出如下信息,提示集群所有的槽都已分配到節(jié)點(diǎn) -- [root@test cluster]# redis-trib.rb check 127.0.0.1:7000 >>> Performing Cluster Check (using node 127.0.0.1:7000) M: b70ce6df43039cd8ef2004a031851668dfe51982 127.0.0.1:7000 slots:0-5460 (5461 slots) master 1 additional replica(s) S: e2fae64bbac1fc28d66c4cb21c5be95be4ba8953 127.0.0.1:7200 slots: (0 slots) slave replicates 3300b8f899d7f369d7095025954f2069857801c0 S: 97cf943c9fac35520fdd9426e344f7b7cc390fb8 127.0.0.1:7101 slots: (0 slots) slave replicates b70ce6df43039cd8ef2004a031851668dfe51982 M: 085d2851ef195428786f7df14a2c00fedb6ccec9 127.0.0.1:7100 slots:10923-16383 (5461 slots) master 1 additional replica(s) S: 5207520b05fd05240a56d132bf90fa4e9dde97cb 127.0.0.1:7300 slots: (0 slots) slave replicates 085d2851ef195428786f7df14a2c00fedb6ccec9 M: 3300b8f899d7f369d7095025954f2069857801c0 127.0.0.1:7001 slots:5461-10922 (5462 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.
1. 建立集群主要步驟如下: ① 準(zhǔn)備節(jié)點(diǎn) ② 節(jié)點(diǎn)握手【meet命令,是一個異步命令】 ③ 分配槽 【cluster addslots {number_start..number_end}】 2. redis cluster 需要至少6個節(jié)點(diǎn),3個主節(jié)點(diǎn) +3個從節(jié)點(diǎn) 3. 主從節(jié)點(diǎn)必須為復(fù)制關(guān)系【cluster replicate 主節(jié)點(diǎn)ID 命令,建立復(fù)制關(guān)系】 4. 節(jié)點(diǎn)握手協(xié)議采用Gossip協(xié)議進(jìn)行通信,通過meet命令建立握手關(guān)系,通過ping/pong命令保持正常通信 5. 加入到集群中的節(jié)點(diǎn),在沒有分配槽時,無法進(jìn)行任何讀寫操作;
相關(guān)鏈接:
手動構(gòu)建redis集群
redis集群【報(bào)錯總結(jié)】
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。