redis5集群安装

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tszxlzc/article/details/86565327

一、准备好三台虚拟机
192.168.152.128
192.168.152.129
192.168.152.130
二、安装
先在192.168.152.128安装redis
创建conf目录

[root@localhost redis-5.0.3]# mkdir -p conf/6379
[root@localhost redis-5.0.3]# mkdir -p conf/6380
#redis配置复制一份到配置目录
[root@localhost redis-5.0.3]# cp redis.conf conf/6379
[root@localhost redis-5.0.3]# cp redis.conf conf/6380
修改6380目录下redis.conf配置文件的的端口号为6380

修改conf/6379/redis.conf为 配置

#bind 127.0.0.1  注释掉
protected-mode no(需要不同服务器的节点连通,这个就要设置为 no)
daemonize yes(设置后台运行redis)
cluster-enabled yes
cluster-node-timeout 5000
appendonly yes
port 6379
pidfile /var/run/redis_6379.pid
cluster-config-file nodes-6379.conf
dbfilename dump_6379.rdb
appendfilename "appendonly_6379.aof"
logfile "/var/log/redis/redis_6379.log"

修改conf/6380/redis.conf为 配置

#bind 127.0.0.1  注释掉
protected-mode no(需要不同服务器的节点连通,这个就要设置为 no)
daemonize yes(设置后台运行redis)
cluster-enabled yes
cluster-node-timeout 5000
appendonly yes
port 6380
pidfile /var/run/redis_6380.pid
cluster-config-file nodes-6380.conf
dbfilename dump_6380.rdb
appendfilename "appendonly_6380.aof"
logfile "/var/log/redis/redis_6380.log"

将安装好的redis复制一份到另外两台机器

scp -r redis-5.0.3 [email protected]:/usr/local
scp -r redis-5.0.3 [email protected]:/usr/local

三、 启动redis
在三台机器上执行下面两条启动命令

root@localhost redis-5.0.3]# /usr/local/redis-5.0.3/src/redis-server /usr/local/redis-5.0.3/conf/6379/redis.conf 
root@localhost redis-5.0.3]# /usr/local/redis-5.0.3/src/redis-server /usr/local/redis-5.0.3/conf/6380/redis.conf 

四、 创建集群

[root@localhost src]# ./redis-cli --cluster create 192.168.152.128:6379 192.168.152.129:6379 192.168.152.130:6379 192.168.152.128:6380 192.168.152.129:6380 192.168.152.130:6380 --cluster-replicas 1
>>> 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.152.129:6380 to 192.168.152.128:6379
Adding replica 192.168.152.128:6380 to 192.168.152.129:6379
Adding replica 192.168.152.130:6380 to 192.168.152.130:6379
>>> Trying to optimize slaves allocation for anti-affinity
[OK] Perfect anti-affinity obtained!
M: fe789bebd8acaa868127c687716620ab109bec6b 192.168.152.128:6379
   slots:[0-5460] (5461 slots) master
M: 61bab2f86b9c145fe4fd6284679f3534837de12d 192.168.152.129:6379
   slots:[5461-10922] (5462 slots) master
M: 4fc3cf03607f57a821981f81a65bf506809feb9b 192.168.152.130:6379
   slots:[10923-16383] (5461 slots) master
S: 364b70e6e5ee83ad909c46de06f676fe1d359794 192.168.152.128:6380
   replicates 61bab2f86b9c145fe4fd6284679f3534837de12d
S: a8bf460bb67b73e05500ba0c4fb8bbbbbe4744ec 192.168.152.129:6380
   replicates 4fc3cf03607f57a821981f81a65bf506809feb9b
S: 6e3a1afd28cb1df99468d044b6d880ffee1dd43e 192.168.152.130:6380
   replicates fe789bebd8acaa868127c687716620ab109bec6b
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.152.128:6379)
M: fe789bebd8acaa868127c687716620ab109bec6b 192.168.152.128:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 61bab2f86b9c145fe4fd6284679f3534837de12d 192.168.152.129:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: a8bf460bb67b73e05500ba0c4fb8bbbbbe4744ec 192.168.152.129:6380
   slots: (0 slots) slave
   replicates 4fc3cf03607f57a821981f81a65bf506809feb9b
S: 364b70e6e5ee83ad909c46de06f676fe1d359794 192.168.152.128:6380
   slots: (0 slots) slave
   replicates 61bab2f86b9c145fe4fd6284679f3534837de12d
S: 6e3a1afd28cb1df99468d044b6d880ffee1dd43e 192.168.152.130:6380
   slots: (0 slots) slave
   replicates fe789bebd8acaa868127c687716620ab109bec6b
M: 4fc3cf03607f57a821981f81a65bf506809feb9b 192.168.152.130:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.


猜你喜欢

转载自blog.csdn.net/tszxlzc/article/details/86565327