redis 主从哨兵集群配置文件(最基本部分)

写在前面,
1、先创建dir、log 相关文件夹!!!!!!!!!!
2、从库需要设置requirepass 密码,否则主从切换会因为密码丢失而失败
3、主从需要配置,以防主库挂掉,哨兵进行从库切换时,外部链接无法感知真实IP
#机器所在的公网IP或局域网IP
replica-announce-ip 192.168.1.30
#机器所在的公网端口或局域网端口
replica-announce-port 6381

主机

bind 0.0.0.0
port 6379
daemonize yes
protected-mode no
dir /home/redis/conf/data/master

logfile "/home/redis/conf/log/redis_master.log"
requirepass 123456
# 加上这个密码是为了防止主库挂了,重启主库后,无法连接新选举的主库
masterauth 123456

#机器所在的公网IP或局域网IP
replica-announce-ip 192.168.1.30
#机器所在的公网端口或局域网端口
replica-announce-port 6379



从机1

bind 0.0.0.0
protected-mode no
port 6380
daemonize yes
logfile "/home/redis/conf/log/redis_slave-1.log"
dir /home/redis/conf/data/redis_slave_1
slaveof 192.168.1.30 6379
requirepass 123456
masterauth 123456

#机器所在的公网IP或局域网IP
replica-announce-ip 192.168.1.30
#机器所在的公网端口或局域网端口
replica-announce-port 6380

从机2

bind 0.0.0.0
protected-mode no
port 6381
daemonize yes
logfile "/home/redis/conf/log/redis_slave-2.log"
dir /home/redis/conf/data/redis_slave_2
slaveof 192.168.1.30 6379
requirepass 123456
masterauth 123456

#机器所在的公网IP或局域网IP
replica-announce-ip 192.168.1.30
#机器所在的公网端口或局域网端口
replica-announce-port 6381

从机3

bind 0.0.0.0
protected-mode no
port 6382
daemonize yes
logfile "/home/redis/conf/log/redis_slave-3.log"
dir /home/redis/conf/data/redis_slave_3
slaveof 192.168.1.30 6379
requirepass 123456
masterauth 123456

#机器所在的公网IP或局域网IP
replica-announce-ip 192.168.1.30
#机器所在的公网端口或局域网端口
replica-announce-port 6382

哨兵1

port 26379
daemonize yes
protected-mode no
sentinel monitor mymaster 192.168.1.30 6379 2
sentinel down-after-milliseconds mymaster 30000
logfile "/home/redis/conf/log/sentinel-1.log"
dir /home/redis/conf/data/sentinel-1
sentinel auth-pass mymaster 123456


# 哨兵所在的公网IP
sentinel announce-ip 192.168.1.30
# 哨兵所在的公网端口
sentinel announce-port 26379

哨兵2

port 26380
daemonize yes
protected-mode no
sentinel monitor mymaster 192.168.1.30 6379 2
sentinel down-after-milliseconds mymaster 30000
logfile "/home/redis/conf/log/sentinel-2.log"
dir /home/redis/conf/data/sentinel-2
sentinel auth-pass mymaster 123456

# 哨兵所在的公网IP
sentinel announce-ip 192.168.1.30
# 哨兵所在的公网端口
sentinel announce-port 26380

哨兵3

port 26381
daemonize yes
protected-mode no
sentinel monitor mymaster 192.168.1.30 6379 2
sentinel down-after-milliseconds mymaster 30000
logfile "/home/redis/conf/log/sentinel-3.log"
dir /home/redis/conf/data/sentinel-3
sentinel auth-pass mymaster 123456

# 哨兵所在的公网IP
sentinel announce-ip 192.168.1.30
# 哨兵所在的公网端口
sentinel announce-port 26381

你可能感兴趣的:(笔记,各式各样的代码,redis)