redis 哨兵集群搭建

部署redis 哨兵集群 一主两从三哨兵集群使用redis6.2.7版本。配置文件中配置 需要结合自己业务特性自己变更。redis哨兵的结构图


一、下载解压压缩包 tail -zxf redis.

https://download.redis.io/releases/redis-6.2.7.tar.gz

  1. 在src目录下编译 make
  2. 执行 make install

二、新增配置文件

0.171主节点配置文件

redis.conf

bind 0.0.0.0

port 6379

protected-mode no

daemonize yes

requirepass "accountredis"

masterauth "accountredis"

logfile "/usr/local/redis-6.2.4/log/redis6379.log"

#减少异步复制和脑裂配置

min-replicas-to-write 1

min-replicas-max-lag 10

2.sentinel.conf

port 26379

#关闭保护模式,可以外部访问。

protected-mode no

#设置为后台启动。

daemonize yes

#日志文件。

logfile "/usr/local/redis-6.2.4/log/sentinel.log"

#指定主机IP地址和端口,并且指定当有2台哨兵认为主机挂了,则对主机进行容灾切换。

sentinel monitor mymaster 192.168.0.173 6381 2

#当在Redis实例中开启了requirepass,这里就需要提供密码。

sentinel auth-pass mymaster accountredis

#这里设置了主机多少秒无响应,则认为挂了。

sentinel down-after-milliseconds mymaster 3000

#主备切换时,最多有多少个slave同时对新的master进行同步,这里设置为默认的1。

0.172配置文件

redis.conf

bind 0.0.0.0

port 6380

protected-mode no

daemonize yes

requirepass "accountredis"

masterauth "accountredis"

logfile "/usr/local/redis-6.2.4/log/redis6380.log"

#减少异步复制和脑裂配置

min-replicas-to-write 1

min-replicas-max-lag 10

replicaof 192.168.0.171 6379

sentinel.conf

port 26380

#关闭保护模式,可以外部访问。

protected-mode no

#设置为后台启动。

daemonize yes

#日志文件。

logfile "/usr/local/redis-6.2.4/log/sentinel.log"

#指定主机IP地址和端口,并且指定当有2台哨兵认为主机挂了,则对主机进行容灾切换。

0.173 配置文件 和0.172配置文件除了端口号外其余相同

三、使用配置文件启动redis服务和哨兵

执行启动命令分别启动redis 

redis-server ../conf/redis.conf

redis-sentinel ../conf/sentinel.conf

四、连接验证

redis-cli -h 192.168.0.171 -p 6379 -a accountredis

查看集群信息

info

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冒黑烟的拖拉机

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值