In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you the method of fault detection in Redis cluster. I hope you will gain a lot after reading this article. Let's discuss the method together.
The method of fault detection in Redis cluster: first, modify the Python script to write a piece of data every 1 second; then write data to the Redis cluster and force a master node to observe the application connection; finally, restart the 8001 nodes that are down.
Method of fault detection in Redis cluster: automatic failover test
Modify the Python script to write a piece of data every 1s in order to observe the impact on the application during the period of primary node downtime and cluster automatic failover (about 1s), or the performance of the application before and after automatic failover.
The following script writes data to the Redis cluster in a loop, forcing a master node to be killed during execution to observe the application connection.
At the same time, if an exception occurs, pause the application 2s, because the cluster failover time configured above is 1s. If the application pauses 2s, you can skip the failover process. After the failover is completed, the application returns to the normal state. Although 8001 nodes are down and the application continues to connect to 8001 nodes, the application is completely unaware of it.
Import timefrom time import ctime,sleepfrom rediscluster import StrictRedisClusterstartup_nodes = [{"host": "111.231.253.stories *", "port": 8001}, {"host": "111.231.253.stories *", "port": 8002}, {"host": "111.231.253.stories *", "port": 8003}, {"host": "111.231.253.questions *", "port": 8004} {"host": "111.231.253.clients *", "port": 8005}, {"host": "111.231.253.clients *", "port": 8006}] redis_conn= StrictRedisCluster (startup_nodes=startup_nodes, decode_responses=True,password= "root") for i in range (0, 100000): try: redis_conn.set ('name' + str (I)) Str (I)) print ('setting name' + str (I) + "-->" + time.strftime ('% Y-%m-%d% HGV% MRV% time.sleep (1) except: print ("connect to redis cluster error") time.sleep (2)
It is found that there is only one connection error after killing the master node, and then because the automatic failover of the Redis cluster is successful, the program is transparent, so the application then works normally and is not affected by the downtime of one of the master nodes.
In the state of the cluster at this time, 8001 nodes are down, obviously, 8004 of the slave node corresponding to 8001 takes over the master node, upgrades to master, and provides external services.
Observing the 8004 instance log of the upgraded primary node, you will find that after the original 8001 primary node was forcibly killed, it was successfully upgraded to the master node instead of 8001 within 1 second.
If no application accesses Redis during the failover process, the application does not even know that the Redis cluster has failed over. As long as the master and slave nodes of one of the nodes in the cluster do not go down at the same time, the whole cluster will be fine and completely transparent to the application.
Then restart the 8001 nodes, you will find that the 8001 nodes automatically become the slave nodes of their original slave node (8004).
After reading this article, I believe you have a certain understanding of Redis cluster fault detection methods, want to know more related knowledge, welcome to follow the industry information channel, thank you for reading!
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.