其中Master的节点是:192.8.8.136:7000/192.8.8.137:7001/192.8.8.138:7002分布在不同的服务器上,该集群的搭建的实现了负载均衡,至此redis集群的搭建过程基本完毕;
9、检查集群状态
[redistest@ip-172-18-98-136 redis]$ ./redis-trib.rb check 192.8.8.136:7000
>>> Performing Cluster Check (using node 192.8.8.136:7000)
M: 6780f0fadd82825d04e524fd81fa710403e7152e 192.8.8.136:7000
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: 6f9c383ec47461c2a86265f5db506e10397605d8 192.8.8.138:7002
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 6e4ae3851e018c08ba5cec96f113815db1931b4d 192.8.8.136:7001
slots: (0 slots) slave
replicates 6780f0fadd82825d04e524fd81fa710403e7152e
S: fc510e5cdcc78a42ef871251736d365db5311c7f 192.8.8.137:7002
slots: (0 slots) slave
replicates 6f9c383ec47461c2a86265f5db506e10397605d8
M: b00521fd8b0fae93d9e56fa6afe505ec9574c399 192.8.8.137:7001
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 5b39cd3bd706d30b5470089f71bd29738b306d3b 192.8.8.138:7000
slots: (0 slots) slave
replicates b00521fd8b0fae93d9e56fa6afe505ec9574c399
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
[redistest@ip-172-18-98-136 redis]$ ./redis-trib.rb info 192.8.8.136:7000
192.8.8.136:7000 (6780f0fa...) -> 0 keys | 5461 slots | 1 slaves.
192.8.8.138:7002 (6f9c383e...) -> 0 keys | 5461 slots | 1 slaves.
192.8.8.137:7001 (b00521fd...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
10 、检查集群信息
./redis-trib.rb info 192.8.8.136:7000
11、如果在执行./redis-trib.rb create --replicas 过程中,长时间没有完成,或者遇到其他错误。如果需要重新执行配置集群的话。
需要关闭redis实例,删除7000/7001/7002目录下,除了redis.conf文件之外的全部文件,再启动redis实例,并再次执行./redis-trib.rb create即可。
12、连接数据库,查询数据
[root@localhost src]# redis-cli -c -p 7000
127.0.0.1:7000> cluster meet 127.0.0.1 7000
OK
至此,redis集群已经大家完成,下面我们需要完成redis随着操作系统启动,减少后续维护的成本。
13、编辑文件/home/redistest/startAll.sh,注意,要写全路径
/home/redistest/redis/redis-server /home/redistest/redis/7000/redis.conf
/home/redistest/redis/redis-server /home/redistest/redis/7001/redis.conf
命令行,加入/etc/rc.local文件夹下,需要以redistest用户启动redis
su - redistest -c /home/redistest/startAll.sh
相关资料可从以下信息得到下载: