Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Redis master-slave replication structure mode, Sentinel mode

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Set temporary effect

1. Configure Slave Library

192.168.4.58:6058> info replication //View master-slave configuration information

# Replication

role:master

connected_slaves:0

master_replid:784d7d32d7f522703ca763c6a1a4bb0f8c1db591

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

Command line specifies master library: SLAVEOF master library IP address Port number

2. One master and one slave

192.168.4.57:6057> 192.168.4.50 6050 #Slave library configuring 57 to 50

OK

192.168.4.57:6057> INFO replication

# Replication

role:slave

master_host:192.168.4.50

master_port:6050

master_link_status:up

master_last_io_seconds_ago:8

master_sync_in_progress:0

slave_repl_offset:56

client test

[root@51 ~]# redis-cli -c -h 192.168.4.50 -p 6050

192.168.4.50:6050> set name bob

OK

Master:

192.168.4.50:6050> keys *

1)"name"

2)192.168.4.57:6057> keys *

3)1) "name"

3. One master with multiple slaves (add 58 to the above)

192.168.4.58:6058> SLAVEOF 192.168.4.50 6050

OK

192.168.4.58:6058> info replication

# Replication

role:slave

master_host:192.168.4.50

...............

192.168.4.58:6058> keys *

1) "age"

2) "name"

4. Master slave (58 configured to become slave library of 57)

Just when we set 58 to 50 from the library, we need redis from Kai 58

[root@58 ~]# redis-cli -h 192.168.4.58 -p 6058 shutdown

[root@58 ~]# redis_6379 start

[root@58 ~]# redis-cli -h 192.168.4.58 -p 6058

192.168.4.58:6058> info replication

# Replication

role:master

connected_slaves:0

............

192.168.4.58:6058> SLAVEOF 192.168.4.57 6057

OK

192.168.4.58:6058> info replication

# Replication

role:slave

master_host:192.168.4.57

master_port:6057

Testing:

192.168.4.50(Master Library Slave Library 57)

192.168.4.50:6050> keys *

1) "age"

2) "name"

192.168.4.50:6050> set sex gral

OK

192.168.4.57(It is the slave library of 50 and the master library of 58)

192.168.4.57:6057> keys *

1) "sex"

2) "name"

3) "age"

192.168.4.58(57 from Library)

192.168.4.58:6058> keys *

1) "age"

2) "name"

3) "sex"

Reverse guest master-manually set slave to master after master outage

192.168.4.50 After downtime, manually set 57 as the master library

192.168.4.57:6057> SLAVEOF no one //Set as main library

OK

The above settings are temporary, restart invalid

Configure permanent master-slave synchronization with authentication (synchronization authentication requires entering the master library password)

1. set a password

[root@50 ~]# vim /etc/redis/6379.conf

501 requirepass 123456

8 REDISPORT="6050"

43 $CLIEXEC -h 192.168.4.50 -p $REDISPORT -a 123546 shutdown

2. from library settings

[root@57 redis]# vim /etc/redis/6379.conf

282 slaveof 192.168.4.50 6050

289 masterauth 123456

[root@57 redis]# redis-cli -h 192.168.4.57 -p 6057

192.168.4.57:6057> INFO replication

# Replication

role:slave

master_host:192.168.4.50

master_port:6050

master_link_status:up

...................................

Configure master-slave (configure 57 slave libraries permanently)

[root@58 ~]# redis-cli -h 192.168.4.58 -p 6058 shutdown

[root@58 ~]# vim /etc/redis/6379.conf

282 slaveof 192.168.4.57 6057

[root@58 ~]# redis_6379 start

[root@58 ~]# redis-cli -h 192.168.4.58 -p 6058

192.168.4.58:6058> info replication

# Replication

role:slave

master_host:192.168.4.57

master_port:6057

master_link_status:up

.............

sentry mode

- When the master database is down, the slave database is automatically upgraded to the master database.

- Edit the sentinel.conf file on the slave host

- Run sentinel on slave host

1. Write a configuration file under Rebase

Format: sentinel monitor host name ip address port votes

Host Name: Custom

IP address: IP address of master host

Port: Port used by master host redis service

Number of votes: After the main database is down, the host with more than 1 votes will be upgraded to the main database.

The production environment generally does not set the connection password

50 before downtime (cancel 51 password)

[root@50 ~]# vim /etc/redis/6379.conf

#requirepass 123456

Restart redis after setup

57 link 50 code cancelled

[root@57 ~]# vim /etc/redis/6379.conf

289 #masterauth 123456

Restart redis after setup

[root@57 redis]# vim /etc/sentinel.conf

sentinel monitor 50 192.168.4.50 6050 1

Sentinel auth-pass 50 123456 If master inventory is in secret, enter

[root@57 redis]# redis-sentinel /etc/sentinel.conf

[root@57 ~]# redis-cli -h 192.168.4.57 -p 6057

192.168.4.57:6057> info replication

# Replication

role:slave

master_host:192.168.4.50

master_port:6050

50 View after downtime

192.168.4.57:6057> info replication

# Replication

role:master

connected_slaves:1

slave0:ip=192.168.4.58,port=6058,state=online,offset=10763,lag=1

.....................

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report