Redis 5 Clusterクラスタ構築構成およびFailed to send CLUSTER MEET command

14790 ワード

redisクラスタは3種類に分けられる:主従複製、哨兵モード、clusterクラスタ本論文ではclusterクラスタモードを使用し、優劣は自分で調べることができる.
環境
3台のマシン1台につき1つのmaster(7001)1つのslave(7002)の合計3つのmaster 3つのslave axe 1(192.168.86.101)7001(master)7002(slave)axe 2(192.168.86.102)7001(master)7002(slave)axe 3(192.168.86.103)7001(master)7002(slave)redisバージョン:最新のredis-5.0.5
 
実行
 
各マシンで以下の手順を実行して/home/filesディレクトリにダウンロードし、/usr/下にインストールします.
cd /home/files
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
cp /home/files/redis-5.0.5.tar.gz /usr/
cd /usr
tar -zxvf redis-5.0.5.tar.gz
cd redis-5.0.5
make

gccがないとエラーが表示されるので、このときgccをインストールします.
yum -y install gcc gcc-c++ kernel-devel

次にmakeを再実行し、終了したら
[root@axe1 redis-5.0.5]# mkdir 17001
[root@axe1 redis-5.0.5]# mkdir 17002


#          
[root@axe1 redis-5.0.5]# cd 17001/
[root@axe1 17001]# cp ../redis.conf ../17001/17001redis.conf
[root@axe1 17001]# mkdir logs

[root@axe1 redis-5.0.5]# cd 17002/
[root@axe1 17002]# cp ../redis.conf ../17002/17002redis.conf
[root@axe1 17002]# mkdir logs

プロファイル17001 redisを変更する.confと17002 redis.confプロファイルは、後述します.
各redisサービスオープンポートを起動し、firewallが設定されていなければ、オープンポートの操作を行わなくてもよい
#systemctl status firewalld
firewall-cmd --zone=public --add-port=17001/tcp --permanent
firewall-cmd --zone=public --add-port=17002/tcp --permanent
firewall-cmd --zone=public --add-port=7001/tcp --permanent
firewall-cmd --zone=public --add-port=7002/tcp --permanent
firewall-cmd --reload

なお、ここで使用するポートは7001と7002であり、公式サイトの説明によれば、7001と7002をオンにすると同時に、redisは17001と17002のポートをオンにしてクラスタ選挙通信用(CLUSTER MEET)をオンにする.すなわち、使用ポートの大きさに10000(ポートがXXXXであれば、通信ウィンドウは1 XXXX)を加える.
#ループ各ノードが先に起動します17001
/usr/redis-5.0.5/src/redis-server /usr/redis-5.0.5/17001/17001redis.conf &

#17001起動完了後、各ノードをループして再起動17002
/usr/redis-5.0.5/src/redis-server /usr/redis-5.0.5/17002/17002redis.conf &

実行ステータスの表示
[root@axe1 ~]# ps -ef|grep redis
root      19979      1  0 19:01 ?        00:00:00 /usr/redis-5.0.5/src/redis-server 0.0.0.0:17001 [cluster]
root      19993      1  0 19:02 ?        00:00:00 /usr/redis-5.0.5/src/redis-server 0.0.0.0:17002 [cluster]
root      19999    986  0 19:02 pts/0    00:00:00 grep --color=auto redis

すべてのノードのmasterとslaveが起動すると、クラスタが直接作成されます.5.0以前のバージョンではrubyのredis-tribが使用されています.rbは起動クラスタの作成を行い、5.0以降は使用せずredis-cliを直接使用する
#   
/usr/redis-5.0.5/src/redis-cli -a pwd@redis --cluster create 192.168.86.101:7001 192.168.86.102:7001 192.168.86.103:7001 192.168.86.101:7002 192.168.86.102:7002 192.168.86.103:7002 --cluster-replicas 1
#   
/usr/redis-5.0.5/src/redis-cli --cluster create 192.168.86.101:7001 192.168.86.102:7001 192.168.86.103:7001 192.168.86.101:7002 192.168.86.102:7002 192.168.86.103:7002 --cluster-replicas 1
#               -p xxxx

注意、hostnameで起動することはできません.ipアドレスしか使用できません.hostnameを使用するとエラーが表示され、redisは認識できません.
[root@axe1 ~]# /usr/redis-5.0.5/src/redis-cli  --cluster create axe1:17001 axe2:17001 axe3:17001 axe1:17002 axe2:17002 axe3:17002 --cluster-replicas 1
[ERR] Node axe1:17001 is not configured as a cluster node.

起動成功
[root@axe1 ~]# /usr/redis-5.0.5/src/redis-cli -a pwd@redis --cluster create 192.168.86.101:7001 192.168.86.102:7001 192.168.86.103:7001 192.168.86.101:7002 192.168.86.102:7002 192.168.86.103:7002 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.86.102:7002 to 192.168.86.101:7001
Adding replica 192.168.86.103:7002 to 192.168.86.102:7001
Adding replica 192.168.86.101:7002 to 192.168.86.103:7001
M: 0d340d927aec46a68965f530e02723283924f139 192.168.86.101:7001
   slots:[0-5460] (5461 slots) master
M: e8128103254836740bf14e4de8bf2de996f89fea 192.168.86.102:7001
   slots:[5461-10922] (5462 slots) master
M: 8c6bd94cc5766a6aa261c5d46e3d5fc60fe750a4 192.168.86.103:7001
   slots:[10923-16383] (5461 slots) master
S: 780c11bdad77c5c27c0766b7d5c22ec501ae3eb2 192.168.86.101:7002
   replicates 8c6bd94cc5766a6aa261c5d46e3d5fc60fe750a4
S: 4eaa35eb64843307c72ee0cb660a73cb60af0406 192.168.86.102:7002
   replicates 0d340d927aec46a68965f530e02723283924f139
S: 09238ec70f91fe129a832c500f409b28c79b6bbf 192.168.86.103:7002
   replicates e8128103254836740bf14e4de8bf2de996f89fea
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 192.168.86.101:7001)
M: 0d340d927aec46a68965f530e02723283924f139 192.168.86.101:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 780c11bdad77c5c27c0766b7d5c22ec501ae3eb2 192.168.86.101:7002
   slots: (0 slots) slave
   replicates 8c6bd94cc5766a6aa261c5d46e3d5fc60fe750a4
S: 09238ec70f91fe129a832c500f409b28c79b6bbf 192.168.86.103:7002
   slots: (0 slots) slave
   replicates e8128103254836740bf14e4de8bf2de996f89fea
M: 8c6bd94cc5766a6aa261c5d46e3d5fc60fe750a4 192.168.86.103:7001
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 4eaa35eb64843307c72ee0cb660a73cb60af0406 192.168.86.102:7002
   slots: (0 slots) slave
   replicates 0d340d927aec46a68965f530e02723283924f139
M: e8128103254836740bf14e4de8bf2de996f89fea 192.168.86.102: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.

本明細書で構成するbingのipアドレスには127.0.0.1がないため、ネイティブがredis-cliクライアントにログインすると、接続拒否Connection refusedがエラーで報告される
[root@axe1 ~]# /usr/redis-5.0.5/src/redis-cli -p 7001
Could not connect to Redis at 127.0.0.1:7001: Connection refused
not connected>

だからどのようにログインして、axe 1を使ってaxe 2にログインすることができて、axe 3を使ってaxe 1にログインして、機械を交換して
ログインとデータの追加
パスワードがある場合は、パスワードを指定する必要があります.そうしないと、エラーが発生します.
[root@axe1 ~]# /usr/redis-5.0.5/src/redis-cli -h axe2 -p 7001
axe2:7001> set 'testkey' 'testvalue'
(error) NOAUTH Authentication required.

ここではパスワードを使用してaxe 2にログインします.
[root@axe1 ~]# /usr/redis-5.0.5/src/redis-cli -h axe2 -p 7001 -a pwd@redis
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
axe2:7001> set 'testkey' 'testvalue'
(error) MOVED 4757 192.168.86.101:7001
axe2:7001>

エラーは、現在のスロットビット(slot)がaxe 1にあるためaxe 1でset getを行う必要があるが、axe 1はネイティブに登録できない(bind 127.0.0.1なし)ため、axe 2マシンにaxe 1を登録する
 
[root@axe2 ~]# /usr/redis-5.0.5/src/redis-cli -h axe1 -p 7001 -a pwd@redis
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
axe1:7001> set 'testkey' 'testvalue'
OK
axe1:7001> get 'testkey'
"testvalue"

 
現在のクラスタの情報とステータスは、任意のノードで表示できます.
 
axe1:7001> cluster nodes
780c11bdad77c5c27c0766b7d5c22ec501ae3eb2 192.168.86.101:7002@17002 slave 8c6bd94cc5766a6aa261c5d46e3d5fc60fe750a4 0 1561455953052 4 connected
09238ec70f91fe129a832c500f409b28c79b6bbf 192.168.86.103:7002@17002 slave e8128103254836740bf14e4de8bf2de996f89fea 0 1561455954062 6 connected
8c6bd94cc5766a6aa261c5d46e3d5fc60fe750a4 192.168.86.103:7001@17001 master - 0 1561455953000 3 connected 10923-16383
0d340d927aec46a68965f530e02723283924f139 192.168.86.101:7001@17001 myself,master - 0 1561455953000 1 connected 0-5460
4eaa35eb64843307c72ee0cb660a73cb60af0406 192.168.86.102:7002@17002 slave 0d340d927aec46a68965f530e02723283924f139 0 1561455953000 5 connected
e8128103254836740bf14e4de8bf2de996f89fea 192.168.86.102:7001@17001 master - 0 1561455955070 2 connected 5461-10922
axe1:7001> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_ping_sent:1888
cluster_stats_messages_pong_sent:1920
cluster_stats_messages_sent:3808
cluster_stats_messages_ping_received:1915
cluster_stats_messages_pong_received:1888
cluster_stats_messages_meet_received:5
cluster_stats_messages_received:3808
axe1:7001>

 
クラスタの作成が完了しました.
次にプロファイルを見て、まず説明を見て、ファイルは最後に
 
プロファイルの説明
 
では、コンフィギュレーションファイルでは、ほとんどがデフォルトのコンフィギュレーションを使用できます.いくつかの点で変更する必要があります.
port 7002:          
bind:       ip(axe1  192.168.86.101,axe2  192.168.86.102,axe3  192.168.86.103)
protected-mode no:      
cluster-enabled yes:      ,   no,             ,      
cluster-config-file /usr/redis-5.0.5/17002/nodes-17002.conf:                  ,     ,      ,              ,        ,                 
cluster-node-timeout 5000:    
pidfile /usr/redis-5.0.5/17001/redis_17001.pid :         id  ,             ,        
logfile /usr/redis-5.0.5/17001/logs/redis.log :         ,             ,        
dir /usr/redis-5.0.5/17001:     rdb         ,             ,        
daemonize yes:      

キータイムアウト
timeout:この構成は0に設定する必要があります.そうしないと、Failed to send CLUSTER MEET commandとエラーが発生します.この問題は私が一日処理して、CLUSTER MEETの役割はすべて何度も調べて、最後にtimeoutに出ました.
 
[root@axe1 ~]# /usr/redis-5.0.5/src/redis-cli -a pwd@redis --cluster create 192.168.86.101:7001 192.168.86.102:7001 192.168.86.103:7001 192.168.86.101:7002 192.168.86.102:7002 192.168.86.103:7002 --cluster              -replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.86.102:7002 to 192.168.86.101:7001
Adding replica 192.168.86.103:7002 to 192.168.86.102:7001
Adding replica 192.168.86.101:7002 to 192.168.86.103:7001
M: d002a6da938782f9fd767df7d562fa03958bb738 192.168.86.101:7001
   slots:[0-5460] (5461 slots) master
M: 0c83e15247182aae7a8ecc3fcdd1fad93ccf235d 192.168.86.102:7001
   slots:[5461-10922] (5462 slots) master
M: cde83649adffc986916a8b6bf6d76c6b6c6a0fde 192.168.86.103:7001
   slots:[10923-16383] (5461 slots) master
S: 3633747cb6613d50b6bb824664fb3d7f6fddd9cb 192.168.86.101:7002
   replicates cde83649adffc986916a8b6bf6d76c6b6c6a0fde
S: a139d0669969ef70c9cdaac293ee510cc6abb66b 192.168.86.102:7002
   replicates d002a6da938782f9fd767df7d562fa03958bb738
S: 29137268085bd0dd2c8de849f0649d69bb735f27 192.168.86.103:7002
   replicates 0c83e15247182aae7a8ecc3fcdd1fad93ccf235d
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
Failed to send CLUSTER MEET command.

 
プロファイル17001 redis.confg
#      bind     ip
bind 192.168.86.101
port 7001
tcp-backlog 511
daemonize yes
supervised no
pidfile /usr/redis-5.0.5/17001/redis_17001.pid
loglevel notice
logfile /usr/redis-5.0.5/17001/logs/redis.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/redis-5.0.5/17001
masterauth pwd@redis
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass pwd@redis
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file /usr/redis-5.0.5/17001/nodes-17001.conf
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

 
プロファイル17002 redis.confg
 
#      bind     ip
bind 192.168.86.101
port 7002
tcp-backlog 511
daemonize yes
supervised no
pidfile /usr/redis-5.0.5/17002/redis_17002.pid
loglevel notice
logfile /usr/redis-5.0.5/17002/logs/redis.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/redis-5.0.5/17002
masterauth pwd@redis
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass pwd@redis
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file /usr/redis-5.0.5/17002/nodes-17002.conf
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes

 
終わって、助けがあってほめて、疑問があって評論することができます