记录下树莓派局域网单机部署Redis集群,用于日常工作测试环境,6台机器.3主3从.
官网地址:https://redis.io/download/
wget https://download.redis.io/releases/redis-5.0.9.tar.gztar -zxvf redis-5.0.9.tar.gzcd redis-5.0.9
#单机集群,为了方便管理配置,我们复制以端口号管理文件 6374-6379cp redis.conf redis6379.confvi redis6379.conf#注释允许局域网访问#bind 127.0.0.1#打开protected-mode no#修改portport 6379#修改端口pidfile /var/run/redis_6379.pidcluster-config-file nodes-6379.conf#设置密码requirepass 123456#打开集群cluster-enabled yes
修改好后分别复制五份为6374-6379
nohup /home/pi/application/redis/redis-5.0.9/src/redis-server /home/pi/application/redis/redis-5.0.9/redis6377.conf >redis.log 2>&1 &nohup /home/pi/application/redis/redis-5.0.9/src/redis-server /home/pi/application/redis/redis-5.0.9/redis6378.conf >redis.log 2>&1 &nohup /home/pi/application/redis/redis-5.0.9/src/redis-server /home/pi/application/redis/redis-5.0.9/redis6379.conf >redis.log 2>&1 &nohup /home/pi/application/redis/redis-5.0.9/src/redis-server /home/pi/application/redis/redis-5.0.9/redis6375.conf >redis.log 2>&1 &nohup /home/pi/application/redis/redis-5.0.9/src/redis-server /home/pi/application/redis/redis-5.0.9/redis6376.conf >redis.log 2>&1 &nohup /home/pi/application/redis/redis-5.0.9/src/redis-server /home/pi/application/redis/redis-5.0.9/redis6374.conf >redis.log 2>&1 &
#如需重新创建集群要删除当前脚本目录下所有nodes-config文件cd /home/pi/application/redis/redis-5.0.9./redis-cli --cluster create 192.168.1.48:6377 192.168.1.48:6378 192.168.1.48:6379 192.168.1.48:6375 192.168.1.48:6376 192.168.1.48:6374 --cluster-replicas$
注意这里请使用本机ip,请勿使用127.0.0.1.否则客户端连接时将其他机器与127.0.0.1方式连接导致失败.
使用redis-cli登录某一节点,以-c(集群模式)访问。
./redis-cli -h 192.168.1.48 -p 6379 -ccluster nodes
注意,redis-cli在src目录下.
如果提示NOAUTH Authentication required.,输入auth 密码,显示ok后再次输入即可
以上命令建议保存为sh脚本方便后续使用
如果局域网访问不了,请检查防火墙端口
sudo ufw status
开放端口
sudo ufw allow 6379 #6374-6379
https://blog.csdn.net/weixin_44565095/article/details/100581393