Centos7 redis 5.0.5 集群简单搭建

Centos7简单搭建 Redis-5.0.5集群


创建目录 /usr/local
上传或下载 一份 redis-5.0.5.tar.gz
解压

tar -zxvf  redis-5.0.5.tar.gz

安装

 make

创建集群目录 redis-cluster 并新增 7001-7006空文件夹
在这里插入图片描述
将 redis-5.0.5/redis.conf 复制一份到 7001文件夹下

cp -a  /usr/local/redis-5.0.5/redis.conf  /usr/local/redis-cluster/7001

修改7001目录下redis.conf
1.端口

 port 7001

2.默认ip为127.0.0.1,需要改为其他节点机器可访问的ip,否则创建集群时无法访问对应的端口,无法创建集群 远程服务器修改为 0.0.0.0

bind 0.0.0.0

3.外网可以访问

protected-mode no

4.redis后台运行

daemonize yes

5.pidfile文件对应70001

pidfile /var/run/redis_7001.pid

6.开启集群,把注释#去掉

cluster-enabled yes

7.集群的配置,配置文件首次启动自动生成 7001

cluster-config-file nodes_7001.conf

8.请求超时,默认15秒,可自行设置

cluster-node-timeout 15000

9.aof日志开启,有需要就开启,它会每次写操作都记录一条日志

appendonly yes

10.设置密码

masterauth  password123321 

requirepass password123321

OK 保存
将7001/redis.conf 各复制一份到 7002-7006,修改每一份 redis.conf 对应port(上面的第1 5 7 三条)
集群中的节点启动

/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-c/7001/redis.conf
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-c/7002/redis.conf
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-c/7003/redis.conf
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-c/7004/redis.conf
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-c/7005/redis.conf
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-c/7006/redis.conf

出现如下信息
出现以下信息,表示启动成功:

15025:C 05 May 2020 11:08:19.801 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
15025:C 05 May 2020 11:08:19.801 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=15025, just started
15025:C 05 May 2020 11:08:19.801 # Configuration loaded

创建集群

[root@VM_0_6_centos redis-5.0.5]# ./src/redis-cli --cluster create  你的公网ip:7001 你的公网ip:7002 你的公网ip:7003 你的公网ip:7004 你的公网ip:7005 你的公网ip:7006  --cluster-replicas 1 -a password123321

其中 -a password123321 是redis.conf中自己设置的密码

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 你的公网ip:7005 to 你的公网ip:7001
Adding replica 你的公网ip:7006 to 你的公网ip:7002
Adding replica 你的公网ip:7004 to 你的公网ip:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: a9d971afbd8f41bfab67fb85fe26f588892c908a 你的公网ip:7001
   slots:[0-5460] (5461 slots) master
M: 924766cc58cd489c7d506a319e2851680dbd285e 你的公网ip:7002
   slots:[5461-10922] (5462 slots) master
M: a99037a568d4d5aad0b6d6e51fd1e7291ace3dcd 你的公网ip:7003
   slots:[10923-16383] (5461 slots) master
S: c955b64be84d514f3d32a66fe71b2f0097fd36d1 你的公网ip:7004
   replicates a99037a568d4d5aad0b6d6e51fd1e7291ace3dcd
S: 10cfb93b3aaa02e8f58b25f088c90008150facb1 你的公网ip:7005
   replicates a9d971afbd8f41bfab67fb85fe26f588892c908a
S: 07afe74cfb95a89e3fa7a3e9023e24dbf032978b 你的公网ip:7006
   replicates 924766cc58cd489c7d506a319e2851680dbd285e
Can I set the above configuration? (type 'yes' to accept): ***yes***

输入 yes
查看集群状态

[root@VM_0_6_centos redis-5.0.5]# ./src/redis-cli -h 你的公网ip -c -p 7001 -a password123321

输入
cluster nodes
**加粗样式
**
ok
可使用桌面工具连接测试
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值