redis|Linux搭建多机Redis集群

三主三从

192.168.200.140:6379 192.168.200.170 :6310
192.168.200.150:6379 192.168.200.170 :6310
192.168.200.170:6379 192.168.200.170 :6310


二、修改主文件配置redis.conf一、首先自行安装搭建redis环境
# bind 127.0.0.1 -::1#注释掉指定访问的IP 修改为 bind 0.0.0.0 bind 0.0.0.0#表示任何机器都可以访问 protected-mode no#关闭本机保护(不需配置了bind ip) daemonize yes #开启守护进程(后台启动) appendonly yes#aof持久化 cluster-enabled yes#开启集群 cluster-config-file nodes-6379.conf#配置文件 cluster-node-timeout 15000#集群超时时间

三、创建从文件配置redis6380.conf(mkdir redis6380.conf )
include /usr/myredis/redis.conf#引入redis.conf文件 pidfile /var/run/redis_6380.pid#启动pid port 6380#端口号 dbfilename dump6380.rdb#rdb持久化保存文件名 cluster-enabled yes#开启集群 cluster-config-file nodes-6380.conf#配置文件 cluster-node-timeout 15000#集群超时时间

【redis|Linux搭建多机Redis集群】四、启动redis服务
redis-server redis.conf redis-server redis6379.conf

注:同上启动剩下两台服务器
五、启动集群
cd /usr/software/redis-6.2.1/src
redis-cli --cluster create --cluster-replicas 1 192.168.200.150:6379 192.168.200.150:6310 192.168.200.140:6379 192.168.200.140:6310 192.168.200.170:6379 192.168.200.170:6310

六、普通方式登录测试
1. redis-cli -c-p 6379#-c 采用集群策略连接,设置数据会自动切换到相应的写主机 2. cluster nodes#通过 cluster nodes 命令查看集群信息

测试成功redis|Linux搭建多机Redis集群
文章图片


    推荐阅读