redis集群 : 三个服务器6个节点
1.下载redis安装包:
http://download.redis.io/releases/redis-3.2.9.tar.gz
2.解压
3.下载redis相关依赖:
yum install cpp binutils glibc-kernheaders glibc-common glibc-devel gcc make tcl -y
4.进入redis 解压目录的src目录
[root@centos1 src]# pwd
/usr/local/src/redis-3.2-rc1/src
5.编译 and 测试
[root@centos1 src]# make && make test
6.安装
[root@centos1 src]# make install PREFIX=/usr/local/redis
7.创建目录
[root@centos1 src]# mkdir -p /usr/local/cluster/6379/
[root@centos1 src]# mkdir -p /usr/local/cluster/6380/
8.拷贝配置文件到目录并修改配置文件内容:
port 6379
pidfile /var/run/6379.pid
logfile "/var/log/redis_6379.log"
daemonize yes
cluster-enabled yes
cluster-config-file nodes_6379.conf
cluster-node-timeout 5000
appendonly yes
其他节点同上
9.启动redis:
[root@centos1 6379]# redis-server redis.conf
10.查看redis进程 并查看监听端口:
[root@centos1 src]# ps -ef | grep redis
root 19282 1 0 May10 ? 00:01:11 redis-server *:6379 [cluster]
root 19297 1 0 May10 ? 00:01:11 redis-server *:6380 [cluster]
[root@centos1 src]# netstat -natp | grep redis | grep LISTEN
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 19282/redis-server
tcp 0 0 0.0.0.0:6380 0.0.0.0:* LISTEN 19297/redis-server
tcp 0 0 0.0.0.0:16379 0.0.0.0:* LISTEN 19282/redis-server
tcp 0 0 0.0.0.0:16380 0.0.0.0:* LISTEN 19297/redis-server
tcp 0 0 :::6379 :::* LISTEN 19282/redis-server
tcp 0 0 :::6380 :::* LISTEN 19297/redis-server
tcp 0 0 :::16379 :::* LISTEN 19282/redis-server
tcp 0 0 :::16380 :::* LISTEN 19297/redis-server
11. 安装cluster依赖:
yum install ruby rubygems -y
12.Redis 官方提供了 redis-trib.rb 这个工具,就在解压目录的 src 目录中,第三步中已将它复制到 /usr/local/bin 目录中,可以直接在命令行中使用了。使用下面这个命令即可完成安装。
执行命令:
[root@centos1 6380]# redis-trib.rb create --replicas 1 192.168.20.165:6379 192.168.20.165:6380 192.168.20.232:6379 192.168.20.232:6380 192.168.20.227:6379 192.168.20.227:6380
如果出现 redis requires Ruby version >= 2.2.2 问题
参考 https://my.oschina.net/LucasZhu/blog/1810514
13.执行成功如下:
[root@centos1 6380]# redis-trib.rb create --replicas 1 192.168.20.165:6379 192.168.20.165:6380 192.168.20.232:6379 192.168.20.232:6380 192.168.20.227:6379 192.168.20.227:6380
/usr/local/bin/redis-trib.rb:1573: warning: key "threshold" is duplicated and overwritten on line 1573
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.20.165:6379
192.168.20.232:6379
192.168.20.227:6379
Adding replica 192.168.20.232:6380 to 192.168.20.165:6379
Adding replica 192.168.20.165:6380 to 192.168.20.232:6379
Adding replica 192.168.20.227:6380 to 192.168.20.227:6379
M: a161882a3929caff01d9b8fcc841185d41d4515a 192.168.20.165:6379
slots:0-5460 (5461 slots) master
S: da6fac6875ff0a62e4b321fa0fd1adc4b6dc6c74 192.168.20.165:6380
replicates 4f0aa979cac27542c3ee39a20f4e4cb48a65c41b
M: 4f0aa979cac27542c3ee39a20f4e4cb48a65c41b 192.168.20.232:6379
slots:5461-10922 (5462 slots) master
S: cf16ec48074df31dacf06c44de12ce8254dafff4 192.168.20.232:6380
replicates a161882a3929caff01d9b8fcc841185d41d4515a
M: 56513b39518077bd5668c3d5c04fad901e91f836 192.168.20.227:6379
slots:10923-16383 (5461 slots) master
S: 5042fdc1a48a7ed0dbf17630b96e659cb7063305 192.168.20.227:6380
replicates 56513b39518077bd5668c3d5c04fad901e91f836
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.20.165:6379)
M: a161882a3929caff01d9b8fcc841185d41d4515a 192.168.20.165:6379
slots:0-5460 (5461 slots) master
M: da6fac6875ff0a62e4b321fa0fd1adc4b6dc6c74 192.168.20.165:6380
slots: (0 slots) master
replicates 4f0aa979cac27542c3ee39a20f4e4cb48a65c41b
M: 4f0aa979cac27542c3ee39a20f4e4cb48a65c41b 192.168.20.232:6379
slots:5461-10922 (5462 slots) master
M: cf16ec48074df31dacf06c44de12ce8254dafff4 192.168.20.232:6380
slots: (0 slots) master
replicates a161882a3929caff01d9b8fcc841185d41d4515a
M: 56513b39518077bd5668c3d5c04fad901e91f836 192.168.20.227:6379
slots:10923-16383 (5461 slots) master
M: 5042fdc1a48a7ed0dbf17630b96e659cb7063305 192.168.20.227:6380
slots: (0 slots) master
replicates 56513b39518077bd5668c3d5c04fad901e91f836
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
参考:
https://blog.csdn.net/naixiyi/article/details/51339374
https://www.linuxidc.com/Linux/2017-06/144948.htm
https://www.linuxidc.com/Linux/2016-09/135122.htm
https://www.cnblogs.com/yuanermen/p/5717885.html
https://blog.csdn.net/u010571316/article/details/79515662
http://code727.iteye.com/blog/2252458
https://www.linuxidc.com/Linux/2015-08/121845.htm