Redis master-slave replication configuration modification

To enable master-slave replication in Redis, some changes need to be made in the Redis configuration file. Here are the steps to configure master-slave replication:

  1. Open the redis.conf configuration file of the Redis master server, find the bind and port configuration items, and ensure that the IP address and port number bound to Redis are correct:
bind 127.0.0.1 # 这里改成服务器的 IP 地址或者绑定的外网地址
port 6379 # 这里保持默认的 Redis 端口号
  1. Name the Redis master server, set the name of the Redis instance to mymaster, and add the following configuration items to the Redis configuration file:
# 设置Redis实例的名称
replicaof no one
masterauth your_master_password # 如果需要密码验证,可以设置这个参数
slave-announce-ip 192.168.x.x # 这里填写 Redis 主服务器的IP地址
slave-announce-port 6379 # 这里填写 Redis 主服务器的端口号
  1. Open the Redis slave server redis.conf configuration file, find the bind and port configuration items, and ensure that the IP address and port number bound to Redis are correct:
bind 127.0.0.1 # 这里改成从服务器的 IP 地址或者绑定的外网地址
port 6380 # 这里可以选择不同于主服务器的 Redis 端口号
  1. Enable the master-slave replication function of the Redis slave server, let the Redis slave server know the address of the master server, and add the following configuration items in the Redis configuration file:
replicaof 主服务器的 IP 地址 6379 # 这里填写 Redis 主服务器的IP地址和端口号
masterauth your_master_password # 如果需要密码验证,可以设置这个参数
  1. Save the changes and restart the Redis service.

Successful configuration information

master
insert image description here
slave
insert image description here

Master-slave replication - effect display

insert image description here
insert image description here

The above are the steps to configure master-slave replication in Redis. Please note that in a production environment, you should adjust the configuration parameters according to the actual situation to ensure data security and high availability.

Guess you like

Origin blog.csdn.net/java_cpp_/article/details/130768629
Recommended