运维实战 Redis安装部署与高可用主从切换

Posted 洛冰音

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运维实战 Redis安装部署与高可用主从切换相关的知识,希望对你有一定的参考价值。

运维实战 Redis安装部署与高可用主从切换

Redis安装及主从配置

Server1操作

##编译安装Redis
make USE_SYSTEMD=yes
make install

##从源码包中复制systemd需要的文件并修改
cp /mnt/redis-6.2.1/Utils/systemd-redis_server.service /usr/lib/systemd/system/redis.service
vim /usr/lib/systemd/system/redis.service

##修改区域的内容如下
[Unit]
Description=Redis data structure server
Documentation=https://redis.io/documentation
#Before=your_application.service another_example_application.service
AssertPathExists=/var/lib/redis
Wants=network-online.target
After=network-online.target

[Service]
#ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize no
## Alternatively, have redis-server load a configuration file:
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/bin/redis-cli -p 6379 shutdown
LimitNOFILE=10032
NoNewPrivileges=yes
#OOMScoreAdjust=-900
PrivateTmp=yes
Type=notify
#TimeoutStartSec=infinity
#TimeoutStopSec=infinity
UMask=0077
#User=redis
#Group=redis
WorkingDirectory=/var/lib/redis

[Install]
WantedBy=multi-user.target

##复制主配置文件并修改
mkdir /etc/redis
cp /mnt/redis-6.2.1/redis.conf /etc/redis/

##主配置文件需要修改的部分
bind 0.0.0.0				允许本机所有端口连接
protected-mode yes			开启保护模式
port 6379					默认端口6379
tcp-backlog 511
timeout 0					超时时间
tcp-keepalive 300
daemonize yes				守护进程运行
supervised auto				运行模式自动判断

##创建需要的目录
mkdir /var/lib/redis

##刷新systemd并启动
systemctl  daemon-reload 
systemctl start redis.service

##启动后可以通过redis-cli测试安装情况
redis-cli
127.0.0.1:6379> set name NeuWings
OK

##复制编译和更改后的文件到Server2便于做主从模式
yum install rsync -y
ssh Server4 yum install rsync -y
cd /usr/local/bin
rsync -a * Server4:/usr/local/bin
ssh Server4 mkdir /etc/redis
ssh Server4 mkdir /var/lib/redis
scp /etc/redis/rsdis.conf Server4:/etc/redis/

Server4操作

##编辑从Server1接收的主配置文件
vim /etc/redis/redis.conf
##增加从机设置
replicaof 172.25.5.1 6379

##启动后可以通过redis-cli测试安装情况
redis-cli
127.0.0.1:6379> get name
"NeuWings"

高可用配置

这里采用哨兵模式(Sentinel)来操作.

首先新开启一台机器并进行从机配置, 这样就拥有了3台机器了.

当其中两台认为主机下线了时, 主机被认为是下线了.

也就是俗称的投票机制.

从源码包复制sentinel.conf放入/etc/redis/并修改

[root@Server1 redis-6.2.1]# cp sentinel.conf /etc/redis/

[root@Server1 redis]# vim sentinel.conf 

sentinel monitor mymaster 172.25.5.1 6379 2
sentinel down-after-milliseconds mymaster 10000

[root@Server1 redis]# scp sentinel.conf Server2:/etc/redis/
[root@Server1 redis]# scp sentinel.conf Server3:/etc/redis/
[root@Server1 redis]# redis-sentinel /etc/redis/sentinel.conf
[root@Server2 redis]# redis-sentinel /etc/redis/sentinel.conf
[root@Server3 redis]# redis-sentinel /etc/redis/sentinel.conf
##启动后应当出现类似的滚动日志
28695:X 14 Apr 2021 14:17:54.083 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
28695:X 14 Apr 2021 14:17:54.083 # Redis version=6.2.1, bits=64, commit=00000000, modified=0, pid=28695, just started
28695:X 14 Apr 2021 14:17:54.083 # Configuration loaded
28695:X 14 Apr 2021 14:17:54.084 * Increased maximum number of open files to 10032 (it was originally set to 1024).
28695:X 14 Apr 2021 14:17:54.084 * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 6.2.1 (00000000/0) 64 bit
  .-`` .-```.  ```\\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in sentinel mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 26379
 |    `-._   `._    /     _.-'    |     PID: 28695
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

28695:X 14 Apr 2021 14:17:54.084 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
28695:X 14 Apr 2021 14:17:54.088 # Sentinel ID is df0295911b7cfb1f36e34951cbf8c7d72e04004f
28695:X 14 Apr 2021 14:17:54.088 # +monitor master mymaster 172.25.5.1 6379 quorum 2
28695:X 14 Apr 2021 14:17:54.089 * +slave slave 172.25.5.2:6379 172.25.5.2 6379 @ mymaster 172.25.5.1 6379
28695:X 14 Apr 2021 14:17:54.094 * +slave slave 172.25.5.3:6379 172.25.5.3 6379 @ mymaster 172.25.5.1 6379
28695:X 14 Apr 2021 14:18:04.100 * +sentinel sentinel d94921d3235086018f038404990c567e5a8d6dc3 172.25.5.2 26379 @ mymaster 172.25.5.1 6379
28695:X 14 Apr 2021 14:18:10.782 * +sentinel sentinel ff9ab199b9e8fb2f0ae33b60b1c96815ccb2b96d 172.25.5.3 26379 @ mymaster 172.25.5.1 6379

在最后两行可以看到两台从机加入了Sentibel管理中

如果手动down掉Server1redis

21733:X 14 Apr 2021 14:18:01.909 * +sentinel sentinel df0295911b7cfb1f36e34951cbf8c7d72e04004f 172.25.5.1 26379 @ mymaster 172.25.5.1 6379
21733:X 14 Apr 2021 14:18:10.382 * +sentinel sentinel ff9ab199b9e8fb2f0ae33b60b1c96815ccb2b96d 172.25.5.3 26379 @ mymaster 172.25.5.1 6379
21733:X 14 Apr 2021 14:21:49.140 # +sdown master mymaster 172.25.5.1 6379
21733:X 14 Apr 2021 14:21:49.216 # +new-epoch 1
21733:X 14 Apr 2021 14:21:49.221 # +vote-for-leader df0295911b7cfb1f36e34951cbf8c7d72e04004f 1
21733:X 14 Apr 2021 14:21:49.486 # +config-update-from sentinel df0295911b7cfb1f36e34951cbf8c7d72e04004f 172.25.5.1 26379 @ mymaster 172.25.5.1 6379
21733:X 14 Apr 2021 14:21:49.486 # +switch-master mymaster 172.25.5.1 6379 172.25.5.2 6379
21733:X 14 Apr 2021 14:21:49.486 * +slave slave 172.25.5.3:6379 172.25.5.3 6379 @ mymaster 172.25.5.2 6379
21733:X 14 Apr 2021 14:21:49.486 * +slave slave 172.25.5.1:6379 172.25.5.1 6379 @ mymaster 172.25.5.2 6379

可以看到投票选举了Server2作为新的MASTER并修改了状态使得Server1Server3成为了其Slave

经过一段时间的等待(10s)后

21733:X 14 Apr 2021 14:22:19.522 # +sdown slave 172.25.5.1:6379 172.25.5.1 6379 @ mymaster 172.25.5.2 6379

判定Server1客观下线

如果此时开启Server1redis则会看到

28695:X 14 Apr 2021 14:23:24.238 # -sdown slave 172.25.5.1:6379 172.25.5.1 6379 @ mymaster 172.25.5.2 6379

Server1从下线状态恢复, 重新作为SLAVE连接在了Server2

查看Server1redis.conf

# ignore-warnings ARM64-COW-BUG
# Generated by CONFIG REWRITE
save 3600 1
save 300 100
save 60 10000
user default on nopass ~* &* +@all
replicaof 172.25.5.2 6379

# Replication
role:slave
master_host:172.25.5.2
master_port:6379

多出了如上内容, 即持久化保存和从机配置相关内容.

操作流程与配置示例(冗长)

安装中的信息查询

127.0.0.1:6379> info
# Server
redis_version:6.2.1
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:4d15dca8c18db182
redis_mode:standalone
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:20858
process_supervised:systemd
run_id:5f50b4628f61c519a837bd5822ded838ffa72499
tcp_port:6379
server_time_usec:1618372093854810
uptime_in_seconds:8
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:7759357
executable:/usr/local/bin/redis-server
config_file:/etc/redis/redis.conf
io_threads_active:0

# Clients
connected_clients:1
cluster_connections:0
maxclients:10000
client_recent_max_input_buffer:16
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0

# Memory
used_memory:873600
used_memory_human:853.12K
used_memory_rss:10973184
used_memory_rss_human:10.46M
used_memory_peak:933616
used_memory_peak_human:911.73K
used_memory_peak_perc:93.57%
used_memory_overhead:830368
used_memory_startup:809872
used_memory_dataset:43232
used_memory_dataset_perc:67.84%
allocator_allocated:1030376
allocator_active:1355776
allocator_resident:4038656
total_system_memory:1039097856
total_system_memory_human:990.96M
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.32
allocator_frag_bytes:325400
allocator_rss_ratio:2.98
allocator_rss_bytes:2682880
rss_overhead_ratio:2.72
rss_overhead_bytes:6934528
mem_fragmentation_ratio:13.21
mem_fragmentation_bytes:10142352
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:20496
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
lazyfreed_objects:0

# Persistence
loading:0
current_cow_size:0
current_fork_perc:0.00%
current_save_keys_processed:0
current_save_keys_total:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1618372085
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0

# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:31
total_net_output_bytes:20384
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
total_forks:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_error_replies:0
dump_payload_sanitizations:0
total_reads_processed:2
total_writes_processed:1
io_threaded_reads_processed:0
io_threaded_writes_processed:0

# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:1445dec6e9203ff7d13eba80ffb0d67916d27b37
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

# CPU
used_cpu_sys:0.021478
used_cpu_user:0.029660
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
used_cpu_sys_main_thread:0.021382
used_cpu_user_main_thread:0.029527

# Modules

# Errorstats

# Cluster
cluster_enabled:0

# Keyspace

从机上则会有这部分信息与上文不同

# Replication
role:slave
master_host:172.25.5.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:2
master_sync_in_progress:0
slave_repl_offset:28
slave_priority:100
slave_read_only:1
connected_slaves:0

哨兵模式配置文件

# 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
# unmounting filesystems.
dir "/tmp"

# sentinel monitor <master-name> <ip> <redis-port> <quorum>
#
# Tells Sentinel to monitor this master, and to consider it in O_DOWN
# (Objectively Down) state only if at least <quorum> sentinels agree.
#
# Note that whatever is the ODOWN quorum, a Sentinel will require to
# be elected by the majority of the known Sentinels in order to
# start a failover, so no failover can be performed in minority.
#
# Replicas are auto-discovered, so you don't need to specify replicas in
# any way. Sentinel itself will rewrite this configuration file adding
# the replicas using additional configuration options.
# Also note that the configuration file is rewritten when a
# replica is promoted to master.
#
# Note: master name should not include special characters or spaces.
# The valid charset is A-z 0-9 and the three characters ".-_".
sentinel monitor mymaster 172.25.5.1 6379 2

# sentinel auth-pass <master-name> <password>
#
# Set the password to use to authenticate with the master and replicas.
# Useful if there is a password set in the Redis instances to monitor.
#
# Note that the master password is also used for replicas, so it is not
# possible to set a different password in masters and replicas instances
# if you want to be able to monitor these instances with Sentinel.
#
# However you can have Redis instances without the authentication enabled
# mixed with Redis instances requiring the authentication (as long as the
# password set is the same for all the instances requiring the password) as
# the AUTH command will have no effect in Redis instances with authentication
# switched off.
#
# Example:
#
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd

# sentinel auth-user <master-name> <username>
#
# This is useful in order to authenticate to instances having ACL capabilities,
# that is, running Redis 6.0 or greater. When just auth-pass is provided the
# Sentinel instance will authenticate to Redis using the old "AUTH <pass>"
# method. When also an username is provided, it will use "AUTH <user> <pass>".
# In the Redis servers side, the ACL to provide just minimal access to
# Sentinel instances, should be configured along the following lines:
#
#     user sentinel-user >somepassword +client +subscribe +publish \\
#                        +ping +info +multi +slaveof +config +client +exec on

# sentinel down-after-milliseconds <master-name> <milliseconds>
#
# Number of milliseconds the master (or any attached replica or sentinel) should
# be unreachable (as in, not acceptable reply to PING, continuously, for the
# specified period) in order to consider it in S_DOWN state (Subjectively
# Down).
#
# Default is 30 seconds.

# IMPORTANT NOTE: starting with Redis 6.2 ACL capability is supported for
# Sentinel mode, please refer to the Redis website https://redis.io/topics/acl
# for more details.

# Sentinel's ACL users are defined in the following format:
#
#   user <username> ... acl rules ...
#
# For example:
#
#   user worker +@admin +@connection ~* on >ffa9203c493aa99
#
# For more information about ACL configuration please refer to the Redis
# website at https://redis.io/topics/acl and redis server configuration
# template redis.conf.

# ACL LOG
#
# The ACL Log tracks failed commands and authentication events associated
# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
# by ACLs. The ACL Log is stored in memory. You can reclaim memory with
# ACL LOG RESET. Define the maximum entry length of the ACL Log below.
acllog-max-len 128

# Using an external ACL file
#
# Instead of configuring users here in this file, it is possible to use
# a stand-alone file just listing users. The two methods cannot be mixed:
# if you configure users here and at the same time you activate the external
# ACL file, the server will refuse to start.
#
# The format of the external ACL user file is exactly the same as the
# format that is used inside redis.conf to describe users.
#
# aclfile /etc/redis/sentinel-users.acl

# requirepass <password>
#
# You can configure Sentinel itself to require a password, however when doing
# so Sentinel will try to authenticate with the same password to all the
# other Sentinels. So you need to configure all your Sentinels in a given
# group with the same "requirepass" password. Check the following documentation
# for more info: https://redis.io/topics/sentinel
#
# IMPORTANT NOTE: starting with Redis 6.2 "requirepass" is a compatibility
# layer on top of the ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# New config files are advised to use separate authentication control for
# incoming connections (via ACL), and for outgoing connections (via
# sentinel-user and sentinel-pass)
#
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.

# sentinel sentinel-user <username>
#
# You can configure Sentinel to authenticate with other Sentinels with specific
# user name.

# sentinel sentinel-pass <password>
#
# The password for Sentinel to authenticate with other Sentinels. If sentinel-user
# is not configured, Sentinel will use 'default' user with sentinel-pass to authenticate.

# sentinel parallel-syncs <master-name> <numreplicas>
#
# How many replicas we can reconfigure to point to the new replica simultaneously
# during the failover. Use a low number if you use the replicas to serve query
# to avoid that all the replicas will be unreachable at about the same
# time while performing the synchronization with the master.

# sentinel failover-timeout <master-name> <milliseconds>
#
# Specifies the failover timeout in milliseconds. It is used in many ways:
#
# - The time needed to re-start a failover after a previous failover was
#   already tried against the same master by a given Sentinel, is two
#   times the failover timeout.
#
# - The time needed for a replica replicating to a wrong master according
#   to a Sentinel current configuration, to be forced to replicate
#   with the right master, is exactly the failover timeout (counting since
#   the moment a Sentinel detected the misconfiguration).
#
# - The time needed to cancel a failover that is already in progress but
#   did not produced any configuration change (SLAVEOF NO ONE yet not
#   acknowledged by the promoted replica).
#
# - The maximum time a failover in progress waits for all the replicas to be
#   reconfigured as replicas of the new master. However even after this time
#   the replicas will be reconfigured by the Sentinels anyway, but not with
#   the exact parallel-syncs progression as specified.
#
# Default is 3 minutes.

# SCRIPTS EXECUTION
#
# sentinel notification-script and sentinel reconfig-script are used in order
# to configure scripts that are called to notify the system administrator
# or to reconfigure clients after a failover. The scripts are executed
# with the following rules for error handling:
#
# If script exits with "1" the execution is retried later (up to a maximum
# number of times currently set to 10).
#
# If script exits with "2" (or an higher value) the script execution is
# not retried.
#
# If script terminates because it receives a signal the behavior is the same
# as exit code 1.
#
# A script has a maximum running time of 60 seconds. After this limit is
# reached the script is terminated with a SIGKILL and the execution retried.

# NOTIFICATION SCRIPT
#
# sentinel notification-script <master-name> <script-path>
#
# Call the specified notification script for any sentinel event that is
# generated in the WARNING level (for instance -sdown, -odown, and so forth).
# This script should notify the system administrator via email, SMS, or any
# other messaging system, that there is something wrong with the monitored
# Redis systems.
#
# The script is called with just two arguments: the first is the event type
# and the second the event description.
#
# The script must exist and be executable in order for sentinel to start if
# this option is provided.
#
# Example:
#
# sentinel notification-script mymaster /var/redis/notify.sh

# CLIENTS RECONFIGURATION SCRIPT
#
# sentinel client-reconfig-script <master-name> <script-path>
#
# When the master changed because of a failover a script can be called in
# order to perform application-specific tasks to notify the clients that the
# configuration has changed and the master is at a different address.
#
# The following arguments are passed to the script:
#
# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
#
# <state> is currently always "failover"
# <role> is either "leader" or "observer"
#
# The arguments from-ip, from-port, to-ip, to-port are used to communicate
# the old address of the master and the new address of the elected replica
# (now a master).
#
# This script should be resistant to multiple invocations.
#
# Example:
#
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh

# SECURITY
#
# By default SENTINEL SET will not be able to change the notification-script
# and client-reconfig-script at runtime. This avoids a trivial security issue
# where clients can set the script to anything and trigger a failover in order
# to get the program executed.

sentinel deny-scripts-reconfig yes

# REDIS COMMANDS RENAMING
#
# Sometimes the Redis server has certain commands, that are needed for Sentinel
# to work correctly, renamed to unguessable strings. This is often the case
# of CONFIG and SLAVEOF in the context of providers that provide Redis as
# a service, and don't want the customers to reconfigure the instances outside
# of the administration console.
#
# In such case it is possible to tell Sentinel to use different command names
# instead of the normal ones. For example if the master "mymaster", and the
# associated replicas, have "CONFIG" all renamed to "GUESSME", I could use:
#
# SENTINEL rename-command mymaster CONFIG GUESSME
#
# After such configuration is set, every time Sentinel would use CONFIG it will
# use GUESSME instead. Note that there is no actual need to respect the command
# case, so writing "config guessme" is the same in the example above.
#
# SENTINEL SET can also be used in order to perform this configuration at runtime.
#
# In order to set a command back to its original name (undo the renaming), it
# is possible to just rename a command to itself:
#
# SENTINEL rename-command mymaster CONFIG CONFIG

# HOSTNAMES SUPPORT
#
# Normally Sentinel uses only IP addresses and requires SENTINEL MONITOR
# to specify an IP address. Also, it requires the Redis replica-announce-ip
# keyword to specify only IP addresses.
#
# You may enable hostnames support by enabling resolve-hostnames. Note
# that you must make sure your DNS is configured properly and that DNS
# resolution does not introduce very long delays.
#
sentinel resolve-hostnames no

# When resolve-hostnames is enabled, Sentinel still uses IP addresses
# when exposing instances to users, configuration files, etc. If you want
# to retain the hostnames when announced, enable announce-hostnames below.
#
sentinel announce-hostnames no
# Generated by CONFIG REWRITE
protected-mode no
user default on nopass ~* &* +@all
sentinel myid df0295911b7cfb1f36e34951cbf8c7d72e04004f
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
sentinel known-replica mymaster 172.25.5.3 6379
sentinel known-replica mymaster 172.25.5.2 6379
sentinel known-sentinel mymaster 172.25.5.2 26379 d94921d3235086018f038404990c567e5a8d6dc3
sentinel known-sentinel mymaster 172.25.5.3 26379 ff9ab199b9e8fb2f0ae33b60b1c96815ccb2b96d

以上是关于运维实战 Redis安装部署与高可用主从切换的主要内容,如果未能解决你的问题,请参考以下文章

运维实战 Mysql高可用与健康检查

redis主从复制与高可用

Linux运维数据库篇 redis三种高可用方式部署

Redis主从复制与高可用方案

Redis 开发与运维Redis Sentinel 哨兵

Redis 开发与运维Redis Sentinel 哨兵