redis 哨兵集群搭建

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

redis 哨兵集群搭建_第1张图片


一、下载解压压缩包 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

redis 哨兵集群搭建_第2张图片

你可能感兴趣的:(redis,数据库,缓存)