当前位置: 首页 > news >正文

wordpress管理媒体库插件/企业关键词优化最新报价

wordpress管理媒体库插件,企业关键词优化最新报价,论坛类网站怎么建设,个人网站建设详细教程Redis哨兵(sentinel)搭建 7.2.5 文章目录 一、单节点哨兵1. 环境介绍2. 环境前准备工作3. 安装 Redis 7.2.54. redis 配置修改并且启动4.1 修改配置文件4.2 编写启动脚本 5. 开启主从5.1 开启5.2 主库实例查看主从信息 6. 创建sentinel的配置文件并启动6.1 创建配置文件6.2 启…

Redis哨兵(sentinel)搭建 7.2.5

文章目录

  • 一、单节点哨兵
    • 1. 环境介绍
    • 2. 环境前准备工作
    • 3. 安装 Redis 7.2.5
    • 4. redis 配置修改并且启动
      • 4.1 修改配置文件
      • 4.2 编写启动脚本
    • 5. 开启主从
      • 5.1 开启
      • 5.2 主库实例查看主从信息
    • 6. 创建sentinel的配置文件并启动
      • 6.1 创建配置文件
      • 6.2 启动
      • 6.3 手动停止主库运行,模拟主库宕机
      • 6.4 手动修复宕机的主库,sentinel会自动发现
  • 二、多节点哨兵
    • 1.Redis配置文件修改并启动
      • 1.1 redis_master 节点
      • 1.2 redis_slave1 节点
      • 1.3 redis_slave2 节点
    • 2. 开启主从
      • 2.1 redis_slave1 节点
      • 2.2 redis_slave2 节点
      • 2.3 redis_master 节点
    • 3. 编写sentinel配置文件并启动
      • 3.1 redis_master 节点
      • 3.2 redis_slave1 节点
      • 3.3 redis_slave2 节点
    • 4. 验证sentinel能够自动切换
      • 4.1 手动停止主库运行,模拟主库宕机
      • 4.2 当16370 实例宕机后,查看集群情况
      • 4.3 恢复16370 实例会成为slaves节点
    • 5. 手动停掉一个sentinel实例
      • 5.1 将redis_master主机中的sentinel实例给停止掉
      • 5.2 验证主从切换
      • 5.3 恢复Redis 实例
    • 6. 手动停掉两个sentinel 实例
      • 6.1 将redis_slave1 主机中的sentinel 实例停止
      • 6.2 验证主从切换

一、单节点哨兵

1. 环境介绍

操作系统Centos 7
内核版本Linux 3.10.0-957.el7.x86_64
主机名称master
IP192.168.1.100
端口master:16370 slaver1:16371 slaver2: 16372 sentinel:16379

2. 环境前准备工作

# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld# 修改 hostname
hostnamectl set-hostname xxxx  # 修改后退出当前终端重新连接即可# 更新下软件源
# 地址 https://developer.aliyun.com/mirror/# 时区调整,时间校准
date -R
timedatectl set-timezone Asia/Shanghai
yum -y install ntp
ntpdate ntp1.aliyun.com# 关闭 selinux: 
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0# 修改内存分配控制
vi /etc/sysctl.confvm.overcommit_memory = 1
# 设置TPC积压值
net.core.somaxconn= 1024# 使其配置文件生效
sysctl -p /etc/sysctl.conf

3. 安装 Redis 7.2.5

# 下载地址
http://download.redis.io/releases/# 下载
wget http://download.redis.io/releases/redis-7.2.5.tar.gz
# 解压
tar -xf redis-7.2.5.tar.gz -C /opt/redis# 编译
make MALLOC=libc# 安装 注意如果安装提示python3不存在 执行 yum install -y python3
make install PREFIX=/usr/local/redis# 配置环境变量
vi /etc/profile.d/redis.sh#!/bin/bashexport REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin # 使其配置生效
source /etc/profile.d/redis.sh

4. redis 配置修改并且启动

4.1 修改配置文件

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/1637{0..2}
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/1637{0..2}
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/1637{0..2}# 创建redis pid存储目录
mkdir /usr/local/redis/run# redis配置文件 16370
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16370
# pid存储目录
pidfile /usr/local/redis/run/redis_16370.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16370.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16370
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes  # redis配置文件 16371
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16371
# pid存储目录
pidfile /usr/local/redis/run/redis_16371.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16371.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16371
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes  # redis配置文件 16372
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16372
# pid存储目录
pidfile /usr/local/redis/run/redis_16372.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16372.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16372
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes  # 复制下面命令即可
cat > /usr/local/redis/conf/redis_16370.conf <<EOF 
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16370
# pid存储目录
pidfile /usr/local/redis/run/redis_16370.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16370.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16370
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes 
EOFcat > /usr/local/redis/conf/redis_16371.conf <<EOF 
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16371
# pid存储目录
pidfile /usr/local/redis/run/redis_16371.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16371.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16371
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes 
EOFcat > /usr/local/redis/conf/redis_16372.conf <<EOF 
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16372
# pid存储目录
pidfile /usr/local/redis/run/redis_16372.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16372.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16372
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes 
EOF

4.2 编写启动脚本

# 启动脚本
cat > /usr/local/redis/bin/master-slave_start.sh << EOF
#!/bin/bashredis-server /usr/local/redis/conf/redis_16370.conf
redis-server /usr/local/redis/conf/redis_16371.conf
redis-server /usr/local/redis/conf/redis_16372.conf
EOF# 赋予可执行权限
chmod +x /usr/local/redis/bin/master-slave_start.sh# 关闭脚本
vi /usr/local/redis/bin/master-slave_shutdown.sh#!/bin/bashkill -9 $(ps -ef | grep 1637 | grep -v grep | awk '{print $2}')# 赋予可执行权限
chmod +x /usr/local/redis/bin/master-slave_shutdown.sh

5. 开启主从

5.1 开启

# 以"192.168.1.100:16370"实例为主库,以"192.168.1.100:16371"实例和"192.168.1.100:16372"实例为从库。
# -a 参数指定密码
# 从库实例开启主从redis-cli -h 192.168.1.100 -p 16371 -a dongdong slaveof 192.168.1.100 16370redis-cli -h 192.168.1.100 -p 16372 -a dongdong slaveof 192.168.1.100 16370# Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.# 警告:在命令行界面上使用带有“-a”或“-u”选项的密码可能不安全。  可以忽略# 解决方式# redis-cli -h 192.168.1.100 -p 16371 -a dongdong --no-auth-warning  slaveof 192.168.1.100 16370 

5.2 主库实例查看主从信息

redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication [root@master-slave ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.100,port=16371,state=online,offset=8428,lag=0
slave1:ip=192.168.1.100,port=16372,state=online,offset=8428,lag=1
master_failover_state:no-failover
master_replid:a292603e2c96a6f451055e6d84a60795f81f2928
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:8428
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:8428

6. 创建sentinel的配置文件并启动

6.1 创建配置文件

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/16379
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/16379
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/16379# 创建redis pid存储目录
mkdir /usr/local/redis/runcat > /usr/local/redis/conf/sentinel.conf <<EOF
bind 192.168.1.100
port 16379
dir /usr/local/redis/data/16379
sentinel monitor redis_master 192.168.1.100 16370 1
sentinel down-after-milliseconds redis_master 5000
sentinel auth-pass redis_master dongdong
EOF配置文件参数说明如下:sentinel monitor redis_master 192.168.1.100 16370 1:指定Redis初始集群的master库节点并命名为"redis_master",注意这个"1"的含义,他表示sentinel需要最少的投票数。这在于多sentinel的场景下很有用,由于本案例只是用了1个sentinel,因此我就设置为1。在生产环境中,建议配置多sentinel的模式,建议最少设置为3(建议设置奇数)个sentinel物理节点,而后将此处的"1"改为"2",表示3个sentinel中最少有2个节点认为master库宕机时,才会真正意义上认为master库宕机。       sentinel down-after-milliseconds redis_master 5000:监控sentinel集群时,如果超过了5000毫秒(即5秒)仍然没有响应,则sentinel会判定master库宕机了。sentinel auth-pass redis_master dongdong:由于sentinel需要访问Redis集群,因此我们要设置访问整个集群的密码,我这里指定的密码为"dongdong",这意味着所有的节点都使用相同的密码。

6.2 启动

# 启动 sentinel进程
redis-sentinel /usr/local/redis/conf/sentinel.conf &> /usr/local/redis/log/16379/sentinel_16379.log &root@master ~]# redis-sentin el /usr/local/redis/conf/sentinel.conf &> /usr/local/redis/log/16379/sentinel_16379.log &
[1] 29961# 查看日志
tail -100f /usr/local/redis/log/16379/sentinel_16379.log
[root@master ~]# tail -100f /usr/local/redis/log/16379/sentinel_16379.log
30008:X 17 Jul 2024 19:51:15.356 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30008:X 17 Jul 2024 19:51:15.356 * Redis version=7.2.5, bits=64, commit=00000000, modified=0, pid=30008, just started
30008:X 17 Jul 2024 19:51:15.356 * Configuration loaded
30008:X 17 Jul 2024 19:51:15.356 * Increased maximum number of open files to 10032 (it was originally set to 1024).
30008:X 17 Jul 2024 19:51:15.356 * monotonic clock: POSIX clock_gettime
30008:X 17 Jul 2024 19:51:15.357 * Running mode=sentinel, port=16379.
30008:X 17 Jul 2024 19:51:15.357 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
30008:X 17 Jul 2024 19:51:15.357 * Sentinel ID is a91bf648c16246f3f7c7e1aa2b1fc6fad38f772b
30008:X 17 Jul 2024 19:51:15.357 # +monitor master redis_master 192.168.1.100 16370 quorum 1# 通过redis-cli 进入 查看
redis-cli -h 192.168.1.100 -p 16379[root@master ~]# redis-cli -h 192.168.1.100 -p 16379
192.168.1.100:16379> ping
PONG
192.168.1.100:16379> 

6.3 手动停止主库运行,模拟主库宕机

# 切换前主从状态正常
[root@master ~]# ss -npl | grep redis
tcp    LISTEN     0      128    192.168.1.100:16370              *:*                   users:(("redis-server",pid=29871,fd=6))
tcp    LISTEN     0      128    192.168.1.100:16371              *:*                   users:(("redis-server",pid=29873,fd=6))
tcp    LISTEN     0      128    192.168.1.100:16372              *:*                   users:(("redis-server",pid=29881,fd=6))
tcp    LISTEN     0      128    192.168.1.100:16379              *:*                   users:(("redis-sentinel",pid=30008,fd=6))# 查看集群状态 master
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication [root@master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.100,port=16371,state=online,offset=111085,lag=0
slave1:ip=192.168.1.100,port=16372,state=online,offset=111085,lag=1
master_failover_state:no-failover
master_replid:208227bbd586d90841dcf753ba669dbde246bba7
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:111085
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:111085# 查看集群状态 slaver
redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replication [root@master ~]# redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16370
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_read_repl_offset:118087
slave_repl_offset:118087
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:208227bbd586d90841dcf753ba669dbde246bba7
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:118087
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:118073# 查看集群状态 slaver
redis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication [root@master ~]# redis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16370
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:126869
slave_repl_offset:126869
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:208227bbd586d90841dcf753ba669dbde246bba7
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:126869
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:126855# 手动将主库宕机,观察从库被sentinel实现了自动切换:
redis-cli -h 192.168.1.100 -p 16370 -a dongdong shutdown[root@master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.# 再查看集群状态 master
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication  # 由于将主库服务停了,因此无法再次连接主库
[root@master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 192.168.1.100:16370: Connection refused# 再查看集群状态 slaves  发现变成了master节点
redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replication [root@master ~]# redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.1.100,port=16372,state=online,offset=150234,lag=0
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:208227bbd586d90841dcf753ba669dbde246bba7
master_repl_offset:150234
second_repl_offset:134150
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:150220# 查看集群状态 slaver
redis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication [root@master ~]# redis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16371
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_read_repl_offset:154406
slave_repl_offset:154406
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:208227bbd586d90841dcf753ba669dbde246bba7
master_repl_offset:154406
second_repl_offset:134150
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:154392# 查看sentinel的日志信息,不难发现有记录切换的过程
tail -100f /usr/local/redis/log/16379/sentinel_16379.log[root@master ~]# tail -100f /usr/local/redis/log/16379/sentinel_16379.log
30008:X 17 Jul 2024 19:51:15.356 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30008:X 17 Jul 2024 19:51:15.356 * Redis version=7.2.5, bits=64, commit=00000000, modified=0, pid=30008, just started
30008:X 17 Jul 2024 19:51:15.356 * Configuration loaded
30008:X 17 Jul 2024 19:51:15.356 * Increased maximum number of open files to 10032 (it was originally set to 1024).
30008:X 17 Jul 2024 19:51:15.356 * monotonic clock: POSIX clock_gettime
30008:X 17 Jul 2024 19:51:15.357 * Running mode=sentinel, port=16379.
30008:X 17 Jul 2024 19:51:15.357 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
30008:X 17 Jul 2024 19:51:15.357 * Sentinel ID is a91bf648c16246f3f7c7e1aa2b1fc6fad38f772b
30008:X 17 Jul 2024 19:51:15.357 # +monitor master redis_master 192.168.1.100 16370 quorum 1
30008:X 17 Jul 2024 20:15:40.962 # +sdown master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:40.962 # +odown master redis_master 192.168.1.100 16370 #quorum 1/1
30008:X 17 Jul 2024 20:15:40.962 # +new-epoch 1
30008:X 17 Jul 2024 20:15:40.962 # +try-failover master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:40.968 * Sentinel new configuration saved on disk
30008:X 17 Jul 2024 20:15:40.968 # +vote-for-leader a91bf648c16246f3f7c7e1aa2b1fc6fad38f772b 1
30008:X 17 Jul 2024 20:15:40.968 # +elected-leader master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:40.968 # +failover-state-select-slave master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:41.026 # +selected-slave slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:41.027 * +failover-state-send-slaveof-noone slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:41.093 * +failover-state-wait-promotion slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:42.015 * Sentinel new configuration saved on disk
30008:X 17 Jul 2024 20:15:42.015 # +promoted-slave slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:42.015 # +failover-state-reconf-slaves master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:42.096 * +slave-reconf-sent slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.040 * +slave-reconf-inprog slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.040 * +slave-reconf-done slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.094 # +failover-end master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.094 # +switch-master redis_master 192.168.1.100 16370 192.168.1.100 16371
30008:X 17 Jul 2024 20:15:43.095 * +slave slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16371
30008:X 17 Jul 2024 20:15:43.095 * +slave slave 192.168.1.100:16370 192.168.1.100 16370 @ redis_master 192.168.1.100 16371
30008:X 17 Jul 2024 20:15:43.100 * Sentinel new configuration saved on disk
30008:X 17 Jul 2024 20:15:48.121 # +sdown slave 192.168.1.100:16370 192.168.1.100 16370 @ redis_master 192.168.1.100 16371

6.4 手动修复宕机的主库,sentinel会自动发现

# 修复之前,16370端口是连接不上的
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication[root@master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 192.168.1.100:16370: Connection refused[root@master ~]# redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.1.100,port=16372,state=online,offset=190264,lag=1
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:208227bbd586d90841dcf753ba669dbde246bba7
master_repl_offset:190410
second_repl_offset:134150
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:190396[root@master ~]# redis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16371
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:192204
slave_repl_offset:192204
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:208227bbd586d90841dcf753ba669dbde246bba7
master_repl_offset:192204
second_repl_offset:134150
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:192190# 修复之后,之前宕机的主库会自动加入集群并成为slaves节点
redis-server /usr/local/redis/conf/redis_16370.conf
[root@master ~]# redis-server /usr/local/redis/conf/redis_16370.conf
[root@master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16371
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:199215
slave_repl_offset:199215
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:199215
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:199047
repl_backlog_histlen:169# 查看 
redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replicationredis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication [root@master ~]# redis-cli -h 192.168.1.100 -p 16371 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2 # slaves 变成两个了
slave0:ip=192.168.1.100,port=16372,state=online,offset=203533,lag=1
slave1:ip=192.168.1.100,port=16370,state=online,offset=203533,lag=1
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:208227bbd586d90841dcf753ba669dbde246bba7
master_repl_offset:203533
second_repl_offset:134150
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:203519[root@master ~]# redis-cli -h 192.168.1.100 -p 16372 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16371
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:207851
slave_repl_offset:207851
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:23729dc7d7aeafa6f85a2a647442965c80b379ed
master_replid2:208227bbd586d90841dcf753ba669dbde246bba7
master_repl_offset:207851
second_repl_offset:134150
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:207837# 注意观察sentinel日志哟,会有新日志记录
tail -100f /usr/local/redis/log/16379/sentinel_16379.log
[root@master ~]# tail -100f /usr/local/redis/log/16379/sentinel_16379.log
30008:X 17 Jul 2024 19:51:15.356 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30008:X 17 Jul 2024 19:51:15.356 * Redis version=7.2.5, bits=64, commit=00000000, modified=0, pid=30008, just started
30008:X 17 Jul 2024 19:51:15.356 * Configuration loaded
30008:X 17 Jul 2024 19:51:15.356 * Increased maximum number of open files to 10032 (it was originally set to 1024).
30008:X 17 Jul 2024 19:51:15.356 * monotonic clock: POSIX clock_gettime
30008:X 17 Jul 2024 19:51:15.357 * Running mode=sentinel, port=16379.
30008:X 17 Jul 2024 19:51:15.357 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
30008:X 17 Jul 2024 19:51:15.357 * Sentinel ID is a91bf648c16246f3f7c7e1aa2b1fc6fad38f772b
30008:X 17 Jul 2024 19:51:15.357 # +monitor master redis_master 192.168.1.100 16370 quorum 1
30008:X 17 Jul 2024 20:15:40.962 # +sdown master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:40.962 # +odown master redis_master 192.168.1.100 16370 #quorum 1/1
30008:X 17 Jul 2024 20:15:40.962 # +new-epoch 1
30008:X 17 Jul 2024 20:15:40.962 # +try-failover master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:40.968 * Sentinel new configuration saved on disk
30008:X 17 Jul 2024 20:15:40.968 # +vote-for-leader a91bf648c16246f3f7c7e1aa2b1fc6fad38f772b 1
30008:X 17 Jul 2024 20:15:40.968 # +elected-leader master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:40.968 # +failover-state-select-slave master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:41.026 # +selected-slave slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:41.027 * +failover-state-send-slaveof-noone slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:41.093 * +failover-state-wait-promotion slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:42.015 * Sentinel new configuration saved on disk
30008:X 17 Jul 2024 20:15:42.015 # +promoted-slave slave 192.168.1.100:16371 192.168.1.100 16371 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:42.015 # +failover-state-reconf-slaves master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:42.096 * +slave-reconf-sent slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.040 * +slave-reconf-inprog slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.040 * +slave-reconf-done slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.094 # +failover-end master redis_master 192.168.1.100 16370
30008:X 17 Jul 2024 20:15:43.094 # +switch-master redis_master 192.168.1.100 16370 192.168.1.100 16371
30008:X 17 Jul 2024 20:15:43.095 * +slave slave 192.168.1.100:16372 192.168.1.100 16372 @ redis_master 192.168.1.100 16371
30008:X 17 Jul 2024 20:15:43.095 * +slave slave 192.168.1.100:16370 192.168.1.100 16370 @ redis_master 192.168.1.100 16371
30008:X 17 Jul 2024 20:15:43.100 * Sentinel new configuration saved on disk
30008:X 17 Jul 2024 20:15:48.121 # +sdown slave 192.168.1.100:16370 192.168.1.100 16370 @ redis_master 192.168.1.100 16371
30008:X 17 Jul 2024 20:30:15.529 # -sdown slave 192.168.1.100:16370 192.168.1.100 16370 @ redis_master 192.168.1.100 16371
30008:X 17 Jul 2024 20:30:25.504 * +convert-to-slave slave 192.168.1.100:16370 192.168.1.100 16370 @ redis_master 192.168.1.100 16371# 除了提到上面的变化外,还有一点变化就是配置文件也修改了,每个"slave"节点都新增了 下面三行 本案例只有192.168.1.100:16370 和 192.168.1.100:16372是 slave
# Generated by CONFIG REWRITE
replicaof 192.168.1.100 16371
latency-tracking-info-percentiles 50 99 99.9
user default on sanitize-payload #162fffe9f429e1fa5d351c11f5a7f2f3031806c5125eeb84993f68738cbb6c84 ~* &* +@all# Generated by CONFIG REWRITE
replicaof 192.168.1.100 16371
latency-tracking-info-percentiles 50 99 99.9
user default on sanitize-payload #162fffe9f429e1fa5d351c11f5a7f2f3031806c5125eeb84993f68738cbb6c84 ~* &* +@all

二、多节点哨兵

一主两从三哨兵

一共三台机器,每台机器部署一个哨兵

注意: 后面启动哨兵可能会出现两个警告

WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1’ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1’ for this to take effect.

警告:必须启用内存超量使用!没有它,在内存不足的情况下,后台保存或复制可能会失败。要解决此问题,请将“vm.overcommit_memory=1”添加到/etc/sysctl.conf中,然后重新启动或运行命令“sysctl vm.overcommit_memory=1”以使其生效。

修改内存分配控制

vi /etc/sysctl.conf

vm.overcommit_memory = 1

使其配置文件生效

sysctl -p /etc/sysctl.conf

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.

警告:无法强制执行TCP积压设置511,因为/proc/sys/net/core/somaxconn设置为较低的值128。

vi /etc/sysctl.conf

net.core.somaxconn= 1024

sysctl -p /etc/sysctl.conf

操作系统Centos 7Centos 7Centos 7
内核版本Linux 3.10.0-957.el7.x86_64Linux 3.10.0-957.el7.x86_64Linux 3.10.0-957.el7.x86_64
主机名称redis_masterredis_salve1redis_salve2
IP192.168.1.100192.168.1.200192.168.1.250
端口16370、2637016371、2637016372、26370

安装前准备工作已经Redis安装,请参照上面步骤进行

1.Redis配置文件修改并启动

1.1 redis_master 节点

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/16370
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/16370
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/16370# 创建redis pid存储目录
mkdir /usr/local/redis/run/16370# 修改配置文件
# 复制下面命令即可
cat > /usr/local/redis/conf/16370/redis_16370.conf <<EOF 
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.100   
# 端口  
port 16370
# pid存储目录
pidfile /usr/local/redis/run/16370/redis_16370.pid   
# 日志存储目录
logfile /usr/local/redis/log/16370/redis_16370.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16370
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes 
EOF# 启动Redis
redis-server /usr/local/redis/conf/16370/redis_16370.conf

1.2 redis_slave1 节点

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/16371
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/16371
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/16371# 创建redis pid存储目录
mkdir /usr/local/redis/run/16371# 修改配置文件
# 复制下面命令即可
cat > /usr/local/redis/conf/16371/redis_16371.conf <<EOF 
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.200   
# 端口  
port 16371
# pid存储目录
pidfile /usr/local/redis/run/16371/redis_16371.pid   
# 日志存储目录
logfile /usr/local/redis/log/16371/redis_16371.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16371
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes 
EOF# 启动Redis
redis-server /usr/local/redis/conf/16371/redis_16371.conf

1.3 redis_slave2 节点

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/16372
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/16372
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/16372# 创建redis pid存储目录
mkdir /usr/local/redis/run/16372# 修改配置文件
# 复制下面命令即可
cat > /usr/local/redis/conf/16372/redis_16372.conf <<EOF 
# 开启保护模式
protected-mode yes
# 添加本机的ip
bind 192.168.1.250   
# 端口  
port 16372
# pid存储目录
pidfile /usr/local/redis/run/16372/redis_16372.pid   
# 日志存储目录
logfile /usr/local/redis/log/16372/redis_16372.log 
# 数据存储目录,目录要提前创建好
dir /usr/local/redis/data/16372
# 设置实例的验证口令
requirepass dongdong
# 以认证的方式连接到master。 如果master中使用了“密码保护”,slave必须交付正确的授权密码,才能连接成功。
# 此配置项中值需要和master机器的“requirepass”保持一致
masterauth dongdong
# 配置RDB持久化策略
save 900 1
save 300 10
save 60 10000
# 配置AOF持久化
appendonly yes 
appendfsync everysec
# 守护进程
daemonize yes 
EOF# 启动Redis
redis-server /usr/local/redis/conf/16372/redis_16372.conf

2. 开启主从

2.1 redis_slave1 节点

# 从库实例开启主从
redis-cli -h 192.168.1.200 -p 16371 -a dongdong slaveof 192.168.1.100 16370[root@redis_slave1 ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong slaveof 192.168.1.100 16370
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
OK# 从库实例查看主从信息
redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication [root@redis_slave1 ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16370
master_link_status:up
master_last_io_seconds_ago:9
master_sync_in_progress:0
slave_read_repl_offset:210
slave_repl_offset:210
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:466362240f16a7414b9236f931c6f97252ee00be
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:210
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:196

2.2 redis_slave2 节点

# 从库实例开启主从
redis-cli -h 192.168.1.250 -p 16372 -a dongdong slaveof 192.168.1.100 16370[root@redis_slave2 ~]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong slaveof 192.168.1.100 16370
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
OK# 从库实例查看主从信息
redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication [root@redis_slave2 ~]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16370
master_link_status:up
master_last_io_seconds_ago:10
master_sync_in_progress:0
slave_read_repl_offset:266
slave_repl_offset:266
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:466362240f16a7414b9236f931c6f97252ee00be
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:266
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:43
repl_backlog_histlen:224

2.3 redis_master 节点

# 主库实例查看主从信息
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication [root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.200,port=16371,state=online,offset=42,lag=0
slave1:ip=192.168.1.250,port=16372,state=online,offset=42,lag=1
master_failover_state:no-failover
master_replid:466362240f16a7414b9236f931c6f97252ee00be
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:56
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:56

3. 编写sentinel配置文件并启动

3.1 redis_master 节点

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/26370
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/26370
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/26370# 创建redis pid存储目录
mkdir /usr/local/redis/run/26370cat > /usr/local/redis/conf/26370/sentinel.conf <<EOF
bind 192.168.1.100
port 26370
dir /usr/local/redis/data/26370
sentinel monitor redis_master 192.168.1.100 16370 2
sentinel down-after-milliseconds redis_master 5000
sentinel auth-pass redis_master dongdong
EOF# 启动 sentinel进程
redis-sentinel /usr/local/redis/conf/26370/sentinel.conf &> /usr/local/redis/log/26370/sentinel_26370.log &[root@redis_master ~]# redis-sentinel /usr/local/redis/conf/26370/sentinel.conf &> /usr/local/redis/log/26370/sentinel_26370.log &
[1] 30569# 查看redis-sentinel 进程
[root@redis_master ~]# ps -ef | grep redis
root      30552      1  0 10:17 ?        00:00:01 redis-server 192.168.1.100:16370
root      30569  30499  0 10:33 pts/1    00:00:00 redis-sentinel 192.168.1.100:26370 [sentinel]  # 已经成功启动了
root      30574  30499  0 10:34 pts/1    00:00:00 grep --color=auto redis# 查看日志信息
tail -100f /usr/local/redis/log/26370/sentinel_26370.log[root@redis_master ~]# tail -100f /usr/local/redis/log/26370/sentinel_26370.log
30569:X 18 Jul 2024 10:33:50.636 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
30569:X 18 Jul 2024 10:33:50.636 * Redis version=7.2.5, bits=64, commit=00000000, modified=0, pid=30569, just started
30569:X 18 Jul 2024 10:33:50.636 * Configuration loaded
30569:X 18 Jul 2024 10:33:50.636 * Increased maximum number of open files to 10032 (it was originally set to 1024).
30569:X 18 Jul 2024 10:33:50.636 * monotonic clock: POSIX clock_gettime
30569:X 18 Jul 2024 10:33:50.637 * Running mode=sentinel, port=26370.
30569:X 18 Jul 2024 10:33:50.637 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
30569:X 18 Jul 2024 10:33:50.638 * Sentinel new configuration saved on disk
30569:X 18 Jul 2024 10:33:50.639 * Sentinel ID is 088b671eb4ac4c8d8a57805c1be88e4f76cf7ff8
30569:X 18 Jul 2024 10:33:50.639 # +monitor master redis_master 192.168.1.100 26370 quorum 2
30569:X 18 Jul 2024 10:33:52.638 * +sentinel sentinel 088b671eb4ac4c8d8a57805c1be88e4f76cf7ff8 192.168.1.100 26370 @ redis_master 192.168.1.100 26370
30569:X 18 Jul 2024 10:33:52.644 * Sentinel new configuration saved on disk

3.2 redis_slave1 节点

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/26370
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/26370
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/26370# 创建redis pid存储目录
mkdir /usr/local/redis/run/26370cat > /usr/local/redis/conf/26370/sentinel.conf <<EOF
bind 192.168.1.200
port 26370
dir /usr/local/redis/data/26370
sentinel monitor redis_master 192.168.1.100 16370 2
sentinel down-after-milliseconds redis_master 5000
sentinel auth-pass redis_master dongdong
EOF# 启动 sentinel进程
redis-sentinel /usr/local/redis/conf/26370/sentinel.conf &> /usr/local/redis/log/26370/sentinel_26370.log &[root@redis_slave1 ~]# redis-sentinel /usr/local/redis/conf/26370/sentinel.conf &> /usr/local/redis/log/26370/sentinel_26370.log &
[1] 38894# 查看redis-sentinel 进程
[root@redis_slave1 ~]# ps -ef | grep redis
root      38879      1  0 10:19 ?        00:00:01 redis-server 192.168.1.200:16371
root      38894  38840  0 10:36 pts/0    00:00:00 redis-sentinel 192.168.1.200:26370 [sentinel]
root      38899  38840  0 10:37 pts/0    00:00:00 grep --color=auto redis# 查看日志信息
tail -100f /usr/local/redis/log/26370/sentinel_26370.log[root@redis_slave1 ~]# tail -100f /usr/local/redis/log/26370/sentinel_26370.log
38894:X 18 Jul 2024 10:36:54.115 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
38894:X 18 Jul 2024 10:36:54.116 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
38894:X 18 Jul 2024 10:36:54.116 * Redis version=7.2.5, bits=64, commit=00000000, modified=0, pid=38894, just started
38894:X 18 Jul 2024 10:36:54.116 * Configuration loaded
38894:X 18 Jul 2024 10:36:54.116 * Increased maximum number of open files to 10032 (it was originally set to 1024).
38894:X 18 Jul 2024 10:36:54.116 * monotonic clock: POSIX clock_gettime
38894:X 18 Jul 2024 10:36:54.116 * Running mode=sentinel, port=26370.
38894:X 18 Jul 2024 10:36:54.116 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
38894:X 18 Jul 2024 10:36:54.119 * Sentinel new configuration saved on disk
38894:X 18 Jul 2024 10:36:54.119 * Sentinel ID is 93a83bf4770f1f8eda48b96ead065382ab2b5fe6
38894:X 18 Jul 2024 10:36:54.119 # +monitor master redis_slave1 192.168.1.200 26370 quorum 2
38894:X 18 Jul 2024 10:36:56.164 * +sentinel sentinel 93a83bf4770f1f8eda48b96ead065382ab2b5fe6 192.168.1.200 26370 @ redis_slave1 192.168.1.200 26370
38894:X 18 Jul 2024 10:36:56.170 * Sentinel new configuration saved on disk

3.3 redis_slave2 节点

# 创建redis数据存储目录
mkdir -p /usr/local/redis/data/26370
# 创建redis配置文件存储目录
mkdir -p /usr/local/redis/conf/26370
# 创建redis日志存储目录
mkdir -p /usr/local/redis/log/26370# 创建redis pid存储目录
mkdir /usr/local/redis/run/26370cat > /usr/local/redis/conf/26370/sentinel.conf <<EOF
bind 192.168.1.250
port 26370
dir /usr/local/redis/data/26370
sentinel monitor redis_master 192.168.1.100 16370 2
sentinel down-after-milliseconds redis_master 5000
sentinel auth-pass redis_master dongdong
EOF# 启动 sentinel进程
redis-sentinel /usr/local/redis/conf/26370/sentinel.conf &> /usr/local/redis/log/26370/sentinel_26370.log &[root@redis_slave2 ~]# redis-sentinel /usr/local/redis/conf/26370/sentinel.conf &> /usr/local/redis/log/26370/sentinel_26370.log &
[1] 39310# 查看redis-sentinel 进程
[root@redis_slave2 ~]# ps -ef | grep redis
root      39290      1  0 10:20 ?        00:00:03 redis-server 192.168.1.250:16372
root      39310  39251  0 10:50 pts/0    00:00:00 redis-sentinel 192.168.1.250:26370 [sentinel]
root      39316  39251  0 10:51 pts/0    00:00:00 grep --color=auto redis# 查看日志信息tail -100f /usr/local/redis/log/26370/sentinel_26370.log[root@redis_slave2 ~]# tail -100f /usr/local/redis/log/26370/sentinel_26370.log
39310:X 18 Jul 2024 10:50:57.403 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
39310:X 18 Jul 2024 10:50:57.403 * oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
39310:X 18 Jul 2024 10:50:57.403 * Redis version=7.2.5, bits=64, commit=00000000, modified=0, pid=39310, just started
39310:X 18 Jul 2024 10:50:57.403 * Configuration loaded
39310:X 18 Jul 2024 10:50:57.404 * Increased maximum number of open files to 10032 (it was originally set to 1024).
39310:X 18 Jul 2024 10:50:57.404 * monotonic clock: POSIX clock_gettime
39310:X 18 Jul 2024 10:50:57.404 * Running mode=sentinel, port=26370.
39310:X 18 Jul 2024 10:50:57.405 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
39310:X 18 Jul 2024 10:50:57.407 * Sentinel new configuration saved on disk
39310:X 18 Jul 2024 10:50:57.407 * Sentinel ID is 9227635399651de294a88fa16281232b9cbbccaf
39310:X 18 Jul 2024 10:50:57.407 # +monitor master redis_slave2 192.168.1.250 26370 quorum 2
39310:X 18 Jul 2024 10:50:59.427 * +sentinel sentinel 9227635399651de294a88fa16281232b9cbbccaf 192.168.1.250 26370 @ redis_slave2 192.168.1.250 26370
39310:X 18 Jul 2024 10:50:59.434 * Sentinel new configuration saved on disk

4. 验证sentinel能够自动切换

4.1 手动停止主库运行,模拟主库宕机

# 查看主库的状态
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replicationWarning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2  
slave0:ip=192.168.1.200,port=16371,state=online,offset=2898,lag=0
slave1:ip=192.168.1.250,port=16372,state=online,offset=2898,lag=0
master_failover_state:no-failover
master_replid:466362240f16a7414b9236f931c6f97252ee00be
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:2898
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:2898# 查看从库状态
redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication[root@redis_slave1 ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16370
master_link_status:up
master_last_io_seconds_ago:4
master_sync_in_progress:0
slave_read_repl_offset:3066
slave_repl_offset:3066
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:466362240f16a7414b9236f931c6f97252ee00be
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:3066
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:3052redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication[root@redis_slave2 ~]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.100
master_port:16370
master_link_status:up
master_last_io_seconds_ago:5
master_sync_in_progress:0
slave_read_repl_offset:3094
slave_repl_offset:3094
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:466362240f16a7414b9236f931c6f97252ee00be
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:3094
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:43
repl_backlog_histlen:3052# 各节点运行redis进程情况
root@redis_master ~]# ss -npl | grep redis
tcp    LISTEN     0      128    192.168.1.100:16370              *:*                   users:(("redis-server",pid=30552,fd=6))
tcp    LISTEN     0      128    192.168.1.100:26370              *:*                   users:(("redis-sentinel",pid=30569,fd=6))[root@redis_slave1 ~]# ss -npl | grep redis
tcp    LISTEN     0      128    192.168.1.200:16371              *:*                   users:(("redis-server",pid=38879,fd=6))
tcp    LISTEN     0      511    192.168.1.200:26370              *:*                   users:(("redis-sentinel",pid=38908,fd=6))[root@redis_slave2 ~]# ss -npl | grep redis
tcp    LISTEN     0      128    192.168.1.250:16372              *:*                   users:(("redis-server",pid=39290,fd=6))
tcp    LISTEN     0      128    192.168.1.250:26370              *:*                   users:(("redis-sentinel",pid=39310,fd=6))# 一切正常
# 手动模拟主库宕机 再来查看情况
redis-cli -h 192.168.1.100 -p 16370 -a dongdong shutdown[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.# 再次执行命令
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 192.168.1.100:16370: Connection refused  # 发现连接不上 因为我们把主库宕了

4.2 当16370 实例宕机后,查看集群情况

# 查看集群状态 
redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication  [root@redis_master ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication  
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master # 此时的slave1主机变成了master 节点
connected_slaves:1   # slave 也变成了1个
slave0:ip=192.168.1.250,port=16372,state=online,offset=14837,lag=1
master_failover_state:no-failover
master_replid:c6e88908dbe348999f5406625612e76ee4d6ffd1
master_replid2:b23a9a971ad73ed23fb81186529c671e54acbac4
master_repl_offset:14837
second_repl_offset:14231
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:14837# 查看集群状态
redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication  [root@redis_slave2 ~]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication  
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200 
master_port:16371
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:87953
slave_repl_offset:87953
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:c6e88908dbe348999f5406625612e76ee4d6ffd1
master_replid2:b23a9a971ad73ed23fb81186529c671e54acbac4
master_repl_offset:87953
second_repl_offset:14231
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:87953# 现在集群里面的情况就是 一主一从

4.3 恢复16370 实例会成为slaves节点

# 修复之前,16370端口是连接不上的
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication[root@master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 192.168.1.100:16370: Connection refused# 修复之后,之前宕机的主库会自动加入集群并成为slaves节点
# 启动Redis
redis-server /usr/local/redis/conf/16370/redis_16370.conf# 可能需要过了几秒才会显示哦 因为信息还没有同步过来哦
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication  
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_read_repl_offset:165354
slave_repl_offset:165354
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:c6e88908dbe348999f5406625612e76ee4d6ffd1
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:165354
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:164602
repl_backlog_histlen:753

5. 手动停掉一个sentinel实例

5.1 将redis_master主机中的sentinel实例给停止掉

# 查看redis进程
[root@redis_master ~]# ps -ef | grep redis
root      30646  30499  0 11:23 pts/1    00:00:06 redis-sentinel 192.168.1.100:26370 [sentinel]
root      30663      1  0 11:42 ?        00:00:01 redis-server 192.168.1.100:16370
root      30672  30499  0 11:50 pts/1    00:00:00 grep --color=auto redis# 杀掉 进程id为30646服务
kill -9 30646# 再次查看redis进程 sentinel 已经被杀掉了
[root@redis_master ~]# ps -ef | grep redis
root      30663      1  0 11:42 ?        00:00:01 redis-server 192.168.1.100:16370
root      30676  30499  0 11:51 pts/1    00:00:00 grep --color=auto redis

5.2 验证主从切换

# 查看各节点状况 此时slave1这台是主库
# 查询从库状态 redis_master主机
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:251306
slave_repl_offset:251306
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:c6e88908dbe348999f5406625612e76ee4d6ffd1
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:251306
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:164602
repl_backlog_histlen:86705# 查询从库状态 redis_slave2主机
redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication 
[root@redis_master ~]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:up
master_last_io_seconds_ago:0
master_sync_in_progress:0
slave_read_repl_offset:254136
slave_repl_offset:254136
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:c6e88908dbe348999f5406625612e76ee4d6ffd1
master_replid2:b23a9a971ad73ed23fb81186529c671e54acbac4
master_repl_offset:254136
second_repl_offset:14231
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:254136# 查询主库状态
redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication 
[root@redis_master ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.250,port=16372,state=online,offset=261722,lag=0
slave1:ip=192.168.1.100,port=16370,state=online,offset=261736,lag=0
master_failover_state:no-failover
master_replid:c6e88908dbe348999f5406625612e76ee4d6ffd1
master_replid2:b23a9a971ad73ed23fb81186529c671e54acbac4
master_repl_offset:261882
second_repl_offset:14231
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:261882# 此时干掉主库
redis-cli -h 192.168.1.200 -p 16371 -a dongdong shutdown
[root@redis_slave1 ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong shutdown
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# 再次查询
[root@redis_slave1 ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Could not connect to Redis at 192.168.1.200:16371: Connection refused# 此时查询集群个节点状态 看看哪个节点成功master 此时集群中只有两个节点 分别是redis_master主机 和 redis_slave2主机
# 先查看redis_master
redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.250
master_port:16372
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:56377
slave_repl_offset:56377
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:a375e44a67edd4fb81880032ef927964da6c376f
master_replid2:3288009c32135c1d1df6e8d56ceff7d45e572875
master_repl_offset:56377
second_repl_offset:55465
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:30454
repl_backlog_histlen:25924# 是正常的

5.3 恢复Redis 实例

# 查看各节点 redis 服务是否停用 如果停用 则重新启动
ps -ef | grep redis# redis_master
redis-server /usr/local/redis/conf/16370/redis_16370.conf# redis_slave1
redis-server /usr/local/redis/conf/16371/redis_16371.conf# redis_slave2
redis-server /usr/local/redis/conf/16372/redis_16372.conf

6. 手动停掉两个sentinel 实例

6.1 将redis_slave1 主机中的sentinel 实例停止

[root@redis_slave1 ~]# ps -ef | grep redis
root      39196      1  0 13:43 ?        00:00:02 redis-server 192.168.1.200:16371
root      39207  38840  0 13:45 pts/0    00:00:03 redis-sentinel 192.168.1.200:26370 [sentinel]
root      39220  38840  0 13:57 pts/0    00:00:00 grep --color=auto rediskill -9 39207root@redis_slave1 ~]# ps -ef | grep redis
root      39196      1  0 13:43 ?        00:00:02 redis-server 192.168.1.200:16371
root      39224  38840  0 13:59 pts/0    00:00:00 grep --color=auto redis

6.2 验证主从切换

# 查询redis_master主机集群状态
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:140766
slave_repl_offset:140766
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:a375e44a67edd4fb81880032ef927964da6c376f
master_replid2:3288009c32135c1d1df6e8d56ceff7d45e572875
master_repl_offset:140766
second_repl_offset:55465
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:30454
repl_backlog_histlen:110313# 查询redis_slvae1主机集群状态
[root@redis_slave1 ~]# redis-cli -h 192.168.1.200 -p 16371 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:master
connected_slaves:2
slave0:ip=192.168.1.100,port=16370,state=online,offset=143290,lag=0
slave1:ip=192.168.1.250,port=16372,state=online,offset=143290,lag=1
master_failover_state:no-failover
master_replid:a375e44a67edd4fb81880032ef927964da6c376f
master_replid2:3288009c32135c1d1df6e8d56ceff7d45e572875
master_repl_offset:143436
second_repl_offset:55465
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:15
repl_backlog_histlen:143422# 查询redis_slave2主机集群状态
[root@redis_slave2 conf]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication  
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:down
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_read_repl_offset:1
slave_repl_offset:1
master_link_down_since_seconds:-1
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:eb44c8dbaaf01ca3b091a4005ecb563cc467dc76
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0# 停掉redis_slvae1主机的redis 服务 看看是否可以进行主从切换
[root@redis_slave1 ~]# ps -ef | grep redis
root      39196      1  0 13:43 ?        00:00:03 redis-server 192.168.1.200:16371
root      39242  38840  0 14:03 pts/0    00:00:00 grep --color=auto rediskill -9 39196# 再次查看redis_master主机集群状态
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:down  # master 已经是 down 状态 说明没有进行主从切换
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_read_repl_offset:154925
slave_repl_offset:154925
master_link_down_since_seconds:49
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:a375e44a67edd4fb81880032ef927964da6c376f
master_replid2:3288009c32135c1d1df6e8d56ceff7d45e572875
master_repl_offset:154925
second_repl_offset:55465
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:30454
repl_backlog_histlen:124472# 再次查询redis_slvae2主机集群状态
[root@redis_slave2 conf]# redis-cli -h 192.168.1.250 -p 16372 -a dongdong  info replication  
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:down # master 已经是 down 状态 说明没有进行主从切换
master_last_io_seconds_ago:-1
master_sync_in_progress:0
slave_read_repl_offset:154925
slave_repl_offset:154925
master_link_down_since_seconds:133
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:a375e44a67edd4fb81880032ef927964da6c376f
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:154925
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:149549
repl_backlog_histlen:5377# 是因为我们再配置文件中指定了 sentinel monitor redis_master 192.168.1.100 16370 2  这个2 表示3个sentinel中最少有2个节点认为master库宕机时,才会真正意义上认为master库宕机。    # 把redis_slvae1主机的redis 服务恢复
redis-server /usr/local/redis/conf/16371/redis_16371.conf# 查看状态
[root@redis_master ~]# redis-cli -h 192.168.1.100 -p 16370 -a dongdong  info replication 
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
# Replication
role:slave
master_host:192.168.1.200
master_port:16371
master_link_status:up  # 恢复redis_slvae1主机的redis后 master服务up了
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_read_repl_offset:3474
slave_repl_offset:3474
slave_priority:100
slave_read_only:1
replica_announced:1
connected_slaves:0
master_failover_state:no-failover
master_replid:527f1bfc1c67513d0813d0c0fddb07964640d907
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:3474
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:476
repl_backlog_histlen:2999

相关文章:

Redis 哨兵搭建

Redis哨兵(sentinel)搭建 7.2.5 文章目录 一、单节点哨兵1. 环境介绍2. 环境前准备工作3. 安装 Redis 7.2.54. redis 配置修改并且启动4.1 修改配置文件4.2 编写启动脚本 5. 开启主从5.1 开启5.2 主库实例查看主从信息 6. 创建sentinel的配置文件并启动6.1 创建配置文件6.2 启…...

HackTheBox--Knife

Knife 测试过程 1 信息收集 端口扫描 80端口测试 echo "10.129.63.56 knife.htb" | sudo tee -a /etc/hosts网站是纯静态的&#xff0c;无任何交互功能&#xff0c;检查网页源代码也未发现任何可利用的文件。 检查页面请求时&#xff0c;请求与响应内容&#xff0…...

Linux_实现TCP网络通信

目录 1、实现服务器的逻辑 1.1 socket 1.2 bind 1.3 listen 1.4 accept 1.5 read 1.6 write 1.7 服务器代码 2、实现客户端的逻辑 2.1 connect 2.3 客户端代码 3、实现服务器与客户端的通信 结语 前言&#xff1a; 在Linux下&#xff0c;实现传输层协议为TCP…...

正则表达式与文本三剑客之grep

目录 前言 一、grep命令 二、基础正则表达式常见元字符 2.1、特殊字符 2.2、定位符 2.3、非打印字符 三、元字符操作实例 3.1、查找特定字符 3.2、利用中括号“[]”来查找集合字符 3.3、查找行首“^”与行尾字符“$” 3.4、查找任意一个字符“.”与重复字符“*” 3.…...

微信小程序开发:项目程序代码构成

✨✨ 欢迎大家来访Srlua的博文&#xff08;づ&#xffe3;3&#xffe3;&#xff09;づ╭❤&#xff5e;✨✨ &#x1f31f;&#x1f31f; 欢迎各位亲爱的读者&#xff0c;感谢你们抽出宝贵的时间来阅读我的文章。 我是Srlua小谢&#xff0c;在这里我会分享我的知识和经验。&am…...

【云原生】Kubernetes微服务Istio:介绍、原理、应用及实战案例

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…...

【Docker】Docker-consul容器服务自动发现与注册

目录 一.Consul概述 1.解决了什么问题 2.什么叫微服务或者注册与发现 3.consul的模式 4.相关命令 二.consul 部署 1.consul服务器部署 2.部署docker容器 3.Nginx负载均衡器 3.1.安装启动nginx 3.2.配置nginx负载均衡 3.3.创建配置consul complate模板文件 3.4.添加…...

Go 1.22 remote error: tls: handshake failure

Golang 1.22 remote error: tls: handshake failure 1.22之前运行下面代码是没有错误 package mainimport ("crypto/tls""fmt""net/http" )func main() {http.DefaultTransport.(*http.Transport).TLSClientConfig &tls.Config{InsecureS…...

迈向通用人工智能:AGI的到来与社会变革展望

正文&#xff1a; 随着科技的飞速发展&#xff0c;通用人工智能&#xff08;AGI&#xff09;的来临似乎已不再遥远。近期&#xff0c;多位行业领袖和专家纷纷预测&#xff0c;AGI的到来时间可能比我们想象的要早。在这篇博客中&#xff0c;我们将探讨AGI的发展趋势、潜在影响以…...

大模型额外篇章三:vercel搭建openai中转服务器

文章目录 一、起因和注意1)起因2)注意二、实现方法(原理:透传)1)nginx方案2)node服务3)纯 js 方案4)选择国外的域名服务商(DNS 解析路径缩短,建议方案国外提供 CDN 云服务商结合自建云服务业务做负载均衡)三、实践(vercel部署OpenAI代理服务器)四、测试搭建的Ope…...

使用 jQuery 中的 this 实例

在 jQuery 中&#xff0c;this 关键字用于表示指向当前操作的 DOM 元素。本篇博客将详细介绍如何在 jQuery 中使用 this 实例。 一、选择器中的 this 在选择器中&#xff0c;this 可以方便地指向当前操作的 DOM 元素。例如&#xff0c;当用户点击一个按钮时&#xff0c;我们想…...

下载最新版Anaconda、安装、更换源、配置虚拟环境并在vscode中使用

文章目录 进入官网进入下载页安装更换源配置虚拟环境env安装包requests在vscode中使用虚拟环境 进入官网 https://repo.anaconda.com/ 或进入清华大学下载 https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/ 进入下载页 安装 更换源 查看已经存在的镜像源 bash cond…...

极狐GitLab Git LFS(大文件存储)如何管理?

GitLab 是一个全球知名的一体化 DevOps 平台&#xff0c;很多人都通过私有化部署 GitLab 来进行源代码托管。极狐GitLab &#xff1a;https://gitlab.cn/install?channelcontent&utm_sourcecsdn 是 GitLab 在中国的发行版&#xff0c;专门为中国程序员服务。可以一键式部署…...

迭代学习笔记

一、迭代学习定义和分类 1、直观理解 迭代学习一般应用于重复性的场景。比如控制一个单自由度的小车以特定的速度曲线移动到指定位置&#xff0c;整个时间是10s&#xff0c;控制频率是0.01&#xff0c;那么整个控制序列就会有1000个点。这1000个点在10s内依次发出&#xff0c…...

【安全】系统安全设计规范(DOC完整版)

1.1安全建设原则 1.2 安全管理体系 1.3 安全管理规范 1.4 数据安全保障措施 1.4.1 数据库安全保障 1.4.2 操作系统安全保障 1.4.3 病毒防治 1.5安全保障措施 1.5.1实名认证保障 1.5.2 接口安全保障 1.5.3 加密传输保障 1.5.4终端安全保障 软件资料清单列表部分文档&…...

windows常用命令整理

本文分享一些常用的windows命令。根据功能的不同&#xff0c;大致可分为以下几个方面&#xff0c;一是文件操作命令&#xff0c;二是进程相关命令&#xff0c;三是磁盘相关命令&#xff0c;四是网络相关命令&#xff0c;五是其他命令。 1.文件操作命令 dir&#xff1a;显示当…...

视频处理基础知识1

1、图像基本知识 图像的组成&#xff1a;像素、RGB(每个像素由三个发光二极管组成)、分辨率&#xff08;横纵向像素的个数乘积&#xff09; PPI每英寸的像素数 DPI每英寸的点数&#xff0c;有可能一个点有多个像素 PPI>300 就属于视网膜级别&#xff0c;就是很清晰&#…...

Linux退不出vim编辑模式

目录 第一章、问题分析1.1&#xff09;报错提示 第二章、解决方式 友情提醒&#xff1a; 先看文章目录&#xff0c;大致了解文章知识点结构&#xff0c;点击文章目录可直接跳转到文章指定位置。 第一章、问题分析 1.1&#xff09;报错提示 报错如下&#xff1a;使用Linux的vi…...

TikTok养号的网络环境及相关代理IP知识

TikTok作为一个流行的短视频分享平台&#xff0c;其用户量非常庞大&#xff0c;很多商家和个人都会使用TikTok来进行引流和推广。由于TikTok的规则和政策限制了每个用户每天发布视频的数量&#xff0c;因此许多用户会使用多个账号来发布更多的视频以提高曝光率。 然而&#xff…...

过程调用和数组的分配访问

系列文章 : 深入理解计算机系统笔记 文章目录 系列文章3.7 过程3.7.1 运行时栈3.7.2 转移控制3.7.3 数据传送3.7.4 栈上的局部存储3.7.5 寄存器中的局部存储空间3.7.6 递归过程 3.8 数组分配和访问3.8.1 基本原则3.8.2 指针运算3.8.3 嵌套的数组3.8.4 定长数组3.8.5 变长数组…...

TeamViewer手机端APP提示:请先验证账户

当你在手机端下载安装了TeamViewerAPP后&#xff0c;需要你先登录个人账号&#xff0c;然后还会要求你验证账户&#xff0c;同时跳转到一个网址中&#xff0c;但是这个网址并没有自动跳转到验证账户的位置。 解决办法&#xff1a; 在手机浏览器中进入下面这个网址&#xff1a;…...

【SpringBoot】分页查询

1. Controller ApiOperation("分页查询")GetMapping("/page")public Result<PageResult> pageResultResult(EmployeePageQueryDTO employeePageQueryDTO) {System.out.println(employeePageQueryDTO.toString());PageResult pageResult employeeSer…...

微软CrowdStrike驱动蓝屏以及内核签名

原因 当Windows操作系统遇到严重错误导致系统崩溃时&#xff0c;屏幕显示为蓝色&#xff0c;通常伴有错误代码和信息&#xff0c;这被称为“蓝屏死机”&#xff08;Blue Screen of Death&#xff0c;简称BSOD&#xff09; https://www.thepaper.cn/newsDetail_forward_281262…...

Spring中Bean的循环依赖

目录 定义&#xff1a; 循环依赖的后果&#xff1a; 一&#xff1a;三级缓存 1、大概的思路&#xff1a; 注意&#xff1a; 2、执行过程&#xff1a; A半完成&#xff1a; B完成&#xff1a; A完成&#xff1a; 注&#xff1a; 二&#xff1a;Lazy 定义&#xff1a; …...

Java二十三种设计模式-代理模式模式(8/23)

代理模式&#xff1a;为对象访问提供灵活的控制 引言 代理模式&#xff08;Proxy Pattern&#xff09;是一种结构型设计模式&#xff0c;它为其他对象提供一个代替或占位符&#xff0c;以控制对它的访问。 基础知识&#xff0c;java设计模式总体来说设计模式分为三大类&#…...

Windows 11 家庭中文版 安装 VMWare 报 安装程序检测到主机启用了Hyper-V或Device

1、问题 我的操作系统信息如下&#xff1a; 我在安装 VMWare 的时候&#xff0c;报&#xff1a; 因为我之前安装了 docker 桌面版&#xff0c;所以才报这个提示。 安装程序检测到主机启用了 Hyper-v或 Device/credential Guard。要在启用了Hyper-或 Device/Credential Guard …...

机械学习—零基础学习日志(高数09——函数图形)

零基础为了学人工智能&#xff0c;真的开始复习高数 函数图像&#xff0c;开始新的学习&#xff01; 幂函数 利用函数的性质&#xff0c;以幂函数为例&#xff0c;因为单调性相同&#xff0c;利用图中的2和3公式&#xff0c;求最值问题&#xff0c;可以直接将式子进行简化。这…...

java迭代集合出现并发修改异常(ConcurrentModificationException)的原因以及解决方案

java迭代集合出现并发修改异常(ConcurrentModificationException)的原因以及解决方案 一. 什么时候会出现并发修改异常? 这里先看需求 : 定义一个集合,存储 唐僧,孙悟空,猪八戒,沙僧,遍历集合,如果遍历到猪八戒,往集合中添加一个白龙马 很显然要求我们先创建一个集合并进行…...

BGP选路之Local Preference

原理概述 当一台BGP路由器中存在多条去往同一目标网络的BGP路由时&#xff0c;BGP协议会对这些BGP路由的属性进行比较&#xff0c;以确定去往该目标网络的最优BGP路由。BGP首先比较的是路由信息的首选值&#xff08;PrefVal)&#xff0c;如果 PrefVal相同&#xff0c;就会比较本…...

WEB渗透信息收集篇--IP和端口信息

WEB渗透信息收集篇--域名信息-CSDN博客 WEB渗透信息收集篇--网站架构和指纹识别-CSDN博客 ​​​​​​​​​​​​​​WEB渗透信息收集篇--人员信息-CSDN博客​​​​​​​ WEB渗透信息收集篇--其他信息-CSDN博客 一、ASN ASN Tool - MxToolBox ASN通常指的是"自…...