centeros7 builds redis cluster (master-slave mode)

The cluster construction is a Master (one-time big brother, lifelong big brother) and two slaves.

1. First, copy three copies of the redis.conf configuration file in the bin folder of the redis installation directory, and name them as shown in the following figure.
insert image description here
Check the added configuration file:
insert image description here

2. Modify each configuration file
① Modify the redis-master.conf master node configuration file:

修改:
# 绑定本机ip地址
# bind 127.0.0.1 -::1
bind  192.168.184.128
#设置端口号
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
Port  6380
# By default Redis does not run as a daemon. Use 'yes' if you need it.
daemonize yes
# The filename where to dump the DB
dbfilename dump6380.rdb  或者修改dir
# master自己的密码(没有密码可忽略)
requirepass 123456

② Modify the redis-slaver1.conf master node configuration file:

bind  192.168.184.128
Port  6381
daemonize yes
dbfilename dump6381.rdb  或者修改dir
#设置节点从属于master主节点
Replicaof  192.168.31.193  6380 
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the replica to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the replica request.
# 如果redis的master设置了密码,需要添加下列认证
# masterauth <master-password>
masterauth  123456
# slaver1自己的密码(没有密码可忽略)
requirepass 123456

③ Modify the redis-slaver2.conf master node configuration file:

修改:
bind  192.168.184.128
Port  6382
daemonize yes
dbfilename dump6383.rdb  或者修改dir
Replicaof  192.168.31.193  6380
# If the master is password protected (using the "requirepass" configuration
# directive below) it is possible to tell the replica to authenticate before
# starting the replication synchronization process, otherwise the master will
# refuse the replica request.
# 如果redis的master设置了密码,需要添加下列认证
# masterauth <master-password> 
masterauth  123456
# slaver2自己的密码(没有密码可忽略)
requirepass 123456

3. Test cluster

Master can read and write, slave can only read.
Master write operations will be synchronized to the slave.
Disadvantages: The master is down, the slave will not be elected as the master, and the slave is still read-only.

①Start the services of the master node master and slave nodes slave1 and slave2 in the background, and check the startup results.
insert image description here
②Master node test
insert image description here
③Slave node slave1 test, can only read the data of the master node master, and cannot add data by itself.
insert image description here
④ The slave node slave2 test can only read the data of the master node master, and cannot add data by itself.
insert image description here
⑤ Test that the master node master is down, and directly kill the process of the master node master.
insert image description here
The slave nodes slave1 and slave2 can only read the master master node data, will not re-elect a new master, and cannot add data.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_43605266/article/details/114686065