案例: centos7 安装redis集群 版本5.0.7

Posted 袁义锐

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了案例: centos7 安装redis集群 版本5.0.7相关的知识,希望对你有一定的参考价值。

请阅读后,再实施;

本文重在讲解; 安装时 ,第3和第4步之间可以加入自己的思路,优化流程

 

1. 单节点安装

       1.1 请在redis官网下载,我选用的是redis-5.0.7;

       1.2 将redis-5.0.7.tar.gz 上传到centos服务器,并解压(我是放在/data目录下)

 

2.  执行如下命令行,进入redis目录,

cd /data/redis-5.0.7

  2.1  make编译:编译完成后,在redis-5.0.7目录会下多一个src目录;

make

如果报错需要gcc ,请执行:yum install gcc

 2.2 进入src目录,启动redis:

./redis-server ../redis.conf

 

3.在/data目录创建redis-cluster文件夹,在redis-cluster文件夹中创建为redis01-master等六个文件加;

[root@SHB-L0120794 redis-cluster]# pwd
/data/redis-cluster
[root@SHB-L0120794 redis-cluster]# ll
total 24
drwxr-xr-x 3 root root 4096 Mar  5 13:56 redis01-master
drwxr-xr-x 3 root root 4096 Mar  5 13:56 redis01-slave
drwxr-xr-x 3 root root 4096 Mar  5 13:56 redis02-master
drwxr-xr-x 3 root root 4096 Mar  5 13:56 redis02-slave
drwxr-xr-x 3 root root 4096 Mar  5 13:56 redis03-master
drwxr-xr-x 3 root root 4096 Mar  5 13:56 redis03-slave

复制redis文件夹到6个目录 ;

cp -r /data/redis5.0.7 /data/redis-cluster/redis01-master

 

4.修改6个文件下redis5.0.7目录下的redis.conf文件中的内容后启动服务

a. port 7001
b. cluster-config-file nodes-7001.conf (和以上端口一一对应)

c. protected-mode no (关闭保护模式)

d. #bind 127.0.0.1 (防止集群启动失败)

e. cluster-enabled yes (开启集群)

f. appendonly yes

g. requirepass redispass  (设置redis访问密码)
h. masterauth redispass (和访问密码一致)

5.启动集群:

./redis-cli -a redispass --cluster create --cluster-replicas 1 30.4.211.1:7001 30.4.211.1:7002 30.4.211.1:7003 30.4.211.1:7004 30.4.211.1:7005 30.4.211.1:7006

日志信息:证明可用了

[root@SHB-L0120794 src]# ./redis-cli -a redis123 --cluster create --cluster-replicas 1 30.4.211.1:7001 30.4.211.1:7002 30.4.211.1:7003 30.4.211.1:7004 30.4.211.1:7005 30.4.211.1:7006
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 30.4.211.1:7005 to 30.4.211.1:7001
Adding replica 30.4.211.1:7006 to 30.4.211.1:7002
Adding replica 30.4.211.1:7004 to 30.4.211.1:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: d33a0f527cac32594ecc3ca1c2c2bd29b8bf5d87 30.4.211.1:7001
   slots:[0-5460] (5461 slots) master
M: fe9ba8cae45047d28ec0b6addc016d42b5cf11cb 30.4.211.1:7002
   slots:[5461-10922] (5462 slots) master
M: 5596104f40f818f2fba311824201d83a8c1de105 30.4.211.1:7003
   slots:[10923-16383] (5461 slots) master
S: a479f4cc4fce79fef162e0bb529ac9c5d5ed74e5 30.4.211.1:7004
   replicates 5596104f40f818f2fba311824201d83a8c1de105
S: 16bf7c40b7aab7f39ab537001ec7e4d3e3f48807 30.4.211.1:7005
   replicates d33a0f527cac32594ecc3ca1c2c2bd29b8bf5d87
S: 1ffe9e60959a7949930f6d65e0db0b55129bb8fd 30.4.211.1:7006
   replicates fe9ba8cae45047d28ec0b6addc016d42b5cf11cb
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 30.4.211.1:7001)
M: d33a0f527cac32594ecc3ca1c2c2bd29b8bf5d87 30.4.211.1:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: fe9ba8cae45047d28ec0b6addc016d42b5cf11cb 30.4.211.1:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: 5596104f40f818f2fba311824201d83a8c1de105 30.4.211.1:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: a479f4cc4fce79fef162e0bb529ac9c5d5ed74e5 30.4.211.1:7004
   slots: (0 slots) slave
   replicates 5596104f40f818f2fba311824201d83a8c1de105
S: 16bf7c40b7aab7f39ab537001ec7e4d3e3f48807 30.4.211.1:7005
   slots: (0 slots) slave
   replicates d33a0f527cac32594ecc3ca1c2c2bd29b8bf5d87
S: 1ffe9e60959a7949930f6d65e0db0b55129bb8fd 30.4.211.1:7006
   slots: (0 slots) slave
   replicates fe9ba8cae45047d28ec0b6addc016d42b5cf11cb
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

 

 

 

 

 

 

以上是关于案例: centos7 安装redis集群 版本5.0.7的主要内容,如果未能解决你的问题,请参考以下文章

Redis集群

Redis v6.0.6 集群cluster模式布署

Redis集群搭建

redis集群搭建

centos7案例实战——redis一主二从三哨兵高可用服务搭建

Redis集群搭建与简单使用