redis 5.0集群搭建

1.wget redis官方路径,解压 tar  安装 make MALLOC=libc

2.配置多个redisxx.conf 文件
port 7001  #需要改变
bind 10.10.20.48  #本机ip
daemonize yes  #后台启动
pidfile /var/run/redis_7001.pid
cluster-enabled yes #集群服务
cluster-config-file nodes_7001.conf
cluster-node-timeout 15000
appendonly yes

3.启动多个redis 服务 
./redis/src/redis-server  redisxx.conf

4.开启集群服务
  ./redis-cli --cluster create 10.10.20.48:7001 10.10.20.48:7002 10.10.20.48:7003 10.10.20.49:7001 10.10.20.49:7002 10.10.20.49:7003 --cluster-replicas 1 
create命令来创建一个新的集群。 --replicas 1 表示我们想为每个master指定一个slave
启动error
坑1:yum intall ruby ,需要ruby环境
坑2:以为只打开对应的端口号就可以了,还需要打开数据端口
每个Redis集群中的节点都需要打开两个TCP连接。一个用于正常的给Client提供服务,比如6379,还有一个额外的端口(通过在这个端口号上加10000)作为数据端口,比如16379。第二个端口(本例中就是16379)用于集群总线,这是一个用二进制协议的点对点通信信道。这个集群总线(Cluster bus)用于节点的失败侦测、配置更新、故障转移授权,等等。客户端从来都不应该尝试和这些集群总线端口通信,它们只应该和正常的Redis命令端口进行通信。注意,确保在你的防火墙中开放着两个端口,否则,Redis集群节点之间将无法通信

5.集群成功结果
Waiting for the cluster to join
......
>>> Performing Cluster Check (using node 10.10.20.48:16379)
M: 8cba32f8f38d78a3bbd4cfd6dc6563ce982cfea5 10.10.20.48:7002
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 24bba2e1ddcf402cef9ab2b4f08fced17cffe7ea 10.10.20.49:7003
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: b0f980a72c11c9bb9b20955ee33bdece0de86d43 10.10.20.49:7002
   slots: (0 slots) slave
   replicates 2e1cb84bf5a354a853ee4a7ff5652b3bac4e1a77
S: e1e4917280c83bd51f9fa5ce4a1f19acc1b27b36 10.10.20.49:7001
   slots: (0 slots) slave
   replicates 8cba32f8f38d78a3bbd4cfd6dc6563ce982cfea5
M: 2e1cb84bf5a354a853ee4a7ff5652b3bac4e1a77 10.10.20.48:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: 19b9def6b24e0648fd5d6c5834de51601e235f55 10.10.20.48:7001
   slots: (0 slots) slave
   replicates 24bba2e1ddcf402cef9ab2b4f08fced17cffe7ea
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

6.查看集群状态
6.1任意进入一台redis客户端
./redis-cli -h 10.10.20.48 -p 7002
6.2 cluster nodes 
10.10.20.49:7002> cluster nodes
110938e0a16c03381917789a02f52df9f458fe0b 10.10.20.49:7003@17003 slave 90f10d1a28dfcdcb4b0e660ddc357a1025afec45 0 1562639077569 6 connected
04c5da943f1dddd57329ae9b70e7f0299d564166 10.10.20.48:7003@17003 slave 9d8f3a2a73a61fe5e22138048ad40702c982fa80 0 1562639075000 4 connected
9d8f3a2a73a61fe5e22138048ad40702c982fa80 10.10.20.49:7001@17001 master - 0 1562639076560 4 connected 5461-10922
df557eadf5f5158187f612471d2767f874c25412 10.10.20.48:7002@17002 master - 0 1562639074546 2 connected 10923-16383
90f10d1a28dfcdcb4b0e660ddc357a1025afec45 10.10.20.48:7001@17001 master - 0 1562639075553 1 connected 0-5460
3b59c8780786599fd20b649b7f6e67b5f63ba58d 10.10.20.49:7002@17002 myself,slave df557eadf5f5158187f612471d2767f874c25412 0 1562639076000 5 connected
6.3停止48:7002(master) shutdown
6.4查看集群状态
10.10.20.48:7001> cluster nodes
90f10d1a28dfcdcb4b0e660ddc357a1025afec45 10.10.20.48:7001@17001 myself,master - 0 1562639565000 1 connected 0-5460
04c5da943f1dddd57329ae9b70e7f0299d564166 10.10.20.48:7003@17003 slave 9d8f3a2a73a61fe5e22138048ad40702c982fa80 0 1562639566650 4 connected
df557eadf5f5158187f612471d2767f874c25412 10.10.20.48:7002@17002 master,fail - 1562639547846 1562639547000 2 disconnected
3b59c8780786599fd20b649b7f6e67b5f63ba58d 10.10.20.49:7002@17002 master - 0 1562639565637 7 connected 10923-16383
110938e0a16c03381917789a02f52df9f458fe0b 10.10.20.49:7003@17003 slave 90f10d1a28dfcdcb4b0e660ddc357a1025afec45 0 1562639566000 6 connected
9d8f3a2a73a61fe5e22138048ad40702c982fa80 10.10.20.49:7001@17001 master - 0 1562639564628 4 connected 5461-10922
发现10.10.20.49:7002@17002,由slave->master; 10.10.20.48:7002@17002 master,fail
6.5重新启动48:7002
6.6查看集群新的状态
10.10.20.48:7001> cluster nodes
90f10d1a28dfcdcb4b0e660ddc357a1025afec45 10.10.20.48:7001@17001 myself,master - 0 1562640483000 1 connected 0-5460
04c5da943f1dddd57329ae9b70e7f0299d564166 10.10.20.48:7003@17003 slave 9d8f3a2a73a61fe5e22138048ad40702c982fa80 0 1562640484326 4 connected
df557eadf5f5158187f612471d2767f874c25412 10.10.20.48:7002@17002 slave 3b59c8780786599fd20b649b7f6e67b5f63ba58d 0 1562640485000 7 connected
3b59c8780786599fd20b649b7f6e67b5f63ba58d 10.10.20.49:7002@17002 master - 0 1562640486341 7 connected 10923-16383
110938e0a16c03381917789a02f52df9f458fe0b 10.10.20.49:7003@17003 slave 90f10d1a28dfcdcb4b0e660ddc357a1025afec45 0 1562640486000 6 connected
9d8f3a2a73a61fe5e22138048ad40702c982fa80 10.10.20.49:7001@17001 master - 0 1562640485331 4 connected 5461-10922

发现10.10.20.48:7002@17002 master,fail 转变为slave

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(linux)