In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
Sentinel (Sentinel) is a tool for monitoring the status of Master in redis clusters. It has been integrated into the version of redis2.4+. Let's take a look at the detailed introduction.
1. Sentinel sentinel
Sentinel (Sentinel) is a high availability solution for Redis: a Sentinel system consisting of one or more Sentinel instances can monitor any number of master servers and all slave servers under these master servers, and automatically upgrade one of the slave servers under the offline master server to a new master server when the monitored master server goes offline.
For example:
After the Server1 is offline:
Upgrade Server2 to the new primary server:
2. Separation of master and slave of Redis
Before we talk about the Sentinel Sentinel cluster, let's build a simple master-slave separation (read-write separation).
First of all, we default that everyone has installed redis, and then we make multiple copies of redis.conf and create multiple directories to distinguish multiple redis services:
Here, each directory has its own redis.conf configuration file. Next, let's set up the configuration file for the master server.
1. Configure Master
1. Modify the port
# Accept connections on the specified port, default is 6379 (IANA # 815344). # If port 0 is specified Redis will not listen on a TCP socket.port 6380
The default port of redis is 6379, here we set the port of the primary server to 6380
2. Modify pidfile
# If a pid file is specified, Redis writes it where specified at startup# and removes it at exit.## When the server runs non daemonized, no pid file is created if none is# specified in the configuration. When the server is daemonized, the pidfile # is used even if not specified, defaulting to "/ var/run/redis.pid". # # Creating a pidfile is best effort: if Redis is not able to create it# nothing bad happens, the server will start and run normally.pidfile / var/run/redis_6380.pid
Pidfile is a pid process number assigned to us by linux when we start redis. If no changes are made here, it will affect the startup of the redis service.
3. Start redis
Start redis, and we can see that redis has occupied port 6380.
Enter the client
Redis-cli-p 6380127.0.0.1 6380 > info...# Replicationrole:masterconnected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0...
As we can see, the current role of redis is a service started by master.
2. Configure Slave
As with configuring master above, we need to modify the port number and pid file. After modification, we have two ways to configure the slave service.
1. Configure the slave service in the configuration file
# # REPLICATION # # Master-Slave replication. Use slaveof to make a Redis instance a copy of# another Redis server. A few things to understand ASAP about Redis replication.## 1) Redis replication is asynchronous, but you can configure a master to# stop accepting writes if it appears to be not connected with at least# a given number of slaves.# 2) Redis slaves are able to perform a partial resynchronization with the# master if the replication link is lost for a relatively small amount of# time. You may want to configure the replication backlog size (see the next# sections of this file) with a sensible value depending on your needs.# 3) Replication is automatic and does not need user intervention. After a# network partition slaves automatically try to reconnect to masters# and resynchronize with them.## slaveof slaveof 127.0.0.1 6380
We can modify the slaveof property directly in the configuration file. We can directly configure the ip address and port number of the master server, if the master server has a configuration password.
You can set the link password by configuring masterauth
# If the master is password protected (using the "requirepass" configuration# directive below) it is possible to tell the slave to authenticate before# starting the replication synchronization process, otherwise the master will# refuse the slave request.## masterauth
Start the redis service:
We can see that there are two running now. Let's go to the client of 6381 and take a look at his status.
# Replicationrole:slavemaster_host:127.0.0.1master_port:6380master_link_status:upmaster_last_io_seconds_ago:1master_sync_in_progress:0slave_repl_offset:71slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
As we can see, redis is now a slave service role, connecting 6380 of the services.
2. Set up after the service is started
After we modify the server configuration file for port 6382, start the service
Enter the client to view the status of the current server:
# Replicationrole:masterconnected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
We can see that the current state of the server is running as the role of a master service, and we next modify its state:
127.0.0.1 slaveof 6382 > 127.0.0.1 6380max / modified status # Replicationrole:slavemaster_host:127.0.0.1master_port:6380master_link_status:upmaster_last_io_seconds_ago:1master_sync_in_progress:0slave_repl_offset:617slave_priority:100slave_read_only:1connected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0
3. Summary
Let's first take a look at the current status of master:
# Replicationrole:masterconnected_slaves:2slave0:ip=127.0.0.1,port=6381,state=online,offset=785,lag=0slave1:ip=127.0.0.1,port=6382,state=online,offset=785,lag=0master_repl_offset:785repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:784
We can see that the two slave services are already connected to the master server. The difference between the above two configurations is that when the salve is disconnected and reconnected,
If we modify the class configuration file, we will link to master ourselves after reconnection, and synchronize the data on master.
If we are manually connected to the master server, after reconnecting, the slave server will read its own local rdb reply data instead of automatically linking the master service.
If we need to set up read-write separation, we only need to set it in the main server:
# Note: read only slaves are not designed to be exposed to untrusted clients# on the internet. It's just a protection layer against misuse of the instance.# Still a read only slave exports by default all the administrative commands# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve# security of read only slaves using 'rename-command' to shadow all the# administrative / dangerous commands.slave-read-only yes
3. Sentinel Sentinel
1. Configure the port
In the sentinel.conf configuration file, we can find the port attribute. Here is the port used to set the sentinel. In general, at least three sentinels are needed to monitor the redis. We can start multiple sentinel services by modifying the port.
# Note: read only slaves are not designed to be exposed to untrusted clients# on the internet. It's just a protection layer against misuse of the instance.# Still a read only slave exports by default all the administrative commands# such as CONFIG, DEBUG, and so forth. To a limited extent you can improve# security of read only slaves using 'rename-command' to shadow all the# administrative / dangerous commands.slave-read-only yes
2. Configure the ip and port of the master server
We modify the listening port to 6380 and add a weight of 2, which is used to calculate which server we need to upgrade to the master server.
# sentinel monitor # # Tells Sentinel to monitor this master, and to consider it in O_DOWN# (Objectively Down) state only if at least sentinels agree.## Note that whatever is the ODOWN quorum, a Sentinel will require to# be elected by the majority of the known Sentinels in order to# start a failover, so no failover can be performed in minority.## Slaves are auto-discovered, so you don't need to specify slaves in# any way. Sentinel itself will rewrite this configuration file adding# the slaves using additional configuration options.# Also note that the configuration file is rewritten when a # slave is promoted to master.## Note: master name should not include special characters or spaces.# The valid charset is Amurz 0-9 and the three characters ".-_" .sentinel monitor mymaster 127.0.0.1 6380 2
3. Start Sentinel
/ sentinel$ redis-sentinel sentinel.conf
After sentinel starts, it will monitor that there is now one master server and two slave servers.
When we close one of them from the server, we can see the log:
10894VR X 30 Dec 16 Dec 27UR 03.670 # + sdown slave 127.0.0.1 mymaster 6381 127.0.0.1 6381 @ mymaster
The log says that the 6381 slave server has been detached from the master server, and we reconnect the 6381.
10894mymaster X 30 Dec 16 Dec 28 Dec 43.288 * + 127.0.0.1 mymaster 127.0.0.1 mymaster 127.0.0.1 @ mymaster 127.0.0.1
4. Close Master
After we manually shut down Master, sentinel will start calculating weights after listening that master is indeed disconnected, and then reassign the primary server
We can see that after the 6380 primary server was down, sentinel selected 6382 as the new primary server for us.
We go to the client of 6382 and check his status:
# Replicationrole:masterconnected_slaves:1slave0:ip=127.0.0.1,port=6381,state=online,offset=13751,lag=0master_repl_offset:13751repl_backlog_active:1repl_backlog_size:1048576repl_backlog_first_byte_offset:2repl_backlog_histlen:13750
We can see that 6382, heavy slave has been promoted to master.
127.0.0.1 purl 6382 > set name jaycekonOK
The original one had no permission to write, and also got the corresponding permission.
5. Reconnect Master
People may wonder if master will take back his position after reconnection, the answer is no, for example, if you are robbed of your boss position by a younger brother, will he give you back this position? So when master comes back, he can only be a little brother.
4. Sentinel summary
First, the role of Sentinel:
A, Master condition monitoring
B. if Master is abnormal, Master-slave conversion is performed, with one of the Slave as the Master and the previous Master as the Slave
After switching between C and Master-Slave, 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.
Second, the working mode of Sentinel:
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.
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.