docker部署redis-sentinel(一主二从三哨兵)

docker部署redis-sentinel(一主二从三哨兵)
在这里插入图片描述

1、环境准备
redis5.0镜像
一主192.168.23.135:6379 数据映射文件data6379,配置文件redis6379.conf
两从
192.168.23.135:6380 数据映射文件data6380,配置文件redis6380.conf
192.168.23.135:6381 数据映射文件data6381,配置文件redis6381.conf
三哨兵
192.168.23.135:26379 数据映射文件data26379,配置文件sentinel26379.conf
192.168.23.135:26380 数据映射文件data26380,配置文件sentinel26380.conf
192.168.23.135:26381 数据映射文件data26381,配置文件sentinel26381.conf

注意: docker容器启动哨兵集群的话需要在主从节点、哨兵节点所有的配置文件中加入以下两个配置
这里配置很重要
,因为哨兵启动后需要往配置自己的配置文件中写入数据,并且哨兵之间以及和主从节点之间都是需要通信的,如果不这样配置的话,默认是用的docker的网段通信的,这样就有一个问题: 在服务器上测试没有问题,但是java代码连接的哨兵选举的主节点的IP是docker的内网网段,java代码是访问不通的,java只能访问服务器对外提供的IP(这里是192.168.23.135),所有必须进行如下配置

#这是主从节点的配置属性
#这里的IP和port对应每个配置文件中自己的IP和port,比如主节点6379配置如下
replica-announce-ip 192.168.21.135
replica-announce-port 6379
#如果是6380,配置如下,依次类推
replica-announce-ip 192.168.21.135
replica-announce-port 6380

#哨兵配置属性如下
sentinel announce-ip 192.168.23.136
sentinel announce-port 26379

一主两从
这里不再重复搭建一主两从
一主两从请参考这里
哨兵配置
哨兵的配置文件也需要是对应版本redis的配置
只需修改以下配置即可,三个配置文件是一样的

# sentinel monitor <master-redis-name> <master-redis-ip> <master-redis-port> <quorum>
# quorum是一个数字,指明当有多少个sentinel认为一个master失效时(值一般为:sentinel总数/2 + 1),master才算真正失效
sentinel monitor mymaster 192.168.0.60 6379 2   # mymaster这个名字随便取,客户端访问时会用到
#以下三个可以使用默认的,也可以自行配置
#down-after-milliseconds是master在连续的5000毫秒内向sentinel返回无效的回复时,sentinel会标记该master为主观下线
sentinel down-after-milliseconds mymaster 5000
#故障转移超时时间(毫秒),如果3分钟内没有完成故障转移操作,则视为转移失败
sentinel failover-timeout mymaster 60000
# 故障转移之后,进行新的主从复制,配置项指定了最多有多少个slave对新的master进行同步,那可以理解为1是串行复制,大于1是并行复制
sentinel parallel-syncs mymaster 1
# 以下两个配置指令在环境中非常有用,因为NAT可以通过非本地地址从外部访问Sentinel。
# 当提供announce-ip时,Sentinel将在通信中声明指定的IP地址,而不是像通常那样自动检测本地地址。
# 类似地,当提供announce-port 有效且非零时,Sentinel将宣布指定的TCP端口。
# 这两个选项不需要一起使用,如果只提供announce-ip,Sentinel将宣告指定的IP和“port”选项指定的服务器端口。
# 如果仅提供announce-port,Sentinel将通告自动检测到的本地IP和指定端口
sentinel announce-ip 192.168.23.136
sentinel announce-port 26379

哨兵配置文件

# Example sentinel.conf

# *** IMPORTANT ***
#
# By default Sentinel will not be reachable from interfaces different than
# localhost, either use the 'bind' directive to bind to a list of network
# interfaces, or disable protected mode with "protected-mode no" by
# adding it to this configuration file.
#
# Before doing that MAKE SURE the instance is protected from the outside
# world via firewalling or other means.
#
# For example you may use one of the following:
#
# bind 127.0.0.1 192.168.1.1
#
# protected-mode no

# port <sentinel-port>
# The port that this sentinel instance will run on
port 26379

# By default Redis Sentinel does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis-sentinel.pid when
# daemonized.
daemonize no

# When running daemonized, Redis Sentinel writes a pid file in
# /var/run/redis-sentinel.pid by default. You can specify a custom pid file
# location here.
pidfile /var/run/redis-sentinel.pid

# Specify the log file name. Also the empty string can be used to force
# Sentinel to log on the standard output. Note that if you use standard
# output for logging but daemonize, logs will be sent to /dev/null
logfile ""

# sentinel announce-ip <ip>
# sentinel announce-port <port>
#
# The above two configuration directives are useful in environments where,
# because of NAT, Sentinel is reachable from outside via a non-local address.
#
# When announce-ip is provided, the Sentinel will claim the specified IP address
# in HELLO messages used to gossip its presence, instead of auto-detecting the
# local address as it usually does.
#
# Similarly when announce-port is provided and is valid and non-zero, Sentinel
# will announce the specified TCP port.
#
# The two options don't need to be used together, if only announce-ip is
# provided, the Sentinel will announce the specified IP and the server port
# as specified by the "port" option. If only announce-port is provided, the
# Sentinel will announce the auto-detected local IP and the specified port.
#
# Example:
#
# sentinel announce-ip 1.2.3.4

# dir <working-directory>
# Every long running process should have a well-defined working directory.
# For Redis Sentinel to chdir to /tmp at startup is the simplest thing
# for the process to don't interfere with administrative tasks such as
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值