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 

你可能感兴趣的:(Redis-哨兵-哨兵结构搭建)