标签:同步 user blog second fork sys systemctl ystemd load
Redis哨兵机制,一主二从
教程步骤:https://www.cnblogs.com/zwcry/p/9046207.html
cd /usr/local/redis-ms/
mkdir -p ./sentinel/26001/tmp
cp /usr/local/redis/sentinel.conf ./sentinel/26001/
cd /usr/local/redis-ms/sentinel/
vim ./26001/sentinel.conf
#修改如下键值对
# bind 127.0.0.1 192.168.1.1#注释掉或者值为0.0.0.0
protected-mode no#关闭保护模式
port 26001#端口号
daemonize yes#后台运行
dir /usr/local/redis-ms/sentinel/26001/tmp#解除挂载信息目录
sentinel monitor mymaster 192.168.194.131 6381 1#设置 主名称 ip地址 端口号 参入选举的哨兵数
sentinel down-after-milliseconds mymaster 3000#sentinel心跳检测主3秒内无响应,视为挂掉,开始切换其他从为主
sentinel parallel-syncs mymaster 1#每次最多可以有1个从同步主。一个从同步结束,另一个从开始同步。
sentinel failover-timeout mymaster 18000#主从切换超时时间
1.先启主从redis
/usr/local/redis/src/redis-server /usr/local/redis-ms/6381/redis.conf
/usr/local/redis/src/redis-server /usr/local/redis-ms/6382/redis.conf
/usr/local/redis/src/redis-server /usr/local/redis-ms/6383/redis.conf
ps -ef|grep redis
如图已经启动
且信息正确
/usr/local/redis/src/redis-cli -p 6381
info
/usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26001/sentinel.conf
ps -ef|grep redis
如图已经启动
且信息正确
/usr/local/redis/src/redis-cli -p 26001
info
/usr/local/redis/src/redis-cli -p 6381 shutdown
/usr/local/redis/src/redis-cli -p 26001
info
/usr/local/redis/src/redis-server /usr/local/redis-ms/6381/redis.conf
/usr/local/redis/src/redis-cli -p 6381
info
cd /usr/local/redis-ms/sentinel/
cp -r 26001 26002
vim 26002/sentinel.conf
#将文本中26001替换为26002
:%s/26001/26002/g
/usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26002/sentinel.conf
info
/usr/local/redis/src/redis-cli -p 26002
注:redis开机启动参照https://www.cnblogs.com/zwcry/p/9046207.html
mkdir /usr/local/redis-ms/sentinel/script
cd /usr/local/redis-ms/sentinel/script/
vim start.sh
#!/bin/sh /usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26001/sentinel.conf /usr/local/redis/src/redis-sentinel /usr/local/redis-ms/sentinel/26002/sentinel.conf
vim stop.sh
#!/bin/sh /usr/local/redis/src/redis-cli -p 26001 shutdown /usr/local/redis/src/redis-cli -p 26002 shutdown
vim restart.sh
#!/bin/sh systemctl stop redis-sentinel systemctl start redis-sentinel
cd /usr/lib/systemd/system/
vim redis-sentinel.service
[Unit] Description=redis-sentinel After=redis-ms.service [Service] Type=forking ExecStart=/usr/local/redis-ms/sentinel/script/start.sh ExecStop=/usr/local/redis-ms/sentinel/script/stop.sh ExecReload=/usr/local/redis-ms/sentinel/script/restart.sh [Install] WantedBy=multi-user.target
#建议启动redis服务后,再启动哨兵
改变权限
chmod 777 redis-sentinel.service
chmod 777 /usr/local/redis-ms/sentinel/script/*
进程服务重加载
systemctl daemon-reload
开机启动哨兵
systemctl enable redis-sentinel.service
启动哨兵
systemctl start redis-sentinel.service
关闭哨兵
systemctl stop redis-sentinel.service
重启哨兵
systemctl restart redis-sentinel.service
备注:哨兵集群服务自主关联响应,如果需要更多哨兵集群,按照26002的方式复制26003...26006即可
标签:同步 user blog second fork sys systemctl ystemd load
原文地址:https://www.cnblogs.com/ExMan/p/11122269.html