在前两篇文章《大数据学习初级入门教程(二) —— Redis 3.x 单节点的安装、启动和测试》和《大数据学习初级入门教程(六) —— Redis 3.x 伪分布式集群的安装、配置、启动和测试》中,已经对 Redis3.x 的单节点安装和伪分布式集群安装做了安装、配置、启动和测试,这篇文章主要对 Redis3.x 完全分布式集群安装进行详细的图文说明。
集群搭建条件:
和搭建伪分布式集群一样,搭建集群还是需要以下几个条件,只不过伪分布式集群是在没有机器的情况下,在一台机器上模拟六个 Redis 实例来搭建集群,而分布式集群,就是完全找不同的机器搭建 Redis 集群。这里用五台机器,总共计划搭建 9 个 Redis 节点。
Redis 集群至少需要 3 个节点,这里计划搭建 9 个节点的环境,包含 Master 和 Slave;
服务器需要安装 ruby 环境。
集群搭建环境:
服务器:
CentOS release 6.9 (Final) x64,节点主机名分别为:node19(1个节点)、node18(2个节点)、node11(2个节点)、node12(2个节点)、node13(2个节点)
Java 环境:
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
Redis 版本:
redis-3.2.9.tar.gz
Ruby 版本:
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
Gem 版本:
1.3.7
Redis 和 Ruby 的接口包:
redis-3.2.1.gem
开始完全分布式集群部署:
第一步,安装第一个节点的 redis 实例。
参考 redis3.x 单节点安装,在其中一台机器上安装 Reids,这里选择在 node19 上先安装 Redis 实例,具体步骤参考《大数据学习初级入门教程(二) —— Redis 3.x 单节点的安装、启动和测试》,这里将不再细说。
node 19 安装后,Redis 路径为:/home/redis-3.2.9/bin
重命名 bin 为 6379:cd /home/redis-3.2.9 && mv bin 6379(因为其它节点都需要安装两个实例,便于区分,分别为 6379 和 6380)
第二步,修改 redis 配置文件。
注释掉bind:# bind 127.0.0.1
密码修改为:requirepass 123456
后台启动:daemonize yes
进程文件名:pidfile /var/run/redis_6379.pid
日志文件名:logfile "/var/log/redis_6379.log"
备份目录:dir /home/redis-3.2.9/6379/
集群间认证密码:masterauth 123456
放开集群配置:cluster-enabled yes
第三步,启动 Redis 实例,并测试是否启停正常。
测试命令如下:
cd /home/redis-3.2.9/6379/
./redis-server redis.conf
./redis-cli -p 6379 -a 123456
keys *
quit
ps -ef |grep redis
./redis-cli -p 6379 -a 123456 shutdown
ps -ef |grep redis
第四步,拷贝 redis 实例到其它四台机器,每台机器拷贝两个实例。
为了拷贝方便,先在第三步的 redis 实例边,再复制一个 redis 实例出来,端口统一改为 6380。只是给其它机器复制时方便用,搭建集群时可以不用这个实例节点即可。
cp -R /home/redis-3.2.9/6379/ /home/redis-3.2.9/6380
修改 6380 下的配置文件 redis.conf,其中的 6379 全部替换为 6380。
vi /home/redis-3.2.9/6380/redis.conf
用命令 :1,$s@6379@6380 完成全文件替换。
然后用下面的远程拷贝命令把 redis-3.2.9 拷贝到其它四台机器上,如果没有做免密,可能需要不断输密码。
scp -r /home/redis-3.2.9/ root@node18:/home/
scp -r /home/redis-3.2.9/ root@node11:/home/
scp -r /home/redis-3.2.9/ root@node12:/home/
scp -r /home/redis-3.2.9/ root@node13:/home/
第五步,启动 9 个实例节点。
启动 5 台机器的 9 个 redis 实例节点(计划是 node 19 的 6380 不启动,按自己需求),看看是否都启动正常。为了启动方便,这里写个启动 redis 实例服务脚本和停用 redis 实例服务脚本,放在 node 19 上。
redis_start.sh:
#!/bin/bash
echo "Redis 集群启动开始..."
echo "--------------------------------"
echo node19 "节点 redis 6379 启动开始..."
ssh node19 "cd /home/redis-3.2.9/6379/; ./redis-server redis.conf"
echo node19 "节点 redis 6379 启动结束."
for host in node18 node11 node12 node13
do
echo "--------------------------------"
echo $host "节点 redis 6379 启动开始..."
ssh $host "cd /home/redis-3.2.9/6379/; ./redis-server redis.conf"
echo $host "节点 redis 6379 启动结束."
echo $host "节点 redis 6380 启动开始..."
ssh $host "cd /home/redis-3.2.9/6380/; ./redis-server redis.conf"
echo $host "节点 redis 6380 启动结束."
done
echo "Redis 集群启动结束."
echo "--------------------------------"
echo "Redis 集群进程信息如下:"
for host in node19 node18 node11 node12 node13
do
ssh $host "hostname; ps -ef |grep redis"
done
redis_stop.sh:
#!/bin/bash
echo "Redis 集群停止开始..."
echo "--------------------------------"
echo node19 "节点 redis 6379 停止开始..."
ssh node19 "cd /home/redis-3.2.9/6379/; ./redis-cli -c -h 127.0.0.1 -p 6379 -a 123456 shutdown"
echo node19 "节点 redis 6379 停止结束."
for host in node18 node11 node12 node13
do
echo "--------------------------------"
echo $host "节点 redis 6379 停止开始..."
ssh $host "cd /home/redis-3.2.9/6379/; ./redis-cli -c -h 127.0.0.1 -p 6379 -a 123456 shutdown"
echo $host "节点 redis 6379 停止结束."
echo $host "节点 redis 6380 停止开始..."
ssh $host "cd /home/redis-3.2.9/6380/; ./redis-cli -c -h 127.0.0.1 -p 6380 -a 123456 shutdown"
echo $host "节点 redis 6380 停止结束."
done
echo "Redis 集群停止结束."
echo "--------------------------------"
echo "Redis 集群进程信息如下:"
for host in node19 node18 node11 node12 node13
do
ssh $host "hostname; ps -ef |grep redis"
done
分别运行 redis_start.sh 和 redis_stop.sh 脚本后,如果安装正常,输出大概如下:
[root@node19 sheel]# sh redis_start.sh
Redis 集群启动开始...
--------------------------------
node19 节点 redis 6379 启动开始...
node19 节点 redis 6379 启动结束.
--------------------------------
node18 节点 redis 6379 启动开始...
node18 节点 redis 6379 启动结束.
node18 节点 redis 6380 启动开始...
node18 节点 redis 6380 启动结束.
--------------------------------
node11 节点 redis 6379 启动开始...
node11 节点 redis 6379 启动结束.
node11 节点 redis 6380 启动开始...
node11 节点 redis 6380 启动结束.
--------------------------------
node12 节点 redis 6379 启动开始...
node12 节点 redis 6379 启动结束.
node12 节点 redis 6380 启动开始...
node12 节点 redis 6380 启动结束.
--------------------------------
node13 节点 redis 6379 启动开始...
node13 节点 redis 6379 启动结束.
node13 节点 redis 6380 启动开始...
node13 节点 redis 6380 启动结束.
Redis 集群启动结束.
--------------------------------
Redis 集群进程信息如下:
node19
root 2940 1590 0 20:33 pts/0 00:00:00 sh redis_start.sh
root 2947 1 1 20:33 ? 00:00:00 ./redis-server *:6379 [cluster]
root 2967 2940 0 20:33 pts/0 00:00:00 ssh node19 hostname; ps -ef |grep redis
root 2971 2968 0 20:33 ? 00:00:00 bash -c hostname; ps -ef |grep redis
node18
root 1829 1 0 20:33 ? 00:00:00 ./redis-server *:6379 [cluster]
root 1837 1 0 20:33 ? 00:00:00 ./redis-server *:6380 [cluster]
root 1843 1840 2 20:33 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1846 1843 0 20:33 ? 00:00:00 grep redis
node11
root 1788 1 1 20:33 ? 00:00:00 ./redis-server *:6379 [cluster]
root 1796 1 0 20:33 ? 00:00:00 ./redis-server *:6380 [cluster]
root 1802 1799 2 20:33 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1805 1802 0 20:33 ? 00:00:00 grep redis
node12
root 1788 1 1 20:33 ? 00:00:00 ./redis-server *:6379 [cluster]
root 1796 1 0 20:33 ? 00:00:00 ./redis-server *:6380 [cluster]
root 1802 1799 2 20:33 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1805 1802 0 20:33 ? 00:00:00 grep redis
node13
root 1773 1 1 20:33 ? 00:00:00 ./redis-server *:6379 [cluster]
root 1781 1 0 20:33 ? 00:00:00 ./redis-server *:6380 [cluster]
root 1787 1784 2 20:33 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1790 1787 0 20:33 ? 00:00:00 grep redis
[root@node19 sheel]# sh redis_stop.sh
Redis 集群停止开始...
--------------------------------
node19 节点 redis 6379 停止开始...
node19 节点 redis 6379 停止结束.
--------------------------------
node18 节点 redis 6379 停止开始...
node18 节点 redis 6379 停止结束.
node18 节点 redis 6380 停止开始...
node18 节点 redis 6380 停止结束.
--------------------------------
node11 节点 redis 6379 停止开始...
node11 节点 redis 6379 停止结束.
node11 节点 redis 6380 停止开始...
node11 节点 redis 6380 停止结束.
--------------------------------
node12 节点 redis 6379 停止开始...
node12 节点 redis 6379 停止结束.
node12 节点 redis 6380 停止开始...
node12 节点 redis 6380 停止结束.
--------------------------------
node13 节点 redis 6379 停止开始...
node13 节点 redis 6379 停止结束.
node13 节点 redis 6380 停止开始...
node13 节点 redis 6380 停止结束.
Redis 集群停止结束.
--------------------------------
Redis 集群进程信息如下:
node19
root 2982 1590 0 20:37 pts/0 00:00:00 sh redis_stop.sh
root 3003 2982 0 20:37 pts/0 00:00:00 ssh node19 hostname; ps -ef |grep redis
root 3007 3004 0 20:37 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 3010 3007 0 20:37 ? 00:00:00 grep redis
node18
root 1860 1857 0 20:37 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1863 1860 0 20:37 ? 00:00:00 grep redis
node11
root 1819 1816 2 20:37 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1822 1819 0 20:37 ? 00:00:00 grep redis
node12
root 1819 1816 2 20:37 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1822 1819 0 20:37 ? 00:00:00 grep redis
node13
root 1804 1801 2 20:37 ? 00:00:00 bash -c hostname; ps -ef |grep redis
root 1807 1804 0 20:37 ? 00:00:00 grep redis
第六步,安装 ruby 运行环境,拷贝集群搭建的脚本文件,执行搭建集群脚本,开始搭建集群
这些步骤和搭建伪分布式集群一模一样,随便选台机器做就行,这里还是在 node19 上安装环境并操作,具体步骤和操作中的错误,详细见上篇《大数据学习初级入门教程(六) —— Redis 3.x 伪分布式集群的安装、配置、启动和测试》中特别详细的说明。
创建集群命令:
./redis-trib.rb create --replicas 1 node19:6379 node18:6379 node18:6380 node11:6379 node11:6380 node12:6379 node12:6380 node13:6379 node13:6380
执行上面命令:
有错误,错误信息如下:
/usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis/client.rb:113:in `call': ERR Invalid node address specified: node19:6379 (Redis::CommandError)
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2556:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2555:in `method_missing'
from ./redis-trib.rb:811:in `join_cluster'
from ./redis-trib.rb:809:in `each'
from ./redis-trib.rb:809:in `join_cluster'
from ./redis-trib.rb:1301:in `create_cluster_cmd'
from ./redis-trib.rb:1701:in `send'
from ./redis-trib.rb:1701
这个错误说指定的节点地址无效,出现这个问题是因为 redis-trib.rb 脚本工具对本机名不识别,支持不是很好。
解决方法是:换成ip:port的方式,则问题可以得到解决。
所以用下面的命令再执行一次:
./redis-trib.rb create --replicas 1 192.168.220.19:6379 node18:6379 node18:6380 node11:6379 node11:6380 node12:6379 node12:6380 node13:6379 node13:6380
又发生错误:
/usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis/client.rb:113:in `call': ERR Slot 9238 is already busy (Redis::CommandError)
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2556:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.2.1/lib/redis.rb:2555:in `method_missing'
from ./redis-trib.rb:212:in `flush_node_config'
from ./redis-trib.rb:776:in `flush_nodes_config'
from ./redis-trib.rb:775:in `each'
from ./redis-trib.rb:775:in `flush_nodes_config'
from ./redis-trib.rb:1296:in `create_cluster_cmd'
from ./redis-trib.rb:1701:in `send'
from ./redis-trib.rb:1701
通过上一篇伪分布式搭建的错误解决中,可以知道是集群配置文件 nodes.conf 的问题,删除所有节点中的该文件,再执行上面的创建集群命令即可。
这里创建删除集群下文件的脚本 redis_delfile.sh。
redis_delfile.sh:
#!/bin/bash
echo "删除 Redis 集群下的指定文件开始..."
echo "--------------------------------"
ssh node19 "cd /home/redis-3.2.9/6379/; rm -f $1"
echo node19 "节点 redis 6379 删除文件结束."
for host in node18 node11 node12 node13
do
echo "--------------------------------"
ssh $host "cd /home/redis-3.2.9/6379/; rm -f $1"
echo $host "节点 redis 6379 删除文件结束."
ssh $host "cd /home/redis-3.2.9/6380/; rm -f $1"
echo $host "节点 redis 6380 删除文件结束."
done
echo "删除 Redis 集群下的指定文件结束."
echo "--------------------------------"
echo "Redis 集群目录信息如下:"
ssh node19 "hostname; cd /home/redis-3.2.9/6379/; pwd; ls -l"
for host in node18 node11 node12 node13
do
ssh $host "hostname; cd /home/redis-3.2.9/6379/; pwd; ls -l"
ssh $host "hostname; cd /home/redis-3.2.9/6380/; pwd; ls -l"
done
执行以下命令,删除 nodes.conf 文件。
命令:sh redis_delfile.sh nodes.conf
[root@node19 sheel]# sh redis_delfile.sh nodes.conf
删除 Redis 集群下的指定文件开始...
--------------------------------
node19 节点 redis 6379 删除文件结束.
--------------------------------
node18 节点 redis 6379 删除文件结束.
node18 节点 redis 6380 删除文件结束.
--------------------------------
node11 节点 redis 6379 删除文件结束.
node11 节点 redis 6380 删除文件结束.
--------------------------------
node12 节点 redis 6379 删除文件结束.
node12 节点 redis 6380 删除文件结束.
--------------------------------
node13 节点 redis 6379 删除文件结束.
node13 节点 redis 6380 删除文件结束.
删除 Redis 集群下的指定文件结束.
--------------------------------
Redis 集群目录信息如下:
node19
/home/redis-3.2.9/6379
total 5668
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 09:18 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 09:18 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 09:18 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 09:18 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 19:24 redis.conf
lrwxrwxrwx. 1 root root 12 Dec 17 09:18 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 2522088 Dec 17 09:18 redis-server
node18
/home/redis-3.2.9/6379
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:03 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:03 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:03 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:03 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:03 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:03 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:03 redis-server
node18
/home/redis-3.2.9/6380
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:03 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:03 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:03 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:03 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:03 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:03 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:03 redis-server
node11
/home/redis-3.2.9/6379
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:04 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:04 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:04 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:04 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-server
node11
/home/redis-3.2.9/6380
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:04 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:04 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:04 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:04 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-server
node12
/home/redis-3.2.9/6379
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:04 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:04 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:04 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:04 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-server
node12
/home/redis-3.2.9/6380
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:04 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:04 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:04 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:04 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-server
node13
/home/redis-3.2.9/6379
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:04 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:04 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:04 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:04 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-server
node13
/home/redis-3.2.9/6380
total 8132
-rw-r--r--. 1 root root 76 Dec 17 21:00 dump.rdb
-rwxr-xr-x. 1 root root 274020 Dec 17 20:04 redis-benchmark
-rwxr-xr-x. 1 root root 22177 Dec 17 20:04 redis-check-aof
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-check-rdb
-rwxr-xr-x. 1 root root 404053 Dec 17 20:04 redis-cli
-rw-r--r--. 1 root root 46732 Dec 17 20:04 redis.conf
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-sentinel
-rwxr-xr-x. 1 root root 2522088 Dec 17 20:04 redis-server
再次执行上面绿色字体的创建集群命令,可以看到集群正常创建成功了。
[root@node19 sheel]# ./redis-trib.rb create --replicas 1 192.168.220.19:6379 node18:6379 node18:6380 node11:6379 node11:6380 node12:6379 node12:6380 node13:6379 node13:6380
>>> Creating cluster
>>> Performing hash slots allocation on 9 nodes...
Using 4 masters:
192.168.220.19:6379
node13:6379
node12:6379
node11:6379
Adding replica node18:6379 to 192.168.220.19:6379
Adding replica node12:6380 to node13:6379
Adding replica node13:6380 to node12:6379
Adding replica node18:6380 to node11:6379
Adding replica node11:6380 to 192.168.220.19:6379
M: 96363758aeb2f94f6ab24e7bb6afc94d6b5e5f01 192.168.220.19:6379
slots:0-4095 (4096 slots) master
S: f8ed93c7fc574a0840b49e3396d117fd86a1ff81 node18:6379
replicates 96363758aeb2f94f6ab24e7bb6afc94d6b5e5f01
S: 9b019d4638f061939f7c572a54823ee24af539a7 node18:6380
replicates 7bc722b94cee8e92081039903f7f43aa9b7b1e41
M: 7bc722b94cee8e92081039903f7f43aa9b7b1e41 node11:6379
slots:12288-16383 (4096 slots) master
S: 5bc91f47fe2ff042f22cce6fc35da67392c12d62 node11:6380
replicates 96363758aeb2f94f6ab24e7bb6afc94d6b5e5f01
M: da5b89b211ba2e50b2e5dee4153c78b8d7a00dd9 node12:6379
slots:8192-12287 (4096 slots) master
S: cc5d7f7fbfce16364755d4dc034a8da7ca67805e node12:6380
replicates 6786c1430e3454dced220f76ed405319cfe0cd23
M: 6786c1430e3454dced220f76ed405319cfe0cd23 node13:6379
slots:4096-8191 (4096 slots) master
S: 6191032f8fe5f9b081ceddaf1a82dcc1f60453de node13:6380
replicates da5b89b211ba2e50b2e5dee4153c78b8d7a00dd9
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.220.19:6379)
M: 96363758aeb2f94f6ab24e7bb6afc94d6b5e5f01 192.168.220.19:6379
slots:0-4095 (4096 slots) master
2 additional replica(s)
S: 9b019d4638f061939f7c572a54823ee24af539a7 192.168.220.18:6380
slots: (0 slots) slave
replicates 7bc722b94cee8e92081039903f7f43aa9b7b1e41
S: cc5d7f7fbfce16364755d4dc034a8da7ca67805e 192.168.220.12:6380
slots: (0 slots) slave
replicates 6786c1430e3454dced220f76ed405319cfe0cd23
M: da5b89b211ba2e50b2e5dee4153c78b8d7a00dd9 192.168.220.12:6379
slots:8192-12287 (4096 slots) master
1 additional replica(s)
M: 7bc722b94cee8e92081039903f7f43aa9b7b1e41 192.168.220.11:6379
slots:12288-16383 (4096 slots) master
1 additional replica(s)
S: f8ed93c7fc574a0840b49e3396d117fd86a1ff81 192.168.220.18:6379
slots: (0 slots) slave
replicates 96363758aeb2f94f6ab24e7bb6afc94d6b5e5f01
M: 6786c1430e3454dced220f76ed405319cfe0cd23 192.168.220.13:6379
slots:4096-8191 (4096 slots) master
1 additional replica(s)
S: 6191032f8fe5f9b081ceddaf1a82dcc1f60453de 192.168.220.13:6380
slots: (0 slots) slave
replicates da5b89b211ba2e50b2e5dee4153c78b8d7a00dd9
S: 5bc91f47fe2ff042f22cce6fc35da67392c12d62 192.168.220.11:6380
slots: (0 slots) slave
replicates 96363758aeb2f94f6ab24e7bb6afc94d6b5e5f01
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
可以看到创建的集群,有 4 个 Master 和 5 个 Slave。
测试集群:
这里随便找个 redis 实例节点,登录客户端测试,这里还是以 node19 为例。
- [root@node19 6379]# ./redis-cli -p 6379 -a 123456 -c
- 127.0.0.1:6379> keys *
- (empty list or set)
- 127.0.0.1:6379> set test_cluster good
- -> Redirected to slot [5056] located at 192.168.220.13:6379
- OK
- 192.168.220.13:6379> get test_cluster
- "good"
- 192.168.220.13:6379> quit
- [root@node19 6379]#
到此,redis 完全分布式的基本安装和配置 OK 了。