Centos8 redis5 main platform from the synchronization arranged structures and sentinel sentinel

First, the planning of three redis ip: two from a master

redismaster01: 172.18 . 1.1 
redisslave01: 172.18 . 1.2         from
redisslave02: 172.18 . 1.3         from

 

Description: Liu association of forest architecture is a framework focused blog, address: https://www.cnblogs.com/architectforest

         The corresponding source code can be accessed here for:  https://github.com/liuhongdi/

 Description: Author: Liu association E-mail: [email protected]

 

Description: centos8 on redis5 installation, refer to this one:

centos8 install redis
Address: HTTPS: // www.cnblogs.com/architectforest/p/12325230.html

 

 Second, three separate configurations machine redis

1, master01 on

[root@redismaster01 /]# vi /usr/local/soft/redis5/conf/redis.conf

content:

bind 172.18.1.1
masterauth 123456
requirepass 123456

Restart redis service:

[root@redismaster01 /]# systemctl stop redis
[root@redismaster01 /]# systemctl start redis

 

2, slave01 on

[root@redisslave01 /]# vi /usr/local/soft/redis5/conf/redis.conf

content

bind 172.18.1.2
slaveof 172.18.1.1 6379
masterauth 123456
requirepass 123456

Restart redis service

[root@redisslave01 /]# systemctl stop redis
[root@redisslave01 /]# systemctl start redis

 

3, the slave02

[root@redisslave02 /]# vi /usr/local/soft/redis5/conf/redis.conf

content

bind 172.18.1.3
slaveof 172.18.1.1 6379
masterauth 123456
requirepass 123456

Restart redis service

[root@redisslave02 /]# systemctl stop redis
[root@redisslave02 /]# systemctl start redis

 

4. Parameters:

slaveof: Specifies the main redis ip and port
masterauth: master password redis
requirepass: Local password

Recommend password keeping

 

Third, from the view master status from redis-cli

1, from the master01

[root@redismaster01 /]# /usr/local/soft/redis5/bin/redis-cli -h 172.18.1.1 -p 6379

Check master-slave synchronization:

172.18.1.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=172.18.1.2,port=6379,state=online,offset=938,lag=0
slave1:ip=172.18.1.3,port=6379,state=online,offset=938,lag=1
master_replid:f2800497a73845ad25276bf74cffce2138a6e216
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:952
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:952

 

2, from the upper slave01

[root@redisslave01 /]# /usr/local/soft/redis5/bin/redis-cli -h 172.18.1.2 -p 6379
172.18.1.2:6379> info replication
# Replication
role:slave
master_host:172.18.1.1
master_port:6379
master_link_status:up
master_last_io_seconds_ago:10
master_sync_in_progress:0
slave_repl_offset:182
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:f2800497a73845ad25276bf74cffce2138a6e216
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:182
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:182

 

Four, info Detailed contents of replaction:

1, the main redis:

role: the role of master # instance, here is a master
connected_slaves: 2           # Slave example the number of connections, two
slave0: IP = 172.18 . 1.2 , Port = 6379 , State = Online, offset = 938 , LAG = 0     #lag REPLCONF command is not transmitted to the main number of seconds from the library Library
Slave1: IP = 172.18 . 1.3 , Port = 6379 , State = Online, offset = 938 , = LAG . 1     #lag REPLCONF command is not transmitted to the main number of seconds from the library Library
master_replid:f2800497a73845ad25276bf74cffce2138a6e216
master_replid2: 0000000000000000000000000000000000000000 
master_repl_offset: 952               # master-slave synchronization offset, and if this value is the same as described above offset from the main delay not consistent
second_repl_offset: - 1 
repl_backlog_active: 1                # copy backlog buffer is turned on
repl_backlog_size: 1048576            # copy backlog buffer size
repl_backlog_first_byte_offset: . 1     # copy the buffer size of the offset
repl_backlog_histlen:952

 

2, from the upper redis

# Replication
role: the role of slave # example, is the slave
MASTER_HOST: 172.18 . 1.1            # corresponding to the master node ip
MASTER_PORT: 6379                  # corresponding to the master node port
master_link_status: up #slave end view synchronization state between it and the master, when copying is disconnected expressed down, the connection is up.
master_last_io_seconds_ago: 7      # main library does not send data to the number of seconds from the library? 
master_sync_in_progress: 0         # whether from a server to synchronize with the master server
slave_repl_offset: 4855              #slave replication offset
slave_priority: 100                     #slave priority
slave_read_only: 1                    # from the library is set read-only
connected_slaves: 0                 Slave # number of instances connected
master_replid:f2800497a73845ad25276bf74cffce2138a6e216
master_replid2: 0000000000000000000000000000000000000000 
master_repl_offset: 4855            # master-slave synchronization offset
second_repl_offset: - 1              
repl_backlog_active: 1              # copy backlog buffer is turned on
repl_backlog_size: 1048576          # copy backlog buffer size
repl_backlog_first_byte_offset: . 1   # copy the buffer size of the offset
repl_backlog_histlen:4855

 

Description: When viewing from the redis synchronization,

1 , if master_link_status is up, it indicates a connection to the main redis normal, or to troubleshoot connection
 2 , if slave_repl_offset and consistent master_repl_offset, represents the synchronization is consistent

Fifth, the main test is in effect from redis

1, master01 on

172.18.1.1:6379> set a 123
OK
172.18.1.1:6379> get a
"123"

 

2, slave01 on

172.18.1.2:6379> get a
"123"

 

3, the slave02

172.18.1.3:6379> get a
"123"

 

VI planning: three Sentinel server

The official recommended that at least three and odd number of nodes Sentinel

172.18 . 1.4     Sentinel 1
 172.18 . 1.5     sentry 2
 172.18 . 1.6     Sentinel 3

 

Seven guards on the machine Each implementation:

  In the source code redis After compilation, should redis-sentinel copied to the installation directory bin

  The sentinel.conf profile is also copied to the conf directory of the installation directory

[root@redissentinel01 src]# cp /usr/local/source/redis-5.0.7/src/redis-sentinel /usr/local/soft/redis5/bin/
[root@redissentinel01 src]# cp /usr/local/source/redis-5.0.7/sentinel.conf /usr/local/soft/redis5/conf/

 

Eight, the sentry on each machine configuration:

1, create a temporary working directory used

[root@redissentinel01 src]# cd /data/redis6379/ 
[root@redissentinel01 redis6379]# mkdir tmp

 

2, edit the configuration Sentinel

[root@redissentinel01 src]# vi /usr/local/soft/redis5/conf/sentinel.conf

Content: When the actual operation to remove the brackets and captions

Port 26379     (default, no need to change)
the bind 0.0 . 0.0     (added)
daemonize yes (default is no, changed to yes)
protected - the MODE NO (default, uncommented)
logfile " /data/redis6379/log/redis.log "     (modify the configuration) 
 the dir / Data / redis6379 / tmp (modified configuration)
sentinel myid 372e722a7630342374ce6d8e0fee5f7a86e647e4
(This value on each machine to distinguish, you can modify only one number,
Otherwise, when viewed with info sentinel sentinels number is incorrect
Or comment out this line should be able to)
Monitor mymaster Sentinel 172.18 . 1.1  6379  2    (modified configuration)
the auth Sentinel -pass mymaster 123456    (modified configuration)

 

3, configuration instructions:

monitor designated primary redis the ip and port, the last two means: this is the primary instance fail judgment requires the consent of at least two Sentinel processes
auth -pass password is specified primary redis

 

Nine, systemd management redis-sentinel

1, edit a file service

[root@redissentinel01 log]# vi /lib/systemd/system/redis-sentinel.service

 

content:

[Unit]
Description = Redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis-sentinel.pid
ExecStart=/usr/local/soft/redis5/bin/redis-sentinel /usr/local/soft/redis5/conf/sentinel.conf --sentinel
ExecStop=/bin/kill -s TERM $MAINPID

[Install]
WantedBy=multi-user.target

 

2, the test start redis-sentinel

[root@redissentinel01 log]# systemctl daemon-reload
[root@redissentinel01 log]# systemctl start redis-sentinel
[root@redissentinel01 log]# ps auxfww | grep redis-sentinel | grep -v grep
root        390  0.1  0.0  41076  3292 ?        Ssl  05:39   0:00 /usr/local/soft/redis5/bin/redis-sentinel 0.0.0.0:26379 [sentinel]

 

Ten, sentinel commonly used commands:

What sentinel under View mymaster

172.18.1.6:26379> sentinel sentinels mymaster

Its primary display list state node

172.18.1.6:26379> sentinel masters

There are several slave under display mymaster

172.18.1.6:26379> sentinel slaves mymaster

Only view information mymaster the master node

172.18.1.6:26379> sentinel master mymaster

View a summary of sentinel information

172.18.1.6:26379> info sentinel

 

Eleven, when the master down test, can function as sentinels of the switching master

1, start the Sentinel server to view the master information

172.18.1.5:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=172.18.1.1:6379,slaves=3,sentinels=3

 

2 killed in master process redis

[root@redismaster01 conf]# kill 1062
[root@redismaster01 conf]# kill 1062
bash: kill: (1062) - No such process

 

3, again to the Sentinel server View:

172.18.1.5:26379> info sentinel
# Sentinel
sentinel_masters:1
sentinel_tilt:0
sentinel_running_scripts:0
sentinel_scripts_queue_length:0
sentinel_simulate_failure_flags:0
master0:name=mymaster,status=ok,address=172.18.1.2:6379,slaves=3,sentinels=3

You can see: redis process is killed on 172.18.1.1, 172.18.1.2 has been selected as master

 

4, log in to see the newly elected master

127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:1
slave0:ip=172.18.1.3,port=6379,state=online,offset=229680,lag=1
master_replid:3977c9f0425ab035dee705874b5b2f7cd8c1bcb4
master_replid2:41d7c9660b1195a58fc273319078a6f4551436b0
master_repl_offset:229950
second_repl_offset:193766
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:229950

Description: The current redis's role has become a master

 

5, back to the old master, start again

[root@redismaster01 conf]# systemctl start redis

 

When viewing with info replication, the role has become a slave

127.0.0.1:6379> info replication
# Replication
role:slave
master_host:172.18.1.2
master_port:6379
master_link_status:up
master_last_io_seconds_ago:1
master_sync_in_progress:0
slave_repl_offset:299988
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:3977c9f0425ab035dee705874b5b2f7cd8c1bcb4
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:299988
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:267193
repl_backlog_histlen:32796

 

XII View centos version

[root@localhost liuhongdi]# cat /etc/redhat-release
CentOS Linux release 8.1.1911 (Core)

 

Guess you like

Origin www.cnblogs.com/architectforest/p/12511089.html