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

Notes on installation and configuration of Redis-3.2.1 sentinel

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Environment description:

Three machines 192.168.21.6ax 7Universe 8

Redis version: redis-3.2.1

Install redis on the three machines:

Decompress:

# tar zxvf redis-3.2.1.tar.gz-C / usr/local

Rename:

# mv / usr/local/redis-3.2.1 / usr/local/redis

Installation:

# cd / usr/local/redis

# make

# make install

# mkdir-p / usr/local/redis/etc

# cp / usr/local/redis/redis.conf / usr/local/redis/sentinel.conf / usr/local/redis/etc

Log in to 192.168.21.6 and modify redis.conf:

# bind 127.0.0.1

Bind 0.0.0.0

Log in to 192.168.21.7 Compact 8 and modify redis.conf:

# bind 127.0.0.1

Bind 0.0.0.0

Slaveof 10.10.10.11 6379

Save exit and start redis on three machines

/ usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf &

Log in to 192.168.21.6 to view the redis replication status:

# redis-cli info replication

# Replication

Role:master

Connected_slaves:2

Slave0:ip=192.168.21.8,port=6379,state=online,offset=198371,lag=0

Slave1:ip=192.168.21.7,port=6379,state=online,offset=198371,lag=1

Sentinel configuration:

Create a new directory:

# mkdir-p / usr/local/redis/db_26379

Modify / usr/local/redis/sentinel.conf on the three machines and add the following configuration:

Dir "/ usr/local/redis/db_26379"

Pidfile "/ usr/local/redis/db_26379/redis_26379.pid"

Loglevel notice

Logfile "/ usr/local/redis/db_26379/sentinel.log"

Bind 0.0.0.0

: X Save exit.

Note: other configurations remain the same.

Then start the Sentinel sentinel on 192.168.21.6 Universe 7Accord 8:

/ usr/local/bin/redis-server / usr/local/redis/etc/sentinel.conf-- sentinel &

Then add the master manually on the three machines 192.168.21.6, 7, and 8:

# redis-cli-p 26379 sentinel monitor chenfeng 192.168.21.6 6379 2

OK

View the log:

# tail-f / data/redis/db_26379/sentinel.log

24177mymaster X 20 Sep 10 mymaster 06V 06.563 * + sentinel sentinel 4eca392422764f3e3f4c0df7aaafc71c416c1a33 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

24177mymaster X 20 Sep 10 mymaster 06bureau 07.816 * + sentinel-invalid-addr sentinel 4eca392422764f3e3f4c0df7aaafc71c416c1a33 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

24177mymaster X 20 Sep 10 mymaster 06bureau 07.816 * + sentinel sentinel 40df350a0e705be6cbafbd83ae18ba51964f3a21 127.0.0.1 26379 @ mymaster 127.0.0.1 6379

24177ip 20 Sep 10 ip 06lo 08.573 * + sentinel-address-switch master mymaster 127.0.0.1 6379 ip 127.0.0.1 port 26379 for 1ecb5a5c14cb85b33935037182fb04d107b47c82

24177ip X 20 Sep 10 ip 06lo 09.854 * + sentinel-address-switch master mymaster 127.0.0.1 6379 ip 127.0.0.1 port 26379 for 4eca392422764f3e3f4c0df7aaafc71c416c1a33

24177quorum X 20 Sep 10 quorum 06 quorum 40.396 # + monitor master chenfeng 192.168.21.6 6379

24177Vera X 20 Sep 10 Sep 06UR 40.446 * + slave slave 192.168.21.7Vue 6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177Vera X 20 Sep 10 chenfeng 06UR 40.447 * + slave slave 192.168.21.8RV 6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177chenfeng X 20 Sep 10V 06V 52.383 * + sentinel sentinel 1ecb5a5c14cb85b33935037182fb04d107b47c82 192.168.21.7 26379 @ chenfeng 192.168.21.6 6379

24177chenfeng X 20 Sep 10 chenfeng 06VR 54.482 * + sentinel sentinel 4eca392422764f3e3f4c0df7aaafc71c416c1a33 127.0.0.1 26379 @ chenfeng 192.168.21.6 6379

Log in to 192.168.21.6 and manually simulate the failure of the main database:

# redis-cli-p 6379 shutdown

View the log:

# tail-f / data/redis/db_26379/sentinel.log

24177VOV X 20 Sep 10VOV 08RU 11.071 # + sdown master mymaster 127.0.16379

24177VOV X 20 Sep 10VOUR 08RU 11.071 # + sdown master chenfeng 192.168.21.6 6379

24177quorum X 20 Sep 10 quorum 08Fringe 11.172 # + odown master mymaster 127.0.0.1 6379 # quorum 4amp 2

24177Vol X 20 Sep 10RU 08RU 11.172 # + new-epoch 1

24177VOV X 20 Sep 10VOR 08RU 11.172 # + try-failover master mymaster 127.0.16379

24177VR X 20 Sep 10 Sep 08RU 11.181 # + vote-for-leader 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177quorum X 20 Sep 10V 08RH 11.181 # + odown master chenfeng 192.168.21.6 6379 # quorum 3Accord 2

24177VOV X 20 Sep 10RU 08RU 11.181 # + new-epoch 2

24177VOV X 20 Sep 10VOR 08RH 11.181 # + try-failover master chenfeng 192.168.21.6 6379

24177Vol X 20 Sep 10RU 08RU 11.198 # + vote-for-leader 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:11.198 # 4eca392422764f3e3f4c0df7aaafc71c416c1a33 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.198 # 4eca392422764f3e3f4c0df7aaafc71c416c1a33 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:11.198 # 40df350a0e705be6cbafbd83ae18ba51964f3a21 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.198 # 1ecb5a5c14cb85b33935037182fb04d107b47c82 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 1

24177:X 20 Sep 10:08:11.198 # 1ecb5a5c14cb85b33935037182fb04d107b47c82 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177VOV X 20 Sep 10VOR 08RV 11.260 # + elected-leader master chenfeng 192.168.21.6 6379

24177VOV X 20 Sep 10VOR 08RV 11.260 # + failover-state-select-slave master chenfeng 192.168.21.6 6379

24177VOV X 20 Sep 10 Sep 08UR 11.360 # + selected-slave slave 192.168.21.7VOV 6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177chenfeng X 20 Sep 08VOV 11.361 * + failover-state-send-slaveof-noone slave 192.168.21.7VOV 6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177chenfeng X 20 Sep 08VOV 11.451 * + failover-state-wait-promotion slave 192.168.21.7VOV 6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177Vera X 20 Sep 10 Sep 08UR 11.898 # + promoted-slave slave 192.168.21.7VOV 6379 192.168.21.7 6379 @ chenfeng 192.168.21.6 6379

24177VOV X 20 Sep 10VOV 08RU 11.898 # + failover-state-reconf-slaves master chenfeng 192.168.21.6 6379

24177 X 20 Sep 10 Sep 08UR 11.948 * + slave-reconf-sent slave 192.168.21.8VO 6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177Vol X 20 Sep 10UR 08RU 12.269 # + vote-for-leader 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.270 # 4eca392422764f3e3f4c0df7aaafc71c416c1a33 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.270 # 40df350a0e705be6cbafbd83ae18ba51964f3a21 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177:X 20 Sep 10:08:12.270 # 1ecb5a5c14cb85b33935037182fb04d107b47c82 voted for 4eca392422764f3e3f4c0df7aaafc71c416c1a33 2

24177VOV X 20 Sep 10VOR 08RU 12.353 # + elected-leader master mymaster 127.0.16379

24177VOV X 20 Sep 10VOR 08RU 12.353 # + failover-state-select-slave master mymaster 127.0.16379

24177VOV X 20 Sep 10 Sep 08UR 12.424 # + selected-slave slave 192.168.21.7VOV 6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177Vera X 20 Sep 10 Sep 08UR 12.424 * + failover-state-send-slaveof-noone slave 192.168.21.7Vol 6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177Vera X 20 Sep 10 Sep 08UR 12.491 * + failover-state-wait-promotion slave 192.168.21.7Vol 6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177chenfeng X 20 Sep 10 Sep 08V 12.916 * + slave-reconf-inprog slave 192.168.21.8V 6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177chenfeng X 20 Sep 10 Sep 08V 12.916 * + slave-reconf-done slave 192.168.21.8V 6379 192.168.21.8 6379 @ chenfeng 192.168.21.6 6379

24177 X 20 Sep 10V 08Rd 13.015 # + failover-end master chenfeng 192.168.21.6 6379

24177 X 20 Sep 10V 08V 13.015 # + switch-master chenfeng 192.168.21.6 6379 192.168.21.7 6379

24177chenfeng X 20 Sep 08V 13.016 * + slave slave 192.168.21.8V 6379 192.168.21.8 6379 @ chenfeng 192.168.21.7 6379

24177chenfeng X 20 Sep 10V 08V 13.016 * + slave slave 192.168.21.6V 6379 192.168.21.6 6379 @ chenfeng 192.168.21.7 6379

24177mymaster X 20 Sep 10 Sep 08 mymaster 13.297 # + 192.168.21.7 promoted-slave slave 6379 192.168.21.7 6379 @ mymaster 127.0.0.1 6379

24177VOV X 20 Sep 10VOR 08RU 13.297 # + failover-state-reconf-slaves master mymaster 127.0.16379

24177mymaster X 20 Sep 10 Sep 08V 13.352 * + slave-reconf-sent slave 192.168.21.8V 6379 192.168.21.8 6379 @ mymaster 127.0.0.1 6379

24177Vera X 20 Sep 10 Sep 08RV 14.345 * + slave-reconf-inprog slave 192.168.21.8RV 6379 192.168.21.8 6379 @ mymaster 127.0.0.1 6379

24177Vera X 20 Sep 10 Sep 08RV 14.345 * + slave-reconf-done slave 192.168.21.8RV 6379 192.168.21.8 6379 @ mymaster 127.0.0.1 6379

24177VOV X 20 Sep 10VUR 08RU 14.420 # + failover-end master mymaster 127.0.16379

24177 X 20 Sep 10 Sep 08vir 14.420 # + switch-master mymaster 127.0.0.1 6379 192.168.21.7 6379

24177Vera X 20 Sep 10 Sep 08RV 14.420 * + slave slave 192.168.21.8RV 6379 192.168.21.8 6379 @ mymaster 192.168.21.7 6379

24177mymaster X 20 Sep 10 Sep 08VR 14.420 * + slave slave 127.0.0.1 mymaster 6379 127.0.0.1 @ mymaster 192.168.21.7

24177Vera X 20 Sep 10 Sep 08VR 43.065 # + sdown slave 192.168.21.6 chenfeng 192.168.21.6 6379 @ chenfeng 192.168.21.6 6379

24177mymaster X 20 Sep 10 Sep 08V 44.465 # + 127.0.0.1 sdown slave 6379 127.0.0.1 @ mymaster 192.168.21.7

24177chenfeng X 20 Sep 10 chenfeng 09V 13.307 #-sdown slave 192.168.21.6 V 6379 192.168.21.6 6379 @ chenfeng

24177mymaster X 20 Sep 10 mymaster 09VR 13.595 #-sdown slave 127.0.0.1 mymaster 6379 127.0.0.1 @ mymaster 192.168.21.7

24177chenfeng X 20 Sep 10 chenfeng 09 chenfeng 23.221 * + 192.168.21.6 chenfeng 6379 192.168.21.6 6379

24177 Sep X 20 10 Sep 09 mymaster 25.310 * + 192.168.21.6 mymaster 6379 192.168.21.6 6379 @ mymaster

From the above log, it can be found that the Sentinel automatically elected the new main library 192.168.21.7, and the failover was successful.

Start the original master library 192.168.21.6 again and become the slave library of 192.168.21.7:

# redis-cli info replication

# Replication

Role:slave

Master_host:192.168.21.7

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:1

Master_sync_in_progress:0

Slave_repl_offset:25901

Slave_priority:100

Slave_read_only:1

Connected_slaves:0

Master_repl_offset:0

Repl_backlog_active:0

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:0

Repl_backlog_histlen:0

At this point, the Sentinel mode is installed and tested.

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