Redis
Redis故障诊断
慢日志查询
安装、启动与连接
常用命令
常用命令2
主从
高可用(SENTINEL)
持久化(RDB、AOF)
集群(CLUSTER)
集群扩容与收缩
管理Redis
备份与恢复
内存使用情况
客户端
数据迁移
Redis配置
Python使用redis
Redis监控指标
本文档使用MrDoc发布
返回首页
-
+
高可用(SENTINEL)
2020年4月17日 09:56
admin
#安装redis主从 # [Redis主从安装](http://baodoc.frp.bao-server.club:22080/project/13/221/ "Redis主从安装") --- ##哨兵一(10.129.136.132) mkdir -p /opt/d9cloud/communication; cp -f /opt/cpaas_install_k8s/no_auto_packages/redis-sentinel.tar.gz /opt/d9cloud/communication; cd /opt/d9cloud/communication; tar -zxvf /opt/d9cloud/communication/redis-sentinel.tar.gz; rm -f /opt/d9cloud/communication/redis-sentinel.tar.gz; ####修改配置: vim /opt/d9cloud/communication/redis-sentinel/conf/sentinel.conf sentinel monitor voice-redis 10.196.8.34 6379 2 修改为 sentinel monitor voice-redis 10.129.136.135 6379 2 添加:(如果实例开启了密码)(一定要加到上面那句的后面) sentinel auth-pass voice-redis <密码> ![](/media//202306/2023-06-02121225747308.png) 添加:(从实例ip 端口) sentinel known-replica voice-redis 10.129.136.136 6379 添加: sentinel myid 231b8e8bde4dd5ee4a21e5b9ee35c71aae535132 #(10.129.136.132) 然后添加另外两台对应信息 sentinel known-sentinel voice-redis 10.129.136.133 26379 331b8e8bde4dd5ee4a21e5b9ee35c71aae535133 sentinel known-sentinel voice-redis 10.129.136.134 26379 431b8e8bde4dd5ee4a21e5b9ee35c71aae535134 --- 启动: cd /opt/d9cloud/communication/redis-sentinel/ sh start.sh --- ##哨兵二(10.129.136.133) mkdir -p /opt/d9cloud/communication; cp -f /opt/cpaas_install_k8s/no_auto_packages/redis-sentinel.tar.gz /opt/d9cloud/communication; cd /opt/d9cloud/communication; tar -zxvf /opt/d9cloud/communication/redis-sentinel.tar.gz; rm -f /opt/d9cloud/communication/redis-sentinel.tar.gz; ####修改配置: vim /opt/d9cloud/communication/redis-sentinel/conf/sentinel.conf sentinel monitor voice-redis 10.196.8.34 6379 2 修改为 sentinel monitor voice-redis 10.129.136.135 6379 2 添加 sentinel known-replica voice-redis 10.129.136.136 6379 添加:(如果实例开启了密码)(一定要加到上面那句的后面) sentinel auth-pass voice-redis <密码> ![](/media//202306/2023-06-02121225747308.png) 添加 sentinel myid 331b8e8bde4dd5ee4a21e5b9ee35c71aae535133 #(10.129.136.133) 然后添加另外两台对应信息 sentinel known-sentinel voice-redis 10.129.136.132 26379 231b8e8bde4dd5ee4a21e5b9ee35c71aae535132 sentinel known-sentinel voice-redis 10.129.136.134 26379 431b8e8bde4dd5ee4a21e5b9ee35c71aae535134 --- 启动: cd /opt/d9cloud/communication/redis-sentinel/ sh start.sh --- ####哨兵三(10.129.136.134) mkdir -p /opt/d9cloud/communication; cp -f /opt/cpaas_install_k8s/no_auto_packages/redis-sentinel.tar.gz /opt/d9cloud/communication; cd /opt/d9cloud/communication; tar -zxvf /opt/d9cloud/communication/redis-sentinel.tar.gz; rm -f /opt/d9cloud/communication/redis-sentinel.tar.gz; ####修改配置: vim /opt/d9cloud/communication/redis-sentinel/conf/sentinel.conf sentinel monitor voice-redis 10.196.8.34 6379 2 修改为 sentinel monitor voice-redis 10.129.136.135 6379 2 添加 sentinel known-replica voice-redis 10.129.136.136 6379 添加:(如果实例开启了密码)(一定要加到上面那句的后面) sentinel auth-pass voice-redis <密码> ![](/media//202306/2023-06-02121225747308.png) 添加 sentinel myid 431b8e8bde4dd5ee4a21e5b9ee35c71aae535134 #(10.129.136.134) 然后添加另外两台对应信息 sentinel known-sentinel voice-redis 10.129.136.132 26379 231b8e8bde4dd5ee4a21e5b9ee35c71aae535132 sentinel known-sentinel voice-redis 10.129.136.133 26379 331b8e8bde4dd5ee4a21e5b9ee35c71aae535133 --- 启动: cd /opt/d9cloud/communication/redis-sentinel/ sh start.sh --- ##sentinel验证步骤 ####看主从状态是否正常 redis-cli -h 10.129.136.132 -p 26379 sentinel masters ![](/media//202306/2023-06-02121522289344.png) sentinel slaves voice-redis ![](/media//202306/2023-06-02121603544973.png) ####手动迁移,看redis的主从信息是否有变更及是否正常 sentinel failover voice-redis --- #单机 ##配置文件 >####修改服务器配置文件 vim /etc/redis.conf >![](/media//202004/2020-04-17093029866994.png) >####复制配置文件sentinel.conf 到etc 文件夹下 cp sentinel.conf /etc/ #进入etc,找到sentinel.conf 并修改 daemonize no 为 daemonize yes ,这样就可以默认启动就后台运行 >####修改配置文件 vim /etc/sentinel.conf daemonize yes #后台运行 logfile "redis-sentinel.log" #日志文件 dir /tmp #文件路径 sentinel monitor mymaster 主实例IP 主实例端口 2 #主实例监控。2代表,当集群中有2个sentinel认为master死了时,才能真正认为该master已经不可用了。 sentinel down-after-milliseconds mymaster 30000 #超过30s不通,将视为下线。 sentinel parallel-syncs mymaster 1 #表示有几个从实例可以同时从新的主实例进行数据同步 ##启动sentinel #方式一 redis-sentinel /etc/sentinel.conf #方式二 redis-server /etc/sentinel.conf --sentinel ##测试sentinel > ####连接sentinel redis-cli -h 192.168.31.88 -p 26379 > ####手动触发迁移 192.168.31.88:26379> sentinel failover mymaster > ####查看复制状态 redis> info replication >![](/media//202004/2020-04-17102817668114.png) ##管理sentinel > ####连接sentinel redis-cli -h 192.168.31.88 -p 26379 > ####获取当前主实例信息 192.168.31.88:26379> sentinel get-master-addr-by-name <master-name> > ####获取所有被监控主实例信息 192.168.31.88:26379> sentinel masters > ####获取一个被监控主实例的所有从实例信息 192.168.31.88:26379> sentinel slaves <master-name> > ####更新哨兵配置 192.168.31.88:26379> sentinel set <master-name> <参数> --- > ####SENTINEL事件发生时执行脚本(重要) 192.168.31.88:26379> sentinel set <master-name> notification-script <master-name> <脚本> --- > ####SENTINEL故障迁移发生时执行脚本(重要) 192.168.31.88:26379> sentinel set <master-name> client-reconfig-script <master-name> <脚本> >####注意:开启上两种功能,要把sentinel配置文件中的对应配置开启,默认为注释状态
分享到: