In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "redis master-slave distributed implementation", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn the "redis master-slave distributed implementation"!
1. Test environment
Master: 127.0.0.1 6379
Slave1: 127.0.0.1 6479
Slave2: 127.0.0.1 6579
Master-sentinel: 127.0.0.1 26379
Slave1-sentinel: 127.0.0.1 26479
Slave2-sentinel: 127.0.0.1 26579
two。 Download and install redis 2.8.3
Cd
Wget http://download.redis.io/releases/redis-2.8.3.tar.gz
Tar-zxvf redis-2.8.3.tar.gz
Cd redis-2.8.3
Make;make install (here you can install redis to another directory with the PREFIX parameter)
3. Configure the test environment
-create a directory:
Cd / usr/local
Mkdir redis_cluster
Mkdir redis_cluster/master_6379
Mkdir redis_cluster/slave_6479
Mkdir redis_cluster/slave_6579
-configure redis:
Master:
Cp-a-R-p ~ / redis-2.8.3/redis.conf. / redis_cluster/master_6379/
Cp-a-R-p ~ / redis-2.8.3/sentinel.conf. / redis_cluster/master_6379/6379-sentinel.conf
Vi. / redis_cluster/master_6379/redis.conf (modify the corresponding configuration as follows)
-
# master redis.conf
# Port
Port 6379
# Authorization password can not be set in a secure environment
Requirepass luyx30
Masterauth luyx30
# rename the comment instruction, which does not need to be modified if it has been configured
# rename-command
# enable AOF
Appendonly yes
Save ""
Slave-read-only yes
-
Vi. / redis_cluster/master_6379/6379-sentinel.conf
-
# master sentinel.conf
# # Communication Port between sentinel instances
Port 26379
# master information to be monitored by sentinel:.
# should be less than the number of slave in the cluster. Only when at least one sentinel instance submits "master failure" will it be considered as ODWON ("objective" failure).
Sentinel monitor mymaster 127.0.0.1 6379 2
# Authorization password can not be set in a secure environment
Sentinel auth-pass mymaster luyx30
# the interval between master being recognized as "SDOWN" by the current sentinel instance
Sentinel down-after-milliseconds mymaster 30000
# when a new master is generated, the number of slave that "slaveof" to the new master and replicate synchronously at the same time.
# # when salve performs salveof and synchronization, the client request will be terminated.
# # this value is larger, which means that the sum of the time taken by the "cluster" to terminate client requests is larger.
# # this value is small, which means that during the failover period, multiple salve still use old data when providing services to clients.
Sentinel parallel-syncs mymaster 1
# failover expiration time. When the failover starts, no failover operation is triggered within this time. The current sentinel will consider this failoer failed.
Sentinel failover-timeout mymaster 900000
-
Slave1:
Cp-a-R-p ~ / redis-2.8.3/redis.conf. / redis_cluster/slave_6479/
Cp-a-R-p ~ / redis-2.8.3/sentinel.conf. / redis_cluster/slave_6479/6479-sentinel.conf
Vi. / redis_cluster/slave_6479/redis.conf (modify the corresponding configuration as follows)
-
# slave1 redis.conf
Port 6479
Slaveof 127.0.0.1 6379
# #-other configurations are consistent with master redis.conf-# #
-
Vi. / redis_cluster/slave_6479/6479-sentinel.conf
-
# slave1 sentinel.conf
Port 26479
# #-other configurations are consistent with master sentinel.conf-# #
-
Slave2:
Cp-a-R-p ~ / redis-2.8.3/redis.conf. / redis_cluster/slave_6579/
Cp-a-R-p ~ / redis-2.8.3/sentinel.conf. / redis_cluster/slave_6579/6579-sentinel.conf
Vi. / redis_cluster/slave_6579/redis.conf (modify the corresponding configuration as follows)
-
# slave1 redis.conf
Port 6579
Slaveof 127.0.0.1 6379
# #-other configurations are consistent with master redis.conf-# #
-
Vi. / redis_cluster/slave_6579/6579-sentinel.conf
-
# slave1 sentinel.conf
Port 26579
# #-other configurations are consistent with master sentinel.conf-# #
-
-start viewing:
Note: when you build a sentinel environment for the first time, you must first start master.
Start master and master-sentinel:
Redis-server-include / usr/local/redis_cluster/master-6379/redis.conf
Redis-sentinel / usr/local/redis_cluster/master-6379/6379-sentinel.conf
Clone session, start slave1 and slave1-sentinel:
Redis-server-include / usr/local/redis_cluster/slave-6479/redis.conf
Redis-sentinel / usr/local/redis_cluster/slave-6479/6479-sentinel.conf
Clone session, start slave2 and slave2-sentinel:
Redis-server-include / usr/local/redis_cluster/slave-6579/redis.conf
Redis-sentinel / usr/local/redis_cluster/slave-6579/6579-sentinel.conf
View the status of master:
Redis-cli-h 127.0.0.1-p 6379
View the status of slave:
Redis-cli-h 127.0.0.1-p 6479
4. Test:
-1:slave downtime in the scenario
Turn off slave1:
View sentinel status:
View the Replication information of master:
There is only one slave at this time.
-scene 2:slave recovery
Reopen slave1:
Redis-server / usr/local/redis_cluster/slave-6479/redis.conf
View sentinel status:
Sentinel can quickly discover that slave is added to the cluster:
View the Replication information of master:
-3:master downtime in the scenario
Master- sentinel, as the leader of master 1, selects a slave of master 1 as the new master. The selection of slave is based on a priority to judge the situation of DNS, and the same priority is obtained through the ranking of runid, but the priority setting has not been realized yet, so we can get slave 1 by directly getting runid ranking.
Then send the command slaveof no one to cancel the slave state of slave 1 to transition to master. When other sentinel observes that the slave becomes master, they know that the error handling routine starts. Sentinel A then sends other slave slaveof new-slave-ip-port commands, and when all slave is configured, sentinel A removes the faulty master from the list of monitored masters, and then notifies the other sentinels.
Turn off master:
View sentinel status:
6379-sentinel:
Automatically switch slave2, that is, 6579, to master, and the original master becomes slave.
6579-sentinel:
Shows the process of failover:
-scene 4:master recovery
Restart the original master:
Redis-server / usr/local/redis_cluster/master-6379/redis.conf
View sentinel status:
The original master is automatically switched to slave, and will not be automatically restored to master:
The test is complete.
Note: if you restart old master before sentinel has selected a new master but has not completed the reconfigure of other instances, an exception that cannot select new master will occur in the whole system.
At this point, I believe you have a deeper understanding of the "redis master-slave distributed implementation". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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: 256
*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.