読者です 読者をやめる 読者になる 読者になる

kenken0807_DBメモ

つば九郎が好きなDBAです。Oracle Standard Editionでの運用やツールとかとかの備忘録。特に記載がない場合はoracle11gR2です。時々MySQL

Redis Cluster構築メモ

同一ホスト内にRedis Cluster構築してみたのでメモ。
version:Redis 3.2.6

インストール

動作確認のためなのでインストールの細かい設定は気にしない。適当に動作するように設定。

  • ダウンロード
mkdir /redis
wget http://download.redis.io/releases/redis-3.2.6.tar.gz
tar zxvf redis-3.2.6.tar.gz
make
make install

Redisを複数起動するため起動スクリプト編集

# vim utils/redis_init_script
REDISPORT=6379 → REDISPORT=$2
  • 設定ファイル変更

6台構成で作成するため、6つ設定ファイル作成

 vim /redis/redis-3.2.6/redis.conf

編集
daemonize no → yes
port 6379 → PORTBANGOU
protected-mode yes → no
pidfile /var/run/redis_6379.pid  → /var/run/redis_PORTBANGOU.pid
dir ./ → /redis
dbfilename dump.rdb dump_PORTBANGOU.rdb
bind 127.0.0.1 → #bind 127.0.0.1

追加
cluster-enabled yes
cluster-config-file nodes_PORTBANGOU.conf
cluster-node-timeout 15000
cluster-require-full-coverage yes
  • ポート番号7001 - 7006までの設定ファイル配置
# mkdir /etc/redis
# for ii in `seq 7001 7006`; do cat /redis/redis-3.2.6/redis.conf |  sed -e "s/PORTBANGOU/${ii}/g" > /etc/redis/${ii}.conf ; done

# ls -ltr /etc/redis/
total 288
-rw-r--r-- 1 root root 46823 Dec  8 02:03 7001.conf
-rw-r--r-- 1 root root 46823 Dec  8 02:03 7002.conf
-rw-r--r-- 1 root root 46823 Dec  8 02:03 7003.conf
-rw-r--r-- 1 root root 46823 Dec  8 02:03 7004.conf
-rw-r--r-- 1 root root 46823 Dec  8 02:03 7005.conf
-rw-r--r-- 1 root root 46823 Dec  8 02:03 7006.conf
  • 起動
# for ii in `seq 7001 7006`; do /redis/redis-3.2.6/utils/redis_init_script start $ii; done

[root@80efe0c08de2 redis-3.2.6]# ps aux | grep redis
root       3727  0.0  0.0  40788  2620 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7001 [cluster]
root       3732  0.0  0.0  40788  2624 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7002 [cluster]
root       3737  0.0  0.0  40788  2620 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7003 [cluster]
root       3742  0.0  0.0  40788  2624 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7004 [cluster]
root       3747  0.0  0.0  40788  2620 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7005 [cluster]
root       3752  0.0  0.0  40788  2620 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7006 [cluster]

6台構成でクラスター作成する

↓を作成する。

slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7003 172.17.0.4:7004
10923-16383 172.17.0.4:7005 172.17.0.4:7006
  • ポート番号7001,7003,7005をマスターとするクラスターを作成
# yum install rubygems -y
# gem install redis

# redis-trib.rb create 172.17.0.4:7001 172.17.0.4:7003 172.17.0.4:7005

# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481164053943 2 connected 5461-10922
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481164054945 3 connected 10923-16383
  • 各マスターに対してスレーブ作成
# redis-trib.rb add-node --slave 172.17.0.4:7002 172.17.0.4:7001
# redis-trib.rb add-node --slave 172.17.0.4:7004 172.17.0.4:7003
# redis-trib.rb add-node --slave 172.17.0.4:7006 172.17.0.4:7005

# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481164102029 1 connected
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481164103031 2 connected 5461-10922
e924857295ad43ccf9f2d792872e4d41293cab07 172.17.0.4:7004 slave 7d2e412e417f4d077bf50372f472f9103c480501 0 1481164105034 2 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481164104033 3 connected 10923-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481164100229 3 connected

これでクラスター作成完了。

ノードを追加してみる

  • 今こういう状態
slot master slave master_nodeid slave_nodeid
0-5460 172.17.0.4:7001 172.17.0.4:7002 1b6d03569f09e6009a25b941887ac1275759d172 c17a5b65fb4ab1b802995ef8769edbe3290d7a03
5461-10922 172.17.0.4:7003 172.17.0.4:7004 7d2e412e417f4d077bf50372f472f9103c480501 e924857295ad43ccf9f2d792872e4d41293cab07
10923-16383 172.17.0.4:7005 172.17.0.4:7006 abe6531b02045b6e16cf51849ba6f7ff22300aa5 89bc1da3bc8417e4513d33d7a175fc48764ec70a

ここに172.17.0.4:7007172:17.0.1:7008を追加してリシャードさせる

  • 7007と7008のノードの設定ファイル作成して起動
# for ii in 7007 7008; do cat /redis/redis-3.2.6/redis.conf |  sed -e "s/PORTBANGOU/${ii}/g" > /etc/redis/${ii}.conf ; done
# ls /etc/redis
7001.conf  7002.conf  7003.conf  7004.conf  7005.conf  7006.conf  7007.conf  7008.conf

# for ii in 7007 7008; do /redis/redis-3.2.6/utils/redis_init_script start $ii; done
# ps aux | grep edis
root       3727  9.4  0.0  40788  3612 ?        Ssl  02:26   1:14 /usr/local/bin/redis-server *:7001 [cluster]
root       3732  0.0  0.0  40788  3252 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7002 [cluster]
root       3737  0.1  0.0  40788  3604 ?        Ssl  02:26   0:01 /usr/local/bin/redis-server *:7003 [cluster]
root       3742  0.0  0.0  40788  3228 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7004 [cluster]
root       3747  0.1  0.0  40788  3608 ?        Ssl  02:26   0:01 /usr/local/bin/redis-server *:7005 [cluster]
root       3752  0.0  0.0  40788  3212 ?        Ssl  02:26   0:00 /usr/local/bin/redis-server *:7006 [cluster]
root      22474  0.0  0.0  36692  2560 ?        Ssl  02:39   0:00 /usr/local/bin/redis-server *:7007 [cluster]
root      22479  0.0  0.0  36692  2568 ?        Ssl  02:39   0:00 /usr/local/bin/redis-server *:7008 [cluster]

ここではまだハッシュスロットの割当はない

# redis-trib.rb add-node 172.17.0.4:7007 172.17.0.4:7001
# redis-trib.rb add-node --slave 172.17.0.4:7008 172.17.0.4:7007


# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481164803460 1 connected
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481164798952 2 connected 5461-10922
e924857295ad43ccf9f2d792872e4d41293cab07 172.17.0.4:7004 slave 7d2e412e417f4d077bf50372f472f9103c480501 0 1481164805463 2 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481164801455 3 connected 10923-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481164804460 3 connected
0c55b1cba923d063cb7566b80f098c7dddea8f96 172.17.0.4:7007 master - 0 1481164802958 0 connected
3ed3899c6ba3ca1371235f91cd8502297c3a46b9 172.17.0.4:7008 slave 0c55b1cba923d063cb7566b80f098c7dddea8f96 0 1481164802457 0 connected
  • リシャード
    • 16384のハッシュスロットに分かれてるので4シャードで割る。16384/4=4096
    • 追加したマスター(port:7007)のノードIDを指定する
# redis-trib.rb reshard 172.17.0.4:7007

How many slots do you want to move (from 1 to 16384)? 4096
What is the receiving node ID? 0c55b1cba923d063cb7566b80f098c7dddea8f96
Please enter all the source node IDs.
  Type 'all' to use all the nodes as source nodes for the hash slots.
  Type 'done' once you entered all the source nodes IDs.
Source node #1:all

# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 1 connected 1365-5460
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481165063925 1 connected
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481165061923 2 connected 6827-10922
e924857295ad43ccf9f2d792872e4d41293cab07 172.17.0.4:7004 slave 7d2e412e417f4d077bf50372f472f9103c480501 0 1481165061923 2 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481165060921 3 connected 12288-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481165062924 3 connected
0c55b1cba923d063cb7566b80f098c7dddea8f96 172.17.0.4:7007 master - 0 1481165058918 4 connected 0-1364 5461-6826 10923-12287
3ed3899c6ba3ca1371235f91cd8502297c3a46b9 172.17.0.4:7008 slave 0c55b1cba923d063cb7566b80f098c7dddea8f96 0 1481165058918 4 connected
slot master slave
1365-5460 172.17.0.4:7001 172.17.0.4:7002
6827-10922 172.17.0.4:7003 172.17.0.4:7004
12288-16383 172.17.0.4:7005 172.17.0.4:7006
0-1364 5461-6826 10923-12287 172.17.0.4:7007 172.17.0.4:7008

完了

ノードを撤去してみる

  • 今の状態
slot master slave master_nodeid slave_nodeid
1365-5460 172.17.0.4:7001 172.17.0.4:7002 1b6d03569f09e6009a25b941887ac1275759d172 c17a5b65fb4ab1b802995ef8769edbe3290d7a03
6827-10922 172.17.0.4:7003 172.17.0.4:7004 7d2e412e417f4d077bf50372f472f9103c480501 e924857295ad43ccf9f2d792872e4d41293cab07
12288-16383 172.17.0.4:7005 172.17.0.4:7006 abe6531b02045b6e16cf51849ba6f7ff22300aa5 89bc1da3bc8417e4513d33d7a175fc48764ec70a
0-1364 5461-6826 10923-12287 172.17.0.4:7007 172.17.0.4:7008 0c55b1cba923d063cb7566b80f098c7dddea8f96 3ed3899c6ba3ca1371235f91cd8502297c3a46b9

ここから172.17.0.4:7003172.17.0.4:7004を取り除く

今のハッシュスロットの割合はノード単位で4096なので4096/3=1365,1365,1366でそれぞれのノードに割り振る

  • 7001のノードに割当
# redis-trib.rb reshard --from 7d2e412e417f4d077bf50372f472f9103c480501 --to 1b6d03569f09e6009a25b941887ac1275759d172 --slots 1365 --yes 172.17.0.4:7001

# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 5 connected 1365-5460 6827-8191
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481165235210 5 connected
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481165233208 2 connected 8192-10922
e924857295ad43ccf9f2d792872e4d41293cab07 172.17.0.4:7004 slave 7d2e412e417f4d077bf50372f472f9103c480501 0 1481165236211 2 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481165236713 3 connected 12288-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481165238213 3 connected
0c55b1cba923d063cb7566b80f098c7dddea8f96 172.17.0.4:7007 master - 0 1481165237212 4 connected 0-1364 5461-6826 10923-12287
3ed3899c6ba3ca1371235f91cd8502297c3a46b9 172.17.0.4:7008 slave 0c55b1cba923d063cb7566b80f098c7dddea8f96 0 1481165234209 4 connected
  • 7005のノードに割当
# redis-trib.rb reshard --from 7d2e412e417f4d077bf50372f472f9103c480501 --to abe6531b02045b6e16cf51849ba6f7ff22300aa5 --slots 1365 --yes 172.17.0.4:7005

# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 5 connected 1365-5460 6827-8191
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481165279296 5 connected
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481165282804 2 connected 9557-10922
e924857295ad43ccf9f2d792872e4d41293cab07 172.17.0.4:7004 slave 7d2e412e417f4d077bf50372f472f9103c480501 0 1481165283305 2 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481165278294 6 connected 8192-9556 12288-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481165282303 6 connected
0c55b1cba923d063cb7566b80f098c7dddea8f96 172.17.0.4:7007 master - 0 1481165284306 4 connected 0-1364 5461-6826 10923-12287
3ed3899c6ba3ca1371235f91cd8502297c3a46b9 172.17.0.4:7008 slave 0c55b1cba923d063cb7566b80f098c7dddea8f96 0 1481165281300 4 connected
  • 7007のノードに割当
# redis-trib.rb reshard --from 7d2e412e417f4d077bf50372f472f9103c480501 --to 0c55b1cba923d063cb7566b80f098c7dddea8f96 --slots 1366 --yes 172.17.0.4:7007

# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 5 connected 1365-5460 6827-8191
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481165327396 5 connected
7d2e412e417f4d077bf50372f472f9103c480501 172.17.0.4:7003 master - 0 1481165323386 2 connected
e924857295ad43ccf9f2d792872e4d41293cab07 172.17.0.4:7004 slave 7d2e412e417f4d077bf50372f472f9103c480501 0 1481165324390 2 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481165322386 6 connected 8192-9556 12288-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481165325392 6 connected
0c55b1cba923d063cb7566b80f098c7dddea8f96 172.17.0.4:7007 master - 0 1481165321383 7 connected 0-1364 5461-6826 9557-12287
3ed3899c6ba3ca1371235f91cd8502297c3a46b9 172.17.0.4:7008 slave 0c55b1cba923d063cb7566b80f098c7dddea8f96 0 1481165326394 7 connected
元slot reshard1回目slot reshard2回目slot reshard3回目slot master slave
1365-5460 1365-5460 6827-8191 1365-5460 6827-8191 1365-5460 6827-8191 172.17.0.4:7001 172.17.0.4:7002
6827-10922 8192-10922 9557-10922 172.17.0.4:7003 172.17.0.4:7004
12288-16383 12288-16383 8192-9556 12288-16383 8192-9556 12288-16383 172.17.0.4:7005 172.17.0.4:7006
0-1364 5461-6826 10923-12287 0-1364 5461-6826 10923-12287 0-1364 5461-6826 10923-12287 0-1364 5461-6826 9557-12287 172.17.0.4:7007 172.17.0.4:7008

7003と7004のノードへのハッシュスロットの割当がなくなった。

  • ノードの削除
# redis-trib.rb del-node 172.17.0.4:7004 e924857295ad43ccf9f2d792872e4d41293cab07
# redis-trib.rb del-node 172.17.0.4:7003 7d2e412e417f4d077bf50372f472f9103c480501
# redis-cli -p 7001 cluster nodes | sort -k2
1b6d03569f09e6009a25b941887ac1275759d172 172.17.0.4:7001 myself,master - 0 0 5 connected 1365-5460 6827-8191
c17a5b65fb4ab1b802995ef8769edbe3290d7a03 172.17.0.4:7002 slave 1b6d03569f09e6009a25b941887ac1275759d172 0 1481165531737 5 connected
abe6531b02045b6e16cf51849ba6f7ff22300aa5 172.17.0.4:7005 master - 0 1481165530735 6 connected 8192-9556 12288-16383
89bc1da3bc8417e4513d33d7a175fc48764ec70a 172.17.0.4:7006 slave abe6531b02045b6e16cf51849ba6f7ff22300aa5 0 1481165529732 6 connected
0c55b1cba923d063cb7566b80f098c7dddea8f96 172.17.0.4:7007 master - 0 1481165532739 7 connected 0-1364 5461-6826 9557-12287
3ed3899c6ba3ca1371235f91cd8502297c3a46b9 172.17.0.4:7008 slave 0c55b1cba923d063cb7566b80f098c7dddea8f96 0 1481165533739 7 connected
slot master slave
1365-5460 6827-8191 172.17.0.4:7001 172.17.0.4:7002
8192-9556 12288-16383 172.17.0.4:7005 172.17.0.4:7006
0-1364 5461-6826 9557-12287 172.17.0.4:7007 172.17.0.4:7008

ノードを移動してみる

slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7003 172.17.0.4:7004
10923-16383 172.17.0.4:7005 172.17.0.4:7006

↓こうしたい

slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7007 172.17.0.4:7008
10923-16383 172.17.0.4:7005 172.17.0.4:7006
  • 事前準備

先程作成したクラスター構成を作り直す

ノード停止
# for ii in `seq 7001 7008`; do /redis/redis-3.2.6/utils/redis_init_script stop $ii; done

rdbファイルとクラスター構成ファイルを削除する
# ls /redis/
dump_7001.rdb  dump_7002.rdb  dump_7003.rdb  dump_7004.rdb  dump_7005.rdb  dump_7006.rdb  dump_7007.rdb  dump_7008.rdb  nodes_7001.conf  nodes_7002.conf  nodes_7003.conf  nodes_7004.conf  nodes_7005.conf  nodes_7006.conf  nodes_7007.conf  nodes_7008.conf  redis-3.2.6  redis-3.2.6.tar.gz

# rm -f /redis/*.rdb /redis/nodes*.conf

6台構成でクラスター作成するに戻って再作成

こういう状態にする。ポート7007と7008のノードはクラスターに参加していない状態。

# redis-cli -p 7001 cluster nodes | sort -k2
550a91f2f1a88e5630ee8e6c3d1d61970715de2b 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
f7b36ed09baeae6d65004e066f11c1b0552cffe7 172.17.0.4:7002 slave 550a91f2f1a88e5630ee8e6c3d1d61970715de2b 0 1481166155471 1 connected
269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 172.17.0.4:7003 master - 0 1481166157474 2 connected 5461-10922
77d3ce18b67647392b753bbbf1148870b3581d42 172.17.0.4:7004 slave 269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 0 1481166156472 2 connected
c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 172.17.0.4:7005 master - 0 1481166152466 3 connected 10923-16383
40d5b8e1241560b53d114b4e363935de66fe5646 172.17.0.4:7006 slave c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 0 1481166156973 3 connected

# ps aux | grep redis
root      22562  0.0  0.0  38740  3092 ?        Rsl  03:01   0:00 /usr/local/bin/redis-server *:7001 [cluster]
root      22565  0.0  0.0  36692  2840 ?        Ssl  03:01   0:00 /usr/local/bin/redis-server *:7002 [cluster]
root      22572  0.0  0.0  38740  3036 ?        Ssl  03:01   0:00 /usr/local/bin/redis-server *:7003 [cluster]
root      22576  0.0  0.0  36692  2828 ?        Ssl  03:01   0:00 /usr/local/bin/redis-server *:7004 [cluster]
root      22582  0.0  0.0  38740  3056 ?        Ssl  03:01   0:00 /usr/local/bin/redis-server *:7005 [cluster]
root      22585  0.0  0.0  36692  2816 ?        Ssl  03:01   0:00 /usr/local/bin/redis-server *:7006 [cluster]
root      22604  0.0  0.0  36692  2564 ?        Ssl  03:02   0:00 /usr/local/bin/redis-server *:7007 [cluster]
root      22607  0.0  0.0  36692  2564 ?        Ssl  03:02   0:00 /usr/local/bin/redis-server *:7008 [cluster]
root      22615  0.0  0.0   6440   696 ?        S+   03:03   0:00 grep redis
  • 7007のノードを7003のノードのスレーブにする
# redis-trib.rb add-node --slave 172.17.0.4:7007 172.17.0.4:7003

# redis-cli -p 7001 cluster nodes | sort -k2
550a91f2f1a88e5630ee8e6c3d1d61970715de2b 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
f7b36ed09baeae6d65004e066f11c1b0552cffe7 172.17.0.4:7002 slave 550a91f2f1a88e5630ee8e6c3d1d61970715de2b 0 1481166293708 1 connected
269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 172.17.0.4:7003 master - 0 1481166294710 2 connected 5461-10922
77d3ce18b67647392b753bbbf1148870b3581d42 172.17.0.4:7004 slave 269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 0 1481166290702 2 connected
c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 172.17.0.4:7005 master - 0 1481166291704 3 connected 10923-16383
40d5b8e1241560b53d114b4e363935de66fe5646 172.17.0.4:7006 slave c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 0 1481166290201 3 connected
eaa0636eaa96d62b20a6440d132ec57addf07109 172.17.0.4:7007 slave 269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 0 1481166289700 2 connected 追加された
slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7003 172.17.0.4:7004
172.17.0.4:7007
10923-16383 172.17.0.4:7005 172.17.0.4:7006
  • 7004のノードを抜く
# redis-trib.rb del-node 127.0.0.1:7004 77d3ce18b67647392b753bbbf1148870b3581d42

# redis-cli -p 7001 cluster nodes | sort -k2
550a91f2f1a88e5630ee8e6c3d1d61970715de2b 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
f7b36ed09baeae6d65004e066f11c1b0552cffe7 172.17.0.4:7002 slave 550a91f2f1a88e5630ee8e6c3d1d61970715de2b 0 1481166368835 1 connected
269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 172.17.0.4:7003 master - 0 1481166366834 2 connected 5461-10922
c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 172.17.0.4:7005 master - 0 1481166365831 3 connected 10923-16383
40d5b8e1241560b53d114b4e363935de66fe5646 172.17.0.4:7006 slave c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 0 1481166369838 3 connected
eaa0636eaa96d62b20a6440d132ec57addf07109 172.17.0.4:7007 slave 269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 0 1481166370839 2 connected
slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7003 172.17.0.4:7007
10923-16383 172.17.0.4:7005 172.17.0.4:7006
  • 7003のマスターノード - 7007のスレーブノードをフェールオーバする スレーブ側で実施する
# redis-cli -p 7007 cluster failover

# redis-cli -p 7001 cluster nodes | sort -k2
550a91f2f1a88e5630ee8e6c3d1d61970715de2b 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
f7b36ed09baeae6d65004e066f11c1b0552cffe7 172.17.0.4:7002 slave 550a91f2f1a88e5630ee8e6c3d1d61970715de2b 0 1481166471012 1 connected
269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 172.17.0.4:7003 slave eaa0636eaa96d62b20a6440d132ec57addf07109 0 1481166467004 4 connected
c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 172.17.0.4:7005 master - 0 1481166470010 3 connected 10923-16383
40d5b8e1241560b53d114b4e363935de66fe5646 172.17.0.4:7006 slave c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 0 1481166469008 3 connected
eaa0636eaa96d62b20a6440d132ec57addf07109 172.17.0.4:7007 master - 0 1481166468006 4 connected 5461-10922
slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7007 172.17.0.4:7003
10923-16383 172.17.0.4:7005 172.17.0.4:7006
  • 7008のノードを7007のノードのスレーブにする
# redis-trib.rb add-node --slave 172.17.0.4:7008 172.17.0.4:7007

# redis-cli -p 7001 cluster nodes | sort -k2
550a91f2f1a88e5630ee8e6c3d1d61970715de2b 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
f7b36ed09baeae6d65004e066f11c1b0552cffe7 172.17.0.4:7002 slave 550a91f2f1a88e5630ee8e6c3d1d61970715de2b 0 1481166527103 1 connected
269d5a679b3bc24c47ecd0fc5cea911fbcc329b2 172.17.0.4:7003 slave eaa0636eaa96d62b20a6440d132ec57addf07109 0 1481166528104 4 connected
c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 172.17.0.4:7005 master - 0 1481166526602 3 connected 10923-16383
40d5b8e1241560b53d114b4e363935de66fe5646 172.17.0.4:7006 slave c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 0 1481166524598 3 connected
eaa0636eaa96d62b20a6440d132ec57addf07109 172.17.0.4:7007 master - 0 1481166522094 4 connected 5461-10922
13a4814123df21a1ead7616f2e801e2d47749396 172.17.0.4:7008 slave eaa0636eaa96d62b20a6440d132ec57addf07109 0 1481166529106 4 connected
slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7007 172.17.0.4:7003
172.17.0.4:7008
10923-16383 172.17.0.4:7005 172.17.0.4:7006
  • 7003のノードを抜く。
# redis-trib.rb del-node 127.0.0.1:7003 269d5a679b3bc24c47ecd0fc5cea911fbcc329b2

# redis-cli -p 7001 cluster nodes | sort -k2
550a91f2f1a88e5630ee8e6c3d1d61970715de2b 172.17.0.4:7001 myself,master - 0 0 1 connected 0-5460
f7b36ed09baeae6d65004e066f11c1b0552cffe7 172.17.0.4:7002 slave 550a91f2f1a88e5630ee8e6c3d1d61970715de2b 0 1481166593220 1 connected
c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 172.17.0.4:7005 master - 0 1481166587711 3 connected 10923-16383
40d5b8e1241560b53d114b4e363935de66fe5646 172.17.0.4:7006 slave c2fa1ae4060ad07ca30ea0c762e1e32d6e480360 0 1481166592219 3 connected
eaa0636eaa96d62b20a6440d132ec57addf07109 172.17.0.4:7007 master - 0 1481166593721 4 connected 5461-10922
13a4814123df21a1ead7616f2e801e2d47749396 172.17.0.4:7008 slave eaa0636eaa96d62b20a6440d132ec57addf07109 0 1481166594223 4 connected
slot master slave
0-5460 172.17.0.4:7001 172.17.0.4:7002
5461-10922 172.17.0.4:7007 172.17.0.4:7008
10923-16383 172.17.0.4:7005 172.17.0.4:7006