Redis5.0.4 集群搭建与远程访问开启&踩到的坑

Redis5.0.4 集群搭建与远程访问开启&踩到的坑

背景

阿里云1核学生机服务器
单机6节点配置方式伪造集群

下载安装redis5.0.4

​wget http://download.redis.io/releases/redis-5.0.4.tar.gz
tar xzf redis-5.0.4.tar.gz
cd redis-5.0.4
make

修改配置文件

# 关闭保护模式 用于公网访问
protected-mode no
port 7001
# 开启集群模式
cluster-enabled yes
cluster-config-file nodes-7001.conf
cluster-node-timeout 5000
# 后台启动
daemonize yes
pidfile /var/run/redis_7001.pid
logfile "7001.log"
dir /redis/data
# 此处绑定ip 可以是阿里内网ip 和 本地ip 也可以直接注释掉该项
bind 127.0.0.1  172.17.24.102 阿里内网ip
#用于连接主节点密码
masterauth test1
#设置redis密码 各个节点请保持密码一致
requirepass test1

安装集群

mkdir 7001 
rm redis.conf 7001
cp -r 7001/ 7002/
vim 7002/redis.conf
# 批量替换7001为7002
:g/7001/s//7002/g
:wq

按照以上命令依次创建7001 7002 7003 7004 7005 7006
并修改对应配置
至此集群就安装成功了

启动集群

依次启动6个节点

./src/redis-server config-cluster-test/7001/reids.conf &
./src/redis-server config-cluster-test/7002/reids.conf &
./src/redis-server config-cluster-test/7003/reids.conf &
./src/redis-server config-cluster-test/7004/reids.conf &
./src/redis-server config-cluster-test/7005/reids.conf &
./src/redis-server config-cluster-test/7006/reids.conf &
# 查看启动结果
ps -ef |grep redis

在这里插入图片描述
构建集群

# 我这里使用阿里云内网ip启动 ,-a 密码 
./src/redis-cli --cluster create -a test1 172.17.24.102:7001 172.17.24.102:7002 172.17.24.102:7003 172.17.24.102:7004 172.17.24.102:7005 172.17.24.102:7006  --cluster-replicas 1

启动成功可以看到以下图示,自动将6个节点分配为3主3从 前面3个为主节点,
注意需要输入一次yes
在这里插入图片描述
记得将你需要开发的端口在阿里云防火墙进行添加,这个很关键
在这里插入图片描述

至此集群就算启动成功了,可以使用阿里云的外网进行集群连接
我这里使用的是Redis Desktop Manager 工具
在这里插入图片描述

踩到的坑

  1. [ERR] Node 120.79.36.202:7001 NOAUTH Authentication required
    这个需要添加密码进行集群构建 ,具体命令请参考上面集群构建部分

  2. [ERR] Node 120.79.36.202:7001 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0
    需要清除掉 appendonly-700*.aof nodes-700*.conf rdb 文件
    关闭节点重启

  3. Node 172.17.24.102:7001 replied with error:
    DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command ‘CONFIG SET protected-mode no’ from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to ‘no’, and then restarting the server. 3) If you started the server manually just for testing, restart it with the ‘–protected-mode no’ option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.*

这个问题需要修改配置文件 protected-mode no bind 127.0.0.1 172.17.24.102阿里内网ip
重启节点

  • 还有一个大坑无论怎么修改配置,重启节点都不能解决,可能是配置文件存在缓存,请重启服务器!

小技巧

redis 5.0 以后utils包中存在一个redis-5.0.4/utils/create-cluster/create-cluster 文件

在这里插入图片描述
在port 中添加自己的端口号 改为7000 启动或者关闭时会自动+1 执行 7001 7002 7003 7004 7005 7006
在停止脚本中加入停止密码 可以实现批量停止节点
./create-cluster stop
./create-cluster start

使用此命令连接redis集群进行测试数据
./redis-cli -c -p 7001

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值