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 cluster building and disaster recovery deployment (Sentinel sentinel)

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Redis disaster recovery deployment (Sentinel Sentinel)

1. Sentinel introduction

Redis Sentinel

Sentinel (Sentinel) is a tool for monitoring the status of Master in redis clusters, which has been integrated into the version of redis2.4+

2. Sentinel function:

1): Master status detection

2): if the Master is abnormal, the Master-Slave will be switched, using one of the Slave as the Master and the previous Master as the Slave

3): after Master-Slave switching, the contents of master_redis.conf, slave_redis.conf and sentinel.conf will all be changed, that is, there will be an additional line of slaveof configuration in master_redis.conf, and the monitoring target of sentinel.conf will be changed accordingly.

3. How Sentinel works:

1): each Sentinel sends a PING command to its known Master,Slave and other Sentinel instances at a frequency of once per second

2): if the time between an instance (instance) and the last valid reply to a PING command exceeds the value specified in the down-after-milliseconds option, the instance will be marked as subjectively offline by Sentinel.

3): if a Master is marked as subjectively offline, all Sentinel that are monitoring the Master should confirm that the Master has indeed entered the subjective offline state at a frequency of once per second.

4): when a sufficient number of Sentinel (greater than or equal to the value specified in the profile) confirms that Master has indeed entered the subjective offline state within the specified time range, the Master will be marked as objective offline.

5): in general, each Sentinel sends INFO commands to all Master,Slave it knows at a frequency of once every 10 seconds

6): when Master is marked as objective offline by Sentinel, the frequency of Sentinel sending INFO commands to all Slave of offline Master will be changed from once in 10 seconds to once per second

7): if there is not enough Sentinel to agree that Master has been taken offline, the objective offline status of Master will be removed.

If Master returns a valid reply to Sentinel's PING command, the subjective offline state of Master will be removed.

4. Subjective referral and objective referral

Subjective referral: Subjectively Down, or SDOWN for short, refers to the offline judgment made by the current Sentinel instance to a redis server.

Objective offline: Objectively Down, referred to as ODOWN, refers to the SDOWN judgment obtained by multiple Sentinel instances after making a SDOWN judgment on Master Server and communicating with each other through the SENTINEL is-master-down-by-addr command, and then turn on failover.

In popular terms, it is:

Redis's sentinel system is used to manage multiple redis servers and can implement a cluster that functionally implements HA. The system mainly performs three tasks:

1. Monitoring: Redis Sentinel monitors the running status of master server and slave server in real time.

2. Notification: when there is a problem with a monitored Redis server, Redis Sentinel can send a notification to the system administrator or send a notification to other programs through API

3. Failover (failover): automatic master-slave switchover

4. Unified configuration management: the connector asks sentinel to obtain the address of the master and slave

5. Raft distributed algorithm

1. Main uses: for distributed systems, system fault tolerance, and selecting leaders

two。 Author: Diego Ongaro, graduated from Harvard

3. Currently, the projects that use this algorithm are:

A. CoreOS: see below

B. Ectd: a distributed, consistent shared configuration

C. LogCabin: distributed storage system

D. Redis sentinel: monitoring system of redis

Core of Raft algorithm used by Sentinel: principle

1. All sentinel have the right to elect the leader.

two。 Each sentinel will ask the other sentinel to elect itself as the leader (mainly initiated by the sentinel who found that redis is objectively offline)

3. Each sentinel has only one chance to vote.

4. Adopt the principle of first come, first served

5. Once added to the system, it will not be cleared automatically (this is important, why?)

6. Each sentinel has a unique uid, which will not be changed due to restart

7. The condition for reaching the leader is that N sentinel chooses itself with 2 + 1 players.

8. Using the configuration era, if there is a brain crack in one election, the configuration era will increase step by step, entering the next election, and all sentinel will be in a unified configuration era, with the latest as the standard.

Core of Raft algorithm: viewable

Raft Visualization (algorithm demonstration)

Application of Raft distributed algorithm

Coreos: cloud computing star Docker is growing like a rocket, and the biosphere associated with it is getting better, and CoreOS is one of them. CoreOS, a new Linux operating system designed for data centers, released its first stable version in July 2014 and has completed a $8 million round of financing.

The architecture diagram of a simple master-slave structure plus sentinel cluster is as follows:

192.168.110.134 (master redis,sentinel)-> 192.168.110.135 (slave redis,sentinel)

| |\ / |

| |\ / |

| |\ / |

| |\ / |

| |\ / |

| |\ |

| |\ |

| | /\ |

| | /\ |

| | /\ |

| | /\ |

192.168.110.132 (sentinel)-> 192.168.110.133 (slave redis,sentinel)

The figure above shows one master and one slave node, plus two clusters with sentinel deployed. Sentinel clusters will communicate with each other, communicate the status of redis nodes, make corresponding judgments and deal with them. Here, subjective offline state and objective offline state are more important states, which determine whether to fail over.

You can subscribe to the specified channel information and inform the administrator when the server fails that the client can treat Sentinel as a Redis service that only provides subscription functionality.

You cannot use the PUBLISH command to send information to this server, but you can use the SUBSCRIBE command or the PSUBSCRIBE command to get it by subscribing to a given channel

The corresponding event reminder.

6. Deploy sentinels

1) configure a Sentinel Sentinel mode:

Copy the sentinel.conf configuration file in the source code to the specified directory

[root@web1 ~] # mkdir / usr/local/sentinel

[root@web1 ~] # cd / usr/local/src/redis-3.2.6/

[root@web1 redis-3.2.6] # cp sentinel.conf / usr/local/sentinel/

[root@web1 redis-3.2.6] # cd / usr/local/sentinel/

[root@web1 sentinel] # vim sentinel.conf

[root@web1 sentinel] # grep-v "^ #" sentinel.conf | grep-v "^ $"

Port 26379

Dir / tmp

Sentinel monitor mymaster 192.168.110.134 6379 1

Sentinel down-after-milliseconds mymaster 30000

Sentinel parallel-syncs mymaster 1

Sentinel failover-timeout mymaster 180000

Example:

# sentinel Port

Port 26380

# work path

Dir "/ usr/local/redis-6380"

# Daemon mode

Daemonize yes

# specify log file name

Logfile ". / sentinel.log"

# the master monitored by Sentinel has the same master-slave configuration. When switching between master and slave, 6379 will become the current master port.

Sentinel monitor mymaster 192.168.137.40 6379 1

# how long master or slave (default is 30 seconds) cannot be marked as s_down status after use.

Sentinel down-after-milliseconds mymaster 5000

# if sentinel fails to complete the failover operation within the configuration value (that is, master/slave automatically switches over in case of failure), this failover is considered to have failed.

Sentinel failover-timeout mymaster 18000

# set master and slaves authentication passwords

Sentinel auth-pass mymaster 123456

# parts automatically added by the Sentinel program

# Generated by CONFIG REWRITE

Sentinel config-epoch mymaster 0

Sentinel leader-epoch mymaster 1

# indicates the ip and port of the slave library of the current cluster, which will change when the master-slave switch occurs.

Sentinel known-slave mymaster 192.168.137.40 6380

# what are the monitoring sentinels besides the current sentinels

Sentinel known-sentinel mymaster 192.168.137.40 26379 7a88891a6147e202a53601ca16a3d438e9d55c9d

Sentinel current-epoch 1

It is mainly this one:

Sentinel monitor mymaster 192.168.110.134 6379 2

My mymaster is followed by master's ip and port

The last'2' means that I want to start as long as 2 sentinel think that master is offline, consider the master offline objectively, launch failover and elect a new master.

Usually the last parameter cannot be more than the number of sentinel instances started.

[root@web2 ~] # mkdir / usr/local/sentinel

[root@web2 ~] # cp / usr/local/src/redis-3.2.6/sentinel.conf / usr/local/sentinel/

[root@web2 ~] # cd / usr/local/sentinel/

[root@web2 sentinel] # vim sentinel.conf

[root@web2 sentinel] # grep-v "^ #" sentinel.conf | grep-v "^ $"

Port 26379

Dir / tmp

Sentinel monitor mymaster 192.168.110.134 6379 2

Sentinel down-after-milliseconds mymaster 30000

Sentinel parallel-syncs mymaster 1

Sentinel failover-timeout mymaster 180000

Start two sentinel (Sentinels) in background startup mode:

[root@web1 sentinel] # redis-sentinel / usr/local/sentinel/sentinel.conf &

[1] 18378

[root@web1 sentinel] # 18378 Increased maximum number of open files to X 16 Dec 1515 Increased maximum number of open files to 10032 (it was originally set to 1024).

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.2.6 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in sentinel mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 26379 |

| | `-. _`. _ / _. -'| PID: 18378 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

18378:X 16 Dec 15:46:16.734 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

18378:X 16 Dec 15:46:16.734 # Sentinel ID is 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

18378 quorum X 16 Dec 15 Switzerland 46 quorum 16.734 # + monitor master mymaster 192.168.110.134 6379

As can be seen from the image above:

1. The Sentinel has been activated, and its id is 236f14b361fc5a0dc0621cf88823ed6e6252b2f3

2. Add a monitor to the master database

3. 2 slave have been found (it can be seen that the sentry does not need to configure slave, but only needs to specify master, and the sentry will automatically discover slave)

[root@web1 sentinel] # ps aux | grep redis

Root 18357 0.1 1.0 135572 2440? Ssl 15:40 0:00 redis-server *: 6379

Root 18378 0.1 1.0 133528 2572 pts/1 Sl 15:46 0:00 redis-sentinel *: 26379 [sentinel]

Root 18400 0.00.3 103244 864 pts/1 S+ 15:51 0:00 grep redis

6. Downtime testing from Redis

Kill one of the processes from redis:

[[root@web1 sentinel] # kill 18357

[root@web1 sentinel] # ps aux | grep redis

Root 18378 0.1 1.0 133528 2572 pts/1 Sl 15:46 0:01 redis-sentinel *: 26379 [sentinel]

Root 18444 0.00.3 103244 864 pts/1 S+ 16:00 0:00 grep redis

30 seconds later, the Sentinel's console output:

[root@web1 sentinel] # 18378 Dec 16 Dec 1615 01lo 16.452 # + sdown master mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 quorum 01lo 16.452 # + odown master mymaster 192.168.110.134 6379 # quorum 1

18378 Dec X 16 Dec 16 01VR 16.452 # + new-epoch 9

18378 Dec X 16 Dec 16 01 16.452 # + try-failover master mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01VR 16.470 # + vote-for-leader 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 9

18378 Dec X 16 Dec 16 01 16.470 # + elected-leader master mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 16.470 # + failover-state-select-slave master mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 mymaster 16.546 # + selected-slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 mymaster 16.546 * + failover-state-send-slaveof-noone slave 192.168.110.135 purl 6379 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 mymaster 16.605 * + failover-state-wait-promotion slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 mymaster 16.699 # + promoted-slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 16.699 # + failover-state-reconf-slaves master mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 16.759 # + failover-end master mymaster 192.168.110.134 6379

18378 Dec X 16 Dec 16 01 16.759 # + switch-master mymaster 192.168.110.134 6379 192.168.110.135 6379

18378 Dec X 16 Dec 16 01 mymaster 16.760 * + slave slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

18378 Dec X 16 Dec 16 01 mymaster 46.858 # + sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ 18378

30 seconds later, the Sentinel's console output:

18378 Dec X 16 Dec 16 01 16.759 # + switch-master mymaster 192.168.110.134 6379 192.168.110.135 6379

18378 Dec X 16 Dec 16 01 mymaster 16.760 * + slave slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

18378 Dec X 16 Dec 16 01 mymaster 46.858 # + sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ 18378

It means that we have monitored the downtime of the master that our kill just dropped.

As you can see, slave has been converted back to the main library-sdown: it means that the service is restored.

[root@web2 sentinel] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

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

127.0.0.1purl 6379 >

Restore 192.168.110.134:

[root@web1 sentinel] # redis-server / usr/local/redis/etc/redis.conf

[root@web1 sentinel] # 18378 Dec 16 Dec 16 sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.135 6379

18378 Dec X 16 Dec 07 Dec 09.806 * + convert-to-slave slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ 192.168.110.135 6379

[root@web1 sentinel] #

[root@web1 sentinel] #

[root@web1 sentinel] # ps aux | grep redis

Root 18378 0.2 1.0 133528 2636 pts/1 Sl 15:46 0:02 redis-sentinel *: 26379 [sentinel]

Root 18487 0.1 1.0 135572 2564? Ssl 16:06 0:00 redis-server *: 6379

Root 18491 0.00.3 103244 864 pts/1 S+ 16:08 0:00 grep redis

192.168.110.134 is added to the replication as a slave library (the master library will not be switched over):

Test:

[root@web2 sentinel] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.110.134,port=6379,state=online,offset=2835,lag=1

Master_repl_offset:2835

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:2834

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.110.134,port=6379,state=online,offset=9687,lag=0

Master_repl_offset:9832

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:9831

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.110.134,port=6379,state=online,offset=36450,lag=0

Master_repl_offset:36595

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:36594

127.0.0.1 purl 6379 > set name2 lisi

OK

127.0.0.1 6379 > set age2 22

OK

127.0.0.1 purl 6379 > get name2

"lisi"

127.0.0.1 purl 6379 > get age2

"22"

127.0.0.1purl 6379 >

[root@web1 sentinel] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:192.168.110.135

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:0

Master_sync_in_progress:0

Slave_repl_offset:73863

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

127.0.0.1 purl 6379 > get name2

"lisi"

127.0.0.1 purl 6379 > get set2

(nil)

127.0.0.1 purl 6379 > get age2

"22"

127.0.0.1purl 6379 >

The effect is good:

Switch the main library back to 192.168.110.134

[root@web2 sentinel] # ps aux | grep redis

Root 7063 0.1 1.2 135572 3116? Ssl 14:35 0:13 redis-server *: 6379

Root 7649 0.00.3 103244 864 pts/1 S+ 16:48 0:00 grep redis

[root@web2 sentinel] # kill 7063

[root@web1 sentinel] # 18522 sdown master mymaster X 16 Dec 1615 49 05.725 # + sdown master mymaster 192.168.110.135 6379

18522 Dec X 16 Dec 16 49 quorum 05.725 # + odown master mymaster 192.168.110.135 6379 # quorum 1

18522 Dec X 16 Dec 1614 49 05.725 # + new-epoch 10

18522 Dec X 16 Dec 1614 49 05.725 # + try-failover master mymaster 192.168.110.135 6379

18522 Dec X 16 Dec 1614 49 05.736 # + vote-for-leader 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 10

18522 Dec X 16 Dec 16V 49V 05.736 # + elected-leader master mymaster 192.168.110.135 6379

18522 Dec X 16 Dec 16V 49V 05.736 # + failover-state-select-slave master mymaster 192.168.110.135 6379

18522 Dec X 16 Dec 16V 49v 05.791 # + selected-slave slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

18522 Dec X 16 Dec 16 49 mymaster 05.791 * + failover-state-send-slaveof-noone slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

18522 Dec X 16 Dec 16 49 mymaster 05.875 * + failover-state-wait-promotion slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

18522 Dec X 16 Dec 1649 mymaster 06.233 # + promoted-slave slave 192.168.110.1341979 192.168.110.134 6379 @ mymaster

18522 Dec X 16 Dec 1614 49 06.233 # + failover-state-reconf-slaves master mymaster 192.168.110.135 6379

18522 Dec X 16 Dec 1614 49 06.331 # + failover-end master mymaster 192.168.110.135 6379

18522 Dec X 16 Dec 16V 49v 06.331 # + switch-master mymaster 192.168.110.135 6379 192.168.110.134 6379

18522 Dec X 16 Dec 16 49 mymaster 06.331 * + slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

18522 Dec X 16 Dec 16 49 mymaster 36.394 # + sdown slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

Successfully switched over

[root@web1 sentinel] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

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

127.0.0.1purl 6379 >

Restore the redis of 192.168.110.135:

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

127.0.0.1 Dec 6379 > 18522 mymaster X 16 Dec 16 Dec 52V 32.351 #-sdown slave 192.168.110.135mymaster 6379 192.168.110.135 6379 @ 192.168.110.134 6379

18522 Dec X 16 Dec 16 V 52V 42.305 * + convert-to-slave slave 192.168.110.135R 6379 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

127.0.0.1purl 6379 >

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.110.135,port=6379,state=online,offset=13653,lag=1

Master_repl_offset:13667

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:13666

127.0.0.1purl 6379 >

one

[root@web2 sentinel] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:192.168.110.134

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:2

Master_sync_in_progress:0

Slave_repl_offset:16502

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

127.0.0.1purl 6379 >

2) configure the mode of two Sentinel Sentinel:

[root@web1 sentinel] # grep-v "^ $" / usr/local/sentinel/sentinel.conf | grep-v "^ #"

Port 26379

Dir "/ tmp"

Sentinel myid 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

Sentinel monitor mymaster 192.168.110.134 6379 2

Sentinel config-epoch mymaster 10

Sentinel leader-epoch mymaster 10

Sentinel known-slave mymaster 192.168.110.135 6379

Sentinel known-sentinel mymaster 192.168.110.135 26379 16286f52de2675345d1b11bc8946adc5d3f0c360

Sentinel current-epoch 10

[root@web2 sentinel] # grep-v "^ $" / usr/local/sentinel/sentinel.conf | grep-v "^ #"

Port 26379

Dir "/ tmp"

Sentinel myid 16286f52de2675345d1b11bc8946adc5d3f0c360

Sentinel monitor mymaster 192.168.110.134 6379 2

Sentinel config-epoch mymaster 0

Sentinel leader-epoch mymaster 6

Sentinel known-slave mymaster 192.168.110.135 6379

Sentinel known-sentinel mymaster 192.168.110.134 26379 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

Sentinel current-epoch 10

It is mainly this one:

Sentinel monitor mymaster 192.168.110.134 6379 2

The last'2' means that I want to start as long as 2 sentinel think that master is offline, consider the master offline objectively, launch failover and elect a new master.

Usually the last parameter cannot be more than the number of sentinel instances started.

[root@web1 sentinel] # redis-sentinel / usr/local/sentinel/sentinel.conf &

[1] 18747

[root@web1 sentinel] # 18747 Increased maximum number of open files to X 16 Dec 17 Increased maximum number of open files to 0415 Increased maximum number of open files to 10032 (it was originally set to 1024).

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.2.6 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in sentinel mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 26379 |

| | `-. _`. _ / _. -'| PID: 18747 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

18747:X 16 Dec 17:04:30.599 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

18747:X 16 Dec 17:04:30.599 # Sentinel ID is 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

18747 Dec X 16 quorum 17 04 quorum 30.599 # + monitor master mymaster 192.168.110.134 6379

18747 Dec X 16 Dec 17 V 05V 00.659 # + sdown sentinel 16286f52de2675345d1b11bc8946adc5d3f0c360 192.168.110.135 26379 @ mymaster 192.168.110.134 6379

[root@web2 sentinel] # redis-sentinel / usr/local/sentinel/sentinel.conf &

[1] 7726

You have new mail in / var/spool/mail/root

[root@web2 sentinel] # 7726 Increased maximum number of open files to X 16 Dec 17 Increased maximum number of open files to 0415 Increased maximum number of open files to 33.835 (it was originally set to 1024).

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.2.6 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in sentinel mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 26379 |

| | `-. _`. _ / _. -'| PID: 7726 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

7726:X 16 Dec 17:04:33.836 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

7726:X 16 Dec 17:04:33.836 # Sentinel ID is 16286f52de2675345d1b11bc8946adc5d3f0c360

7726quorum X 16 Dec 17 quorum 04 quorum 33.836 # + monitor master mymaster 192.168.110.134 6379

7726 X 16 Dec 171R 04R 34.668 # + new-epoch 10

7726 Dec X 16 Dec 17 Revue 03.836 # + sdown sentinel 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 192.168.110.134 26379 @ mymaster 192.168.110.134 6379

There is a problem with the above: the reason is that bind only monitors the native and 192.168.1.1 IP addresses by default.

# bind 127.0.0.1 192.168.1.1

Add: bind 0.0.0.0

There will be no problem.

Configuration file:

[root@web1 ~] # grep-v "^ $" / usr/local/sentinel/sentinel.conf | grep-v "^ #"

Bind 0.0.0.0

Port 26379

Dir "/ tmp"

Sentinel myid 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

Sentinel monitor mymaster 192.168.110.135 6379 2

Sentinel config-epoch mymaster 14

Sentinel leader-epoch mymaster 14

Sentinel known-slave mymaster 192.168.110.134 6379

Sentinel known-sentinel mymaster 192.168.110.135 26379 16286f52de2675345d1b11bc8946adc5d3f0c360

Sentinel current-epoch 14

Mainly the following two items:

Bind 0.0.0.0

Sentinel monitor mymaster 192.168.110.135 6379 2

If the password is set, add the following:

# sentinel auth-pass

Sentinel auth-pass def_master 012345 ^ 678-90

[root@web1 ~] # redis-sentinel / usr/local/sentinel/sentinel.conf &

[1] 1963

[root@web1] # 1963 Increased maximum number of open files to X 19 Dec 11 Dec 55 it was originally set to 29.670 * Increased maximum number of open files to 1024.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.2.6 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in sentinel mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 26379 |

| | `-. _`. _ / _. -'| PID: 1963 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

1963:X 19 Dec 11:55:29.671 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

1963:X 19 Dec 11:55:29.671 # Sentinel ID is 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

1963 Dec X 19 quorum 11 55 quorum 29.672 # + monitor master mymaster 192.168.110.134 6379

It says that there is no problem with startup:

Kill drop one from the redis and observe the output information from the sentinel console:

[root@web1 ~] # kill 1912

[root@web1 ~] # ps aux | grep redis

Root 1963 0.2 1.0 133528 2588 pts/0 Sl 11:55 0:00 redis-sentinel 0.0.0.0:26379 [sentinel]

Root 1992 0.00.3 103244 864 pts/0 S+ 11:58 0:00 grep redis

[root@web1 ~] # 1963 Dec X 19 1915 11V 59V 06.906 # + sdown master mymaster 192.168.110.134 6379

1963 Dec X 19 quorum 11 59 quorum 06.963 # + 192.168.110.134 6379 # quorum 2

1963 X 19 Dec 11 59 06.963 # + new-epoch 14

1963 X 19 Dec 11 59 06.963 # + try-failover master mymaster 192.168.110.134 6379

1963 X 19 Dec 11 59 06.972 # + vote-for-leader 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 14

1963:X 19 Dec 11:59:06.992 # 16286f52de2675345d1b11bc8946adc5d3f0c360 voted for 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 14

1963 X 19 Dec 11 59 07.035 # + elected-leader master mymaster 192.168.110.134 6379

1963 X 19 Dec 11 59 07.035 # + failover-state-select-slave master mymaster 192.168.110.134 6379

1963 mymaster X 19 Dec 59 mymaster 07.136 # + 192.168.110.135 mymaster 6379 192.168.110.135 6379 @ 192.168.110.134 6379

1963 mymaster X 19 Dec 59 mymaster 07.136 * + 192.168.110.135 mymaster 6379 192.168.110.135 6379 @ 192.168.110.134 6379

1963 Dec X 19 11 Dec 59 mymaster 07.199 * + failover-state-wait-promotion slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

1963 mymaster X 19 Dec 59 Dec 08.171 # + promoted-slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

1963 X 19 Dec 11 59 08.171 # + failover-state-reconf-slaves master mymaster 192.168.110.134 6379

1963 X 19 Dec 11 59 08.260 # + failover-end master mymaster 192.168.110.134 6379

1963 X 19 Dec 11 59 Dec 08.260 # + switch-master mymaster 192.168.110.134 6379 192.168.110.135 6379

1963 Dec X 19 11 Dec 59 mymaster 08.260 * + 192.168.110.134 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 11 Dec 59 mymaster 38.290 # + 192.168.110.134 6379 @ mymaster 192.168.110.134 6379

The other one:

[root@web2 ~] # redis-sentinel / usr/local/sentinel/sentinel.conf &

[1] 1809

[root@web2] # 1809 Increased maximum number of open files to X 19 Dec 11 Increased maximum number of open files to 11 55 Increased maximum number of open files to 35.698 (it was originally set to 1024).

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.2.6 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in sentinel mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 26379 |

| | `-. _`. _ / _. -'| PID: 1809 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

1809:X 19 Dec 11:55:35.700 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

1809:X 19 Dec 11:55:35.700 # Sentinel ID is 16286f52de2675345d1b11bc8946adc5d3f0c360

1809 Dec X 19 quorum 11 55 quorum 35.700 # + monitor master mymaster 192.168.110.134 6379

1809 Dec X 19 11 59 06.895 # + sdown master mymaster 192.168.110.134 6379

1809 X 19 Dec 11R 59R 06.999 # + new-epoch 14

1809 X 19 Dec 11 59R 07.001 # + vote-for-leader 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 14

1809 Dec X 19 quorum 11 59 Dec 08.020 # + odown master mymaster 192.168.110.134 6379 # quorum 2

1809:X 19 Dec 11:59:08.020 # Next failover delay: I will not start a failover before Mon Dec 19 12:05:07 2016

1809 Dec X 19 11 Dec 59 Dec 08.284 # + config-update-from sentinel 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 192.168.110.134 26379 @ mymaster 192.168.110.134 6379

1809 Dec X 19 11 Dec 59 Dec 08.284 # + switch-master mymaster 192.168.110.134 6379 192.168.110.135 6379

1809 Dec X 19 11 Dec 59 mymaster 08.284 * + slave slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

1809 Dec X 19 11 Dec 59 Dec 38.344 # + sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

[root@web2 ~] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

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

127.0.0.1purl 6379 >

Restore 192.168.110.134:

[root@web1 ~] # redis-server / usr/local/redis/etc/redis.conf

[root@web1 ~] # 1963 sdown slave X 19 Dec 12 sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.135 6379

[root@web1 ~] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:192.168.110.135

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:1

Master_sync_in_progress:0

Slave_repl_offset:38769

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

127.0.0.1purl 6379 >

The display on 135:

Repl_backlog_histlen:0

127.0.0.1 Dec 6379 > 1809 mymaster X 19 12 Dec 1424. 105 #-sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379

127.0.0.1purl 6379 >

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.110.134,port=6379,state=online,offset=2404,lag=1

Master_repl_offset:2404

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:2403

It is also only as from.

2) configure the mode of three Sentinel Sentinel:

[root@web2 ~] # scp redis-3.2.6.tar.gz 192.168.110.133:/root

The authenticity of host '192.168.110.133 (192.168.110.133)' can't be established.

RSA key fingerprint is 60:6c:0d:f4:3b:f8:42:b1:c9:7e:ab:c4:bc:83:d1:09.

Are you sure you want to continue connecting (yes/no)? Yes

Warning: Permanently added '192.168.110.133' (RSA) to the list of known hosts.

Root@192.168.110.133's password:

Redis-3.2.6.tar.gz 100% 1509KB 1.5MB/s 00:00

[root@node2] # iptables-I INPUT 6-m state-- state NEW-p tcp-- dport 6379-j ACCEPT

[root@node2] # iptables-I INPUT 7-m state-- state NEW-p tcp-- dport 26379-j ACCEPT

[root@node2] # tar-zxvf redis-3.2.6.tar.gz-C / usr/local/src/

[root@node2 ~] # cd / usr/local/src/redis-3.2.6/

[root@node2 redis-3.2.6] # make

[root@node2 redis-3.2.6] # make install

Root@node2 redis-3.2.6] # mkdir / etc/redis

[root@node2 redis-3.2.6] # mkdir-p / redis/data

[root@node2 redis-3.2.6] # mkdir-p / redis/log

2. Configure master and slave:

[root@node2 redis-3.2.6] # grep-v "^ $" / etc/redis/redis.conf | grep-v "^ #"

Bind *

Protected-mode yes

Port 6379

Tcp-backlog 511

Timeout 0

Tcp-keepalive 300

Daemonize yes

Supervised no

Pidfile / var/run/redis_6379.pid

Loglevel notice

Logfile "/ redis/log/redis.log"

Databases 16

Save 900 1

Save 300 10

Save 60 10000

Stop-writes-on-bgsave-error yes

Rdbcompression yes

Rdbchecksum yes

Dbfilename dump.rdb

Dir / redis/data

Slaveof 192.168.110.134 6379

Slave-serve-stale-data yes

Slave-read-only yes

Repl-diskless-sync no

Repl-diskless-sync-delay 5

Repl-disable-tcp-nodelay no

Slave-priority 100

Appendonly no

Appendfilename "appendonly.aof"

Appendfsync everysec

No-appendfsync-on-rewrite no

Auto-aof-rewrite-percentage 100

Auto-aof-rewrite-min-size 64mb

Aof-load-truncated yes

Lua-time-limit 5000

Slowlog-log-slower-than 10000

Slowlog-max-len 128

Latency-monitor-threshold 0

Notify-keyspace-events ""

Hash-max-ziplist-entries 512

Hash-max-ziplist-value 64

List-max-ziplist-size-2

List-compress-depth 0

Set-max-intset-entries 512

Zset-max-ziplist-entries 128

Zset-max-ziplist-value 64

Hll-sparse-max-bytes 3000

Activerehashing yes

Client-output-buffer-limit normal 0 0 0

Client-output-buffer-limit slave 256mb 64mb 60

Client-output-buffer-limit pubsub 32mb 8mb 60

Hz 10

Aof-rewrite-incremental-fsync yes

[root@node2 redis-3.2.6] # redis-server / etc/redis/redis.conf

[root@node2 redis-3.2.6] # ps aux | grep redis

Root 4220 0.1 0.9 133524 2312? Ssl 16:36 0:00 redis-server *: 6379

Root 4224 0.00.3 103248 864 pts/0 S+ 16:36 0:00 grep redis

[root@web1 ~] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:2

Slave0:ip=192.168.110.135,port=6379,state=online,offset=325246,lag=0

Slave1:ip=192.168.110.133,port=6379,state=online,offset=325246,lag=0

Master_repl_offset:325246

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:325245

127.0.0.1purl 6379 >

2. Set up sentinels:

[root@node2 redis-3.2.6] # mkdir / etc/sentinel

[root@node2 redis-3.2.6] # cp sentinel.conf / etc/sentinel/

[root@node2 redis-3.2.6] # grep-v "^ $" / etc/sentinel/sentinel.conf | grep-v "^ #"

Bind 0.0.0.0

Port 26379

Dir "/ tmp"

Sentinel myid fd3e2ac303fd06dfa7934718d68429dc88e3b5b8

Sentinel monitor mymaster 192.168.110.134 6379 2

Sentinel config-epoch mymaster 15

Sentinel leader-epoch mymaster 0

Sentinel known-slave mymaster 192.168.110.133 6379

Sentinel known-slave mymaster 192.168.110.135 6379

Sentinel known-sentinel mymaster 192.168.110.135 26379 16286f52de2675345d1b11bc8946adc5d3f0c360

Sentinel known-sentinel mymaster 192.168.110.134 26379 28c5f96738e4fe3335088d037a85ef47dfe9ab8f

Sentinel current-epoch 15

[root@node2 redis-3.2.6] # redis-sentinel / etc/sentinel/sentinel.conf &

[1] 4240

[root@node2 redis-3.2.6] # 4240 Increased maximum number of open files to X 18 Dec 16 root@node2 redis-3.2.6 48 Increased maximum number of open files to 07.492 * Increased maximum number of open files to 1024.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 3.2.6 (00000000Universe 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in sentinel mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 26379 |

| | `-. _`. _ / _. -'| PID: 4240 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

4240:X 18 Dec 16:48:07.494 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

4240:X 18 Dec 16:48:07.494 # Sentinel ID is fd3e2ac303fd06dfa7934718d68429dc88e3b5b8

4240quorum X 18 Dec 16 Dec 48V 07.494 # + monitor master mymaster 192.168.110.134 6379 quorum 2

4240 Dec X 18 Dec 16 Dec 48V 07.499 * + slave slave 192.168.110.135R 6379 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

4240 Dec X 18 Dec 16 48 mymaster 07.515 * + slave slave 192.168.110.133 1979 192.168.110.133 6379 @ mymaster

4240 Dec X 18 Dec 16 Fringe 08.295 * + sentinel sentinel 16286f52de2675345d1b11bc8946adc5d3f0c360 192.168.110.135 26379 @ mymaster 192.168.110.134 6379

4240 X 18 Dec 16 Dec 488.328 # + new-epoch 15

4240 Dec X 18 Dec 16 Velcro 09.420 * + sentinel sentinel 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 192.168.110.134 26379 @ mymaster 192.168.110.134 6379

[root@node2 redis-3.2.6] # ps aux | grep redis

Root 4220 0.2 1.0 133524 2408? Ssl 16:36 0:03 redis-server *: 6379

Root 4240 0.3 1.1 133528 2696 pts/0 Sl 16:48 0:02 redis-sentinel 0.0.0.0:26379 [sentinel]

Root 4264 0.00.3 103248 860 pts/0 S+ 17:01 0:00 grep redis

[root@web2] # redis-cli-p 26379

127.0.0.1purl 26379 > info

.... .

# 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=192.168.110.134:6379,slaves=2,sentinels=2

127.0.0.1 Dec 26379 > 1809 mymaster X 19 mymaster 14 mymaster 59 mymaster 24.984 * + mymaster 192.168.110.133 6379

127.0.0.1purl 26379 >

127.0.0.1purl 26379 > info

# Server

Redis_version:3.2.6

Redis_git_sha1:00000000

Redis_git_dirty:0

Redis_build_id:2f0dd1a83d7e7010

Redis_mode:sentinel

Os:Linux 2.6.32-431.el6.x86_64 x861464

Arch_bits:64

Multiplexing_api:epoll

Gcc_version:4.4.7

Process_id:1809

Run_id:519043c8b9e7314a71c425400d01769b3384f77c

Tcp_port:26379

Uptime_in_seconds:11045

Uptime_in_days:0

Hz:11

Lru_clock:5735772

Executable:/root/redis-sentinel

Config_file:/usr/local/sentinel/sentinel.conf

# Clients

Connected_clients:3

Client_longest_output_list:0

Client_biggest_input_buf:0

Blocked_clients:0

# CPU

Used_cpu_sys:26.71

Used_cpu_user:2.31

Used_cpu_sys_children:0.00

Used_cpu_user_children:0.00

# Stats

Total_connections_received:3

Total_commands_processed:16011

Instantaneous_ops_per_sec:4

Total_net_input_bytes:937405

Total_net_output_bytes:97572

Instantaneous_input_kbps:0.26

Instantaneous_output_kbps:0.02

Rejected_connections:0

Sync_full:0

Sync_partial_ok:0

Sync_partial_err:0

Expired_keys:0

Evicted_keys:0

Keyspace_hits:0

Keyspace_misses:0

Pubsub_channels:0

Pubsub_patterns:0

Latest_fork_usec:0

Migrate_cached_sockets:0

# 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=192.168.110.134:6379,slaves=2,sentinels=3

127.0.0.1purl 26379 >

[root@node2 redis-3.2.6] # redis-cli-p 26379

127.0.0.1purl 26379 > info

# Server

Redis_version:3.2.6

Redis_git_sha1:00000000

Redis_git_dirty:0

Redis_build_id:98c29634d36aff37

Redis_mode:sentinel

Os:Linux 2.6.32-431.el6.x86_64 x861464

Arch_bits:64

Multiplexing_api:epoll

Gcc_version:4.4.7

Process_id:4240

Run_id:d0cf3dbc5259fa960ccf02ed101bc69bd878e26d

Tcp_port:26379

Uptime_in_seconds:630

Uptime_in_days:0

Hz:10

Lru_clock:5656509

Executable:/usr/local/src/redis-3.2.6/redis-sentinel

Config_file:/etc/sentinel/sentinel.conf

# Clients

Connected_clients:3

Client_longest_output_list:0

Client_biggest_input_buf:0

Blocked_clients:0

# CPU

Used_cpu_sys:1.88

Used_cpu_user:0.12

Used_cpu_sys_children:0.00

Used_cpu_user_children:0.00

# Stats

Total_connections_received:3

Total_commands_processed:1819

Instantaneous_ops_per_sec:2

Total_net_input_bytes:106447

Total_net_output_bytes:10937

Instantaneous_input_kbps:0.25

Instantaneous_output_kbps:0.01

Rejected_connections:0

Sync_full:0

Sync_partial_ok:0

Sync_partial_err:0

Expired_keys:0

Evicted_keys:0

Keyspace_hits:0

Keyspace_misses:0

Pubsub_channels:0

Pubsub_patterns:0

Latest_fork_usec:0

Migrate_cached_sockets:0

# 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=192.168.110.134:6379,slaves=2,sentinels=3

[root@node2 redis-3.2.6] # redis-cli

127.0.0.1 purl 6379 > get name

"zhangsan"

127.0.0.1 purl 6379 > get age

"20"

127.0.0.1 purl 6379 > get age1

(nil)

127.0.0.1 purl 6379 > get age2

"22"

127.0.0.1purl 6379 >

Downtime the main library of 192.168.110.134:

[root@web1 ~] # ps aux | grep redis

Root 1963 0.2 1.1 133528 2716 pts/0 Sl 11:55 0:31 redis-sentinel 0.0.0.0:26379 [sentinel]

Root 2068 0.1 1.4 135572 3468? Ssl 12:14 0:20 redis-server *: 6379

Root 2817 0.00.3 103244 864 pts/0 S+ 15:11 0:00 grep redis

[root@web1 ~] # kill 2068

[root@web1 ~] # ps aux | grep redis

Root 1963 0.2 1.1 133528 2716 pts/0 Sl 11:55 0:31 redis-sentinel 0.0.0.0:26379 [sentinel]

Root 2826 0.00.3 103244 864 pts/0 S+ 15:13 0:00 grep redis

[root@web1] # 1963 sdown master mymaster X 19 Dec 15 sdown master mymaster 13 44.721 # + 192.168.110.134 6379

1963 quorum X 19 Dec 15 quorum 13 quorum 44.776 # + 192.168.110.134 # 192.168.110.134

1963 X 19 Dec 15 13 44.776 # + new-epoch 16

1963 Dec X 19 15 13 44.776 # + try-failover master mymaster 192.168.110.134 6379

1963 X 19 Dec 15 13 44.778 # + vote-for-leader 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 16

1963:X 19 Dec 15:13:44.797 # fd3e2ac303fd06dfa7934718d68429dc88e3b5b8 voted for 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 16

1963:X 19 Dec 15:13:44.804 # 16286f52de2675345d1b11bc8946adc5d3f0c360 voted for 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 16

1963 Dec X 19 15 13 44.855 # + elected-leader master mymaster 192.168.110.134 6379

1963 Dec X 19 15 13 44.855 # + failover-state-select-slave master mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 mymaster 44.956 # + 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 14 44.956 * + failover-state-send-slaveof-noone slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 mymaster 45.023 * + failover-state-wait-promotion slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 mymaster 45.898 # + promoted-slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 13 Dec 45.898 # + failover-state-reconf-slaves master mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 mymaster 45.963 * + slave-reconf-sent slave 192.168.110.133 1979 192.168.110.133 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 mymaster 46.107 * + 192.168.110.133 slave-reconf-inprog slave 6379 192.168.110.133 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 13 46.911 #-odown master mymaster 192.168.110.134 6379

Slave-reconf-done slave 192.168.110.133 Dec 6379 192.168.110.133 6379 @ mymaster 192.168.110.134 6379

1963 X 19 Dec 15 13 47.212 # + failover-end master mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 13 47.212 # + switch-master mymaster 192.168.110.134 6379 192.168.110.135 6379

1963 Dec X 19 15 Dec 13 mymaster 47.213 * + 192.168.110.133 1979 192.168.110.133 6379 @ mymaster 192.168.110.135 6379

1963 Dec X 19 15 Dec 13 mymaster 47.213 * + 192.168.110.134 6379 @ mymaster 192.168.110.134 6379

1963 Dec X 19 15 Dec 14 mymaster 17.223 # + 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ 192.168.110.134 6379

135 has become the main library:

[root@web2 ~] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:1

Slave0:ip=192.168.110.133,port=6379,state=online,offset=27695,lag=0

Master_repl_offset:27695

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:27694

127.0.0.1 purl 6379 > quit

[root@node2 redis-3.2.6] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:192.168.110.135

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:0

Master_sync_in_progress:0

Slave_repl_offset:21626

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

127.0.0.1purl 6379 >

Another 135:

[root@web2 ~] # ps aux | grep redis

Root 1809 0.2 1.1 133528 2764 pts/0 Sl 11:55 0:32 redis-sentinel 0.0.0.0:26379 [sentinel]

Root 2390 0.2 1.1 135572 2872? Ssl 14:11 0:08 redis-server *: 6379

Root 2675 0.00.3 103244 860 pts/0 S+ 15:16 0:00 grep redis

[root@web2 ~] # kill 2390

[root@web2 ~] # ps aux | grep redis

Root 1809 0.2 1.1 133528 2768 pts/0 Sl 11:55 0:32 redis-sentinel 0.0.0.0:26379 [sentinel]

Root 2677 0.00.2 103216 640 pts/0 R + 15:17 0:00 grep redis

[root@web2] # 1809 sdown master mymaster X 19 Dec 15V 1731.230 # + sdown master mymaster 192.168.110.135 6379

1809 X 19 Dec 15 1731.271 # + new-epoch 17

1809 X 19 Dec 15 1731.286 # + vote-for-leader 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 17

1809 quorum X 19 Dec 15 Dec 1731.302 # + odown master mymaster 192.168.110.135 6379 # quorum 3

1809:X 19 Dec 15:17:31.302 # Next failover delay: I will not start a failover before Mon Dec 19 15:23:31 2016

1809 Dec X 19 15 mymaster 17 Dec 32.002 # + config-update-from sentinel 28c5f96738e4fe3335088d037a85ef47dfe9ab8f 192.168.110.134 26379 @ mymaster 192.168.110.135 6379

1809 Dec X 19 15 Dec 17 32.003 # + switch-master mymaster 192.168.110.135 6379 192.168.110.133 6379

1809 Dec X 19 15 Dec 17 mymaster 32.003 * + slave slave 192.168.110.1341979 192.168.110.134 6379 @ mymaster

1809 Dec X 19 15 Dec 17 mymaster 32.003 * + slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.133

1809 Dec X 19 15 Dec 18 02.004 # + sdown slave 192.168.110.134 6379 @ mymaster 192.168.110.134 6379 @ mymaster

1809 Dec X 19 15 Dec 18 mymaster 02.004 # + sdown slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.133

133 set up the main library:

127.0.0.1purl 6379 >

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

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

127.0.0.1purl 6379 >

[root@web1 ~] # redis-server / usr/local/redis/etc/redis.conf

[root@web1 ~] # 1963 sdown slave X 19 Dec 15 sdown slave 47.745 #-192.168.110.134 6379 @ mymaster 192.168.110.133 6379

Convert-to-slave slave 192.168.110.134Dec 6379 192.168.110.134 6379 @ mymaster 192.168.110.133 6379

[root@web2 ~] # redis-server / etc/redis.conf

[root@web2] # 1809 sdown slave X 19 Dec 15 sdown slave 2234.441 #-192.168.110.135sdown slave 6379 192.168.110.135 6379 @ mymaster 192.168.110.133 6379

1809 Dec X 19 15 Dec 22 mymaster 44.421 * + convert-to-slave slave 192.168.110.135 1979 192.168.110.135 6379 @ mymaster 192.168.110.133 6379

Viewed on 133:

127.0.0.1 Dec 6379 > 4240 mymaster X 18 17V 11V 18.953 #-sdown slave 192.168.110.135Vera 6379 192.168.110.135 6379 @ mymaster 192.168.110.133 6379

127.0.0.1purl 6379 >

127.0.0.1 purl 6379 > info replication

# Replication

Role:master

Connected_slaves:2

Slave0:ip=192.168.110.134,port=6379,state=online,offset=24323,lag=1

Slave1:ip=192.168.110.135,port=6379,state=online,offset=24470,lag=0

Master_repl_offset:24470

Repl_backlog_active:1

Repl_backlog_size:1048576

Repl_backlog_first_byte_offset:2

Repl_backlog_histlen:24469

127.0.0.1purl 6379 >

[root@web1 ~] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:192.168.110.133

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:0

Master_sync_in_progress:0

Slave_repl_offset:113832

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

127.0.0.1purl 6379 >

[root@web2 ~] # redis-cli

127.0.0.1 purl 6379 > info replication

# Replication

Role:slave

Master_host:192.168.110.133

Master_port:6379

Master_link_status:up

Master_last_io_seconds_ago:1

Master_sync_in_progress:0

Slave_repl_offset:122708

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

127.0.0.1purl 6379 >

Introduction to some commands of sentinel

To use the sentinel command, we need to enter the sentinel using the redis-cli command:

1 、 INFO

Basic status information of sentinel

2 、 SENTINEL masters

Lists all primary servers being monitored and the current status of these primary servers

3 、 SENTINEL slaves

Lists all slave servers for a given master server and the current status of these slave servers

4 、 SENTINEL get-master-addr-by-name

Returns the IP address and port number of the primary server with the given name

5 、 SENTINEL reset

Resets all primary servers whose names match the given pattern pattern. The reset operation clears all the current state of the master server, including the failover in progress, and removes all slaves and Sentinel of the master server that have been discovered and associated.

6 、 SENTINEL failover

When the primary server fails, force an automatic failover without asking other Sentinel comments, but it will send the other sentinel an up-to-date configuration, and the other sentinel will update according to this configuration

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

Servers

Wechat

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

12
Report