Redis-哨兵-哨兵结构搭建

配置哨兵

  • 配置一拖二的主从结构
  • 配置三个哨兵(配置相同,端口不同)
  • 启动哨兵
redis-sentinel sentinel-端口号.conf
创建三个哨兵配置文件,配置文件如下
[root@localhost redis-4.0.11]# cat sentinel.conf |grep -v "#"|grep -v "^$"
port 26379
dir /tmp
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
sentinel deny-scripts-reconfig yes
[root@localhost conf]# vi sentinel-26379.conf 
port 26379
dir /redis-4.0.11/data
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 180000
[root@localhost redis-4.0.11]# cat sentinel.conf |grep -v "#"|grep -v "^$" > ./conf/sentinel-26379.conf
[root@localhost conf]# sed 's/26379/26380/g' sentinel-26379.conf > sentinel-26380.conf 
[root@localhost conf]# sed 's/26379/26380/g' sentinel-26379.conf > sentinel-26381.conf 
创建三个redis.conf放在/redis-4.0.11/conf目录下,分别为redis-6379.conf、redis-6380.conf、redis-6381.conf

redis-6379.conf

port 6379
daemonize no
#logfile "6379.log"
dir /redis-4.0.11/data
dbfilename dump-6379.rdb
rdbcompression yes
rdbchecksum yes
save 10 2
appendonly yes
appendfsync always
appendfilename appendonly-6379.aof
bind 127.0.0.1
databases 16

redis-6380.conf

port 6380
daemonize no
#logfile "6380.log"
dir /redis-4.0.11/data
slaveof 127.0.0.1 6379

redis-6381.conf

port 6381
daemonize no
#logfile "6381.log"
dir /redis-4.0.11/data
slaveof 127.0.0.1 6379

启动顺序

先启动redis服务器

[root@localhost /]# redis-server /redis-4.0.11/conf/redis-6379.conf 
[root@localhost /]# redis-server /redis-4.0.11/conf/redis-6380.conf 
[root@localhost /]# redis-server /redis-4.0.11/conf/redis-6381.conf 

再启动redis哨兵

[root@localhost ~]# redis-sentinel /redis-4.0.11/conf/sentinel-26379.conf 
[root@localhost ~]# redis-sentinel /redis-4.0.11/conf/sentinel-26380.conf 
[root@localhost ~]# redis-sentinel /redis-4.0.11/conf/sentinel-26381.conf 
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容