三、创建集群
怎么样把redis各个节点组合起来来搭建集群。官方提供的工具:redis-trib.rb(/usr/local/redis-3.2.1/src/redis-trib.rb) 是用ruby写的一个程序,因此还需要安装ruby.
1.配置安装工具
yum -y install ruby ruby-devel rubygems rpm-build
因为网络原因:gem install redis失败
只好手工下载安装:
wget
[root@rediscls01 ~]# gem install -l ./redis-3.3.1.gem
Successfully installed redis-3.3.1
1 gem installed
Installing ri documentation for redis-3.3.1...
Installing RDoc documentation for redis-3.3.1...
2、创建redis cluster
在第一个服务器上运行
[root@rediscls01 redis-cluster]# /usr/local/redis/src/redis-trib.rb create --replicas 1 192.168.56.21:7000 192.168.56.21:7001 192.168.56.21:7002 192.168.56.22:7003
192.168.56.22:7004 192.168.56.22:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.56.22:7003
192.168.56.21:7000
192.168.56.22:7004
Adding replica 192.168.56.21:7001 to 192.168.56.22:7003
Adding replica 192.168.56.22:7005 to 192.168.56.21:7000
Adding replica 192.168.56.21:7002 to 192.168.56.22:7004
M: 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a 192.168.56.21:7000
slots:5461-10922 (5462 slots) master
S: e6678b43ea46f500cf6eacbe2295af6b91e54193 192.168.56.21:7001
replicates 12f700e533e195cd7620112a80b5f2ba2af054aa
S: 2314d710c4ca4ad7baa2abdad9b97b9329aa7789 192.168.56.21:7002
replicates 8cf406f09a89cede69ab2ae84899a679cc1c2981
M: 12f700e533e195cd7620112a80b5f2ba2af054aa 192.168.56.22:7003
slots:0-5460 (5461 slots) master
M: 8cf406f09a89cede69ab2ae84899a679cc1c2981 192.168.56.22:7004
slots:10923-16383 (5461 slots) master
S: 9c7a3a7f4a6d4515a52534624ce2e43de3de9fc2 192.168.56.22:7005
replicates 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a
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.56.21:7000)
M: 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a 192.168.56.21:7000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 8cf406f09a89cede69ab2ae84899a679cc1c2981 192.168.56.22:7004
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 2314d710c4ca4ad7baa2abdad9b97b9329aa7789 192.168.56.21:7002
slots: (0 slots) slave
replicates 8cf406f09a89cede69ab2ae84899a679cc1c2981
S: 9c7a3a7f4a6d4515a52534624ce2e43de3de9fc2 192.168.56.22:7005
slots: (0 slots) slave
replicates 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a
M: 12f700e533e195cd7620112a80b5f2ba2af054aa 192.168.56.22:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: e6678b43ea46f500cf6eacbe2295af6b91e54193 192.168.56.21:7001
slots: (0 slots) slave
replicates 12f700e533e195cd7620112a80b5f2ba2af054aa
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
如上cluster创建结果:
Master 7000 7004 7003
Slave 7002 7005 7001
至此,redis cluster集群创建完毕
四、集群信息:
127.0.0.1:7000> CLUSTER NODES
8cf406f09a89cede69ab2ae84899a679cc1c2981 192.168.56.22:7004 master - 0 1478674477648 5 connected 10923-16383
04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a 192.168.56.21:7000 myself,master - 0 0 1 connected 5461-10922
2314d710c4ca4ad7baa2abdad9b97b9329aa7789 192.168.56.21:7002 slave 8cf406f09a89cede69ab2ae84899a679cc1c2981 0 1478674477146 5 connected
9c7a3a7f4a6d4515a52534624ce2e43de3de9fc2 192.168.56.22:7005 slave 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a 0 1478674478150 6 connected
12f700e533e195cd7620112a80b5f2ba2af054aa 192.168.56.22:7003 master - 0 1478674476140 4 connected 0-5460
e6678b43ea46f500cf6eacbe2295af6b91e54193 192.168.56.21:7001 slave 12f700e533e195cd7620112a80b5f2ba2af054aa 0 1478674476644 4 connected
集群状态检查
[root@rediscls01 ~]# redis-trib.rb check 192.168.56.21:7000
>>> Performing Cluster Check (using node 192.168.56.21:7000)
M: 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a 192.168.56.21:7000
slots:5461-10922 (5462 slots) master
1 additional replica(s)
M: 8cf406f09a89cede69ab2ae84899a679cc1c2981 192.168.56.22:7004
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 2314d710c4ca4ad7baa2abdad9b97b9329aa7789 192.168.56.21:7002
slots: (0 slots) slave
replicates 8cf406f09a89cede69ab2ae84899a679cc1c2981
S: 9c7a3a7f4a6d4515a52534624ce2e43de3de9fc2 192.168.56.22:7005
slots: (0 slots) slave
replicates 04e1c93333ca47fe6f3e18ef73bc7f69e9d9a13a
M: 12f700e533e195cd7620112a80b5f2ba2af054aa 192.168.56.22:7003
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: e6678b43ea46f500cf6eacbe2295af6b91e54193 192.168.56.21:7001
slots: (0 slots) slave
replicates 12f700e533e195cd7620112a80b5f2ba2af054aa
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
五、redis cluster测试
1.连通性测试;
登陆redis各节点进行验证。
2.数据库操作功能测试;
对redis cluster 进行
get 和 set数据的测试。
3.高可用测试;
对各节点和服务器进行failover测试。
---The end