恢弘志士之气,不宜妄自菲薄。这篇文章主要讲述Redis哨兵(Sentinel)集群部署相关的知识,希望能为你提供帮助。
三台主机系统:
[root@master ~]# cat /etc/redhat-releaseCentOS Linux release 7.8.2003 (Core)
redis版本:
redis-4.0.14
部署redis 1主2从: 主库master的redis.conf配置文件如下:
[root@host-172-17-80-204 bin]# cat ../etc/redis.conf | grep -v \'^$\' | grep -v \'^#\'bind 172.17.80.204 127.0.0.1protected-mode yesport 6379daemonize yeslogfile "/usr/local/redis/redis.log"dir /usr/local/redisslave-serve-stale-data yesslave-read-only no#masterauth "redhat6.3"#主库不需要配置requirepass "redhat6.3"appendonly yesappendfilename "appendonly.aof"
从库node1的redis.conf配置文件如下:
[root@host-172-17-80-60 redis]# cat etc/redis.conf| grep -v \'^$\' | grep -v \'^#\'bind 172.17.80.60 127.0.0.1protected-mode yesport 6379daemonize yeslogfile "/usr/local/redis/redis.log"dir /usr/local/redisslaveof172.17.80.204 6379slave-serve-stale-data yesslave-read-only nomasterauth "redhat6.3"requirepass "redhat6.3"#此密码可以单独配置appendonly yesappendfilename "appendonly.aof"
从库node2的redis.conf配置文件如下:
[root@host-172-17-80-109 redis]# cat etc/redis.conf| grep -v \'^$\' | grep -v \'^#\'bind 172.17.80.109 127.0.0.1protected-mode yesport 6379daemonize yeslogfile "/usr/local/redis/redis.log"dir /usr/local/redisslaveof172.17.80.204 6379slave-serve-stale-data yesslave-read-only nomasterauth "redhat6.3"requirepass "redhat6.3"#此密码可以单独配置appendonly yesappendfilename "appendonly.aof"
登录master主库,查看主从的配置信息:
文章图片
部署redis 哨兵集群:依次将三台机器解压的redis包的sentinel.conf配置文件复制到reids的etc目录下:
cp redis-4.0.14/sentinel.conf /usr/local/redis/etc/
Master主上sentinel文件的配置:
[root@master etc]# cat sentinel.conf | grep -v \'^$\' | grep -v \'^#\'
bind 172.17.80.204 127.0.0.1
port 26379
daemonize yes
dir /usr/local/redis
#主节点别名为mymaster,后面是ip和端口,2代表判断主节点失败至少需要2个sentinel节点同意
sentinel monitor master 172.17.80.204 6379 2
sentinel auth-pass master "redhat6.3"
#主节点故障30秒后启用新的主节点
sentinel down-after-milliseconds master 30000#故障转移时最多可以有1个从节点同时对主节点进行数据同步,数字越大,用时越短,存在网络和IO开销
sentinel parallel-syncs master 1
sentinel failover-timeout master 180000
sentinel deny-scripts-reconfig yes
node1上的sentinel文件的配置:
[root@node01 etc]# cat sentinel.conf | grep -v \'^$\' | grep -v \'^#\'bind 172.17.80.60 127.0.0.1port 26380daemonize yesdir /usr/local/redissentinel monitor master 172.17.80.204 6379 2sentinel auth-pass master "redhat6.3"sentinel down-after-milliseconds master 30000sentinel parallel-syncs master 1sentinel failover-timeout master 180000sentinel deny-scripts-reconfig yes
node2上的sentinel文件的配置:
[root@host-172-17-80-109 etc]# cat sentinel.conf | grep -v \'^#\' | grep -v \'^$\'bind 172.17.80.109 127.0.0.1port 26381daemonize yesdir /usr/local/redissentinel monitor master 172.17.80.109 6379 2sentinel auth-pass master "redhat6.3"sentinel down-after-milliseconds master 30000sentinel parallel-syncs master 1sentinel failover-timeout master 180000sentinel deny-scripts-reconfig yes
登录master的哨兵查看sentinel配置信息:
[root@master etc]# redis-cli -p 26379127.0.0.1:26379>
info sentinel# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=master,status=ok,address=172.17.80.204:6379,slaves=2,sentinels=3127.0.0.1:26379>
文章图片
登录node1的哨兵查看sentinel配置信息:
[root@node01 ~]# redis-cli -p 26380127.0.0.1:26380>
info sentinel# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=master,status=ok,address=172.17.80.204:6379,slaves=2,sentinels=3
文章图片
登录node2的哨兵查看sentinel配置信息:
[root@host-172-17-80-109 ~]# redis-cli -p 26381127.0.0.1:26381>
info sentinel# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=master,status=ok,address=172.17.80.204:6379,slaves=2,sentinels=3
文章图片
哨兵模式启动成功后,master的sentinel.conf配置文件发生变化:
文章图片
哨兵模式启动成功后,node1的sentinel.conf配置文件发生变化:
文章图片
哨兵模式启动成功后,node2的sentinel.conf配置文件发生变化:
文章图片
测试哨兵模式:kill redis master节点,其他从节点变化: 主节点执行kill redis进程:
文章图片
登录node1节点查看sentinel哨兵选举变化:
[root@node01 redis]# redis-cli -p 26380127.0.0.1:26380>
info sentinel# Sentinelsentinel_masters:1sentinel_tilt:0sentinel_running_scripts:0sentinel_scripts_queue_length:0sentinel_simulate_failure_flags:0master0:name=master,status=ok,address=172.17.80.109:6379,slaves=2,sentinels=3
【Redis哨兵(Sentinel)集群部署】
文章图片
登录node1 redis节点,查看redis主从配置信息:
[root@node01 redis]# redis-cli -a redhat6.3Warning: Using a password with \'-a\' option on the command line interface may not be safe.127.0.0.1:6379>
info replication
文章图片
推荐阅读
- #导入MD文档图片#windows下如何安装配置删除MySQL数据库
- #导入MD文档图片#使用ora2pg迁移Oracle19c到PG13并使用OGG配置实时同步
- Linux安装Redis
- 面向大规模商业系统的数据库设计和实践
- 深入剖析 MySQL 自增锁
- HBase写入流程
- 缓存与数据库的双写一致性
- 「免费开源」基于Vue和Quasar前端SPA项目crudapi后台管理系统实战之数据库逆向
- MySQL 页完全指南——浅入深出页的原理