| 主机 | ip |
|---|---|
| master | 192.168.2.50 |
| slave1 | 192.168.2.51 |
| slave2 | 192.168.2.52 |
[root@bigdata-node05 redis-4.0.9]vim /opt/redis-4.0.9/redis.conf
# 注释监听地址
#bind 127.0.0.1
#开启守护进程 开启这个会在后台启动redis-server
daemonize yes
#修改日志文件目录
logfile /opt/redis-4.0.9/log/redis.log
#修改工作目录
dir /opt/redis-4.0.9
#开启AOF持久化功能 要开启持久化才能实现主从复制
appendonly yes
slave1
[root@bigdata-node05 redis-4.0.9]vim /opt/redis-4.0.9/redis.conf # 注释监听地址 #bind 127.0.0.1 #开启守护进程 开启这个会在后台启动redis-server daemonize yes #修改日志文件目录 logfile /opt/redis-4.0.9/log/redis.log #开启AOF持久化功能 要开启持久化才能实现主从复制 appendonly yes # 修改IP和端口 指向master slaveof 192.168.2.50 6379slave2
[root@bigdata-node05 redis-4.0.9]vim /opt/redis-4.0.9/redis.conf # 注释监听地址 #bind 127.0.0.1 #开启守护进程 开启这个会在后台启动redis-server daemonize yes #修改日志文件目录 logfile /opt/redis-4.0.9/log/redis.log #开启AOF持久化功能 要开启持久化才能实现主从复制 appendonly yes # 修改IP和端口 指向master slaveof 192.168.2.50 6379重启Redis
redis-server redis.conf二、Redis哨兵模式 1、修改配置文件(所有redis-sentinel配置统一修改)
[root@bigdata-node05 redis-4.0.9]# vi /opt/redis-4.0.9/sentinel.conf protected-mode no #关闭保护模式 daemonize yes #指定sentinel为后台启动 logfile "/opt/redis-4.0.9/log/sentinel.log" #指定日志存放路径 sentinel monitor mymaster 192.168.2.50 6379 2 #至少几个哨兵检测到主服务器故障了,才会进行故障迁移,全部指向masterIP sentinel auth-pass mymaster 123456 #设置主redis密码(auth-pass 要放在monitor配置后面,不然会报错) sentinel down-after-milliseconds mymaster 30000 #判定服务器down掉的时间周期,默认30000毫秒(30秒) sentinel failover-timeout mymaster 180000 #故障节的的最大超时时间为180000(180秒)2、开启哨兵模式
- 先开启master,在开启slave
redis-sentinel /opt/redis-4.0.9/sentinel.conf --Sentinel3、查看哨兵信息
[root@localhost opt]# redis-cli -h 192.168.2.50 -p 26379 info Sentinel
address:主redis ip;slaves:有多少个从库;sentinels:有多少个哨兵
[root@localhost opt]# tail -f /opt/redis-4.0.9/log/sentinel.log



