Get the App
SLTechnology News&Howtos  ›  Database  › 

Redis-Master-Slave configuration

Shulou Source: shulou.com Published: 2022-06-01 11:06:03 09月17日 Update

The role of the cluster:

1. Master-slave backup prevents master library from downloading

2. Separate reading and writing to share master pressure.

3. Task separation, such as sharing backup work from the server

Probably the principle of synchronization:

1Jing started and found that master needs to be connected, so sync automatically synchronizes it.

2Mastermaster dump sends a rdb file to slave

3Jing master newly generated data, by buffering aof files

4, and then keep in touch through the replicationfeedsalves process

Master configuration:

1. Close the rdb snapshot and give the backup to slave

2. Enable aof

Slave configuration:

1, declare slave-of

2. Configure password-- if master has a password

3. A certain slave opens the rdb snapshot function

4. Configure whether to read-only slave-read-only

Configure the slave server:

1, copy the relevant configuration files in the main library

[root@ZFRC-YW-YJF-TEST-370123 redis] # cp redis.conf redis6380.conf

[root@ZFRC-YW-YJF-TEST-370123 redis] # cp redis.conf redis6381.conf

2, configure from the server configuration file 6380, modify the following

Port 6380

Pidfile / var/run/redis_6380.pid

Dbfilename dump6380.rdb

Slaveof localhost 6379

Slave-read-only yes

Configure the configuration from the server profile 6381, modify it as follows

Port 6381

Pidfile / var/run/redis_6381.pid

Note rdb generation conditions

# save 900 1

# save 300 10

# save 60 3000

Turn off the aof function of the second slave node

Appendonly no

Slaveof localhost 6379

3. View the rdb file and aof file in the environment. Delete cleanly

[root@ZFRC-YW-YJF-TEST-370123 dir] # rm *

Rm: remove regular empty file 'laoyang-appendonly.aof'? Y

4, primary master node configuration

Cancel rdb

# save 900 1

# save 300 10

# save 60 3000

Aof file closed

Appendonly no

5. Start the master-slave cluster

[root@ZFRC-YW-YJF-TEST-370123 redis] #. / bin/redis-server. / redis.conf

[root@ZFRC-YW-YJF-TEST-370123 redis] #. / bin/redis-server. / redis6380.conf

[root@ZFRC-YW-YJF-TEST-370123 redis] #. / bin/redis-server. / redis6381.conf

6, verification, main server 6379 inserts data, 6380 checks

[root@ZFRC-YW-YJF-TEST-370123 redis] #. / bin/redis-cli

127.0.0.1 6379 > keys *

(empty list or set)

127.0.0.1 purl 6379 > set zhucong ok

OK

127.0.0.1 purl 6379 > exit

[root@ZFRC-YW-YJF-TEST-370123 redis] #. / bin/redis-cli-p 6380

127.0.0.1 6380 > get zhucong

"ok"

[root@ZFRC-YW-YJF-TEST-370123 redis] #. / bin/redis-cli-p 6381

127.0.0.1purl 6381 > get zhucong

"ok"

Summary:

Disadvantages: every time the slave is disconnected, whether it is active disconnection or network failure. When connecting to master, you have to master all dump out of rdb, and then aof. The synchronization process has to be done all over again, so keep in mind that multiple slave should not be started all at once, or the master may IO soar.

Tags: Configuration file server service backup synchronization master-slave function place password snapshot data node cluster clean active task function pressure principle Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Microsoft OPPO Reno MariaDB Shulou Tech Info