redis 5.0.4集群搭建
step0 简介
redis 集群搭建指南
模式: 三主三从
redis 版本: redis 5.0.4
5.0版本后不需要ruby支持,其底层改由C实现
主从配置、leader选举由redis自己实现
操作系统: centos 7.x
192.168.1.240:6379 192.168.1.240:6380
192.168.1.241:6379 192.168.1.241:6380
192.168.1.242:6379 192.168.1.242:6380
Step1 环境安装
环境需要:
安装 gcc 、tcl(8.5版本以上),可以 yum安装
Step2 编译安装
解压到 /user/local
编译: make MALLOC=libc
安装: make install
Step3 修改配置文件
修改配置文件(每个实列)
1)daemonize yes //后台启动哟
2)port 6379(分别对每个机器的端口号进行设置)
3)dir /usr/local/redis-data/6379/(指定数据文件存放位置,必须要指定不同的目录位置,不然会丢失数据)
4)cluster-enabled yes(启动集群模式)
5)cluster-config-file nodes-6379.conf(集群节点信息文件,这里63xx最好和port对应上)
6)cluster-node-timeout 5000
#bind 127.0.0.1(去掉bind绑定访问ip信息)
protected-mode no (关闭保护模式)
9)appendonly yes
Step4 启动实例
启动每个机器上的redis实例
/usr/local/redis-5.0.4/src/redis-server /etc/redis-cluster/6379/redis-6379.conf
/usr/local/redis-5.0.4/src/redis-server /etc/redis-cluster/6380/redis-6380.conf
Step5 配置集群
/usr/local/redis-5.0.4/src/redis-cli --cluster create --cluster-replicas 1 192.168.1.240:6379 192.168.1.240:6380 192.168.1.241:6379 192.168.1.241:6380 192.168.1.242:6379 192.168.1.242:6380
集群配置日志信息如下:
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.1.241:6380 to 192.168.1.240:6379
Adding replica 192.168.1.242:6380 to 192.168.1.241:6379
Adding replica 192.168.1.240:6380 to 192.168.1.242:6379
M: f4d763efc7877aeb18c91a167b88990e1cc706dc 192.168.1.240:6379
slots:[0-5460] (5461 slots) master
S: db6d582b92fb702a2a1ce9a6aa7195098b644fb1 192.168.1.240:6380
replicates 83f67e85589b5e9f7b5f0a43f611b5e96a004773
M: 0ce04b5892a77e8f37a6d6f742aa27063f723b3b 192.168.1.241:6379
slots:[5461-10922] (5462 slots) master
S: 69b7cc12e3ca97defbeb48bbf4ecf0d0c3010e09 192.168.1.241:6380
replicates f4d763efc7877aeb18c91a167b88990e1cc706dc
M: 83f67e85589b5e9f7b5f0a43f611b5e96a004773 192.168.1.242:6379
slots:[10923-16383] (5461 slots) master
S: 0659876c92846182a617c914cb6fa1668e722ad0 192.168.1.242:6380
replicates 0ce04b5892a77e8f37a6d6f742aa27063f723b3b
Can I set the above configuration? (type 'yes' to accept): yes (这里需要选择 yes,是yes 不是 'y')
>>> 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.1.240:6379)
M: f4d763efc7877aeb18c91a167b88990e1cc706dc 192.168.1.240:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: db6d582b92fb702a2a1ce9a6aa7195098b644fb1 192.168.1.240:6380
slots: (0 slots) slave
replicates 83f67e85589b5e9f7b5f0a43f611b5e96a004773
S: 0659876c92846182a617c914cb6fa1668e722ad0 192.168.1.242:6380
slots: (0 slots) slave
replicates 0ce04b5892a77e8f37a6d6f742aa27063f723b3b
M: 0ce04b5892a77e8f37a6d6f742aa27063f723b3b 192.168.1.241:6379
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
M: 83f67e85589b5e9f7b5f0a43f611b5e96a004773 192.168.1.242:6379
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 69b7cc12e3ca97defbeb48bbf4ecf0d0c3010e09 192.168.1.241:6380
slots: (0 slots) slave
replicates f4d763efc7877aeb18c91a167b88990e1cc706dc
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
##收工