None of these 4 commonly used operation and maintenance tools for Redis? What kind of operator are you?
When we apply Redis , we often face the operation and maintenance work, including Redis , data migration, deployment and operation and maintenance of master-slave clusters and sliced clusters. Next, I will introduce some tools to you from these three aspects.
Let's first learn the tools to monitor the real-time running status of Redis. These tools use a monitoring command provided by Redis: INFO.
The most basic monitoring command: INFO command
The INFO command provided by Redis itself will return rich instance running monitoring information. This command is the basis of the Redis monitoring tool.
When using the INFO command, you can take a parameter section. There are several values for this parameter. Correspondingly, the INFO command will also return different types of monitoring information. I divided the return information of the INFO command into 5 categories, some of which contain different monitoring contents, as shown in the following table:
The results returned by the INFO command are useful when monitoring the Redis If you want to know the detailed meaning of all the parameters returned by the INFO command, you can check the introduction of Redis official website.
Here, I will give you a few parameters that you need to focus on during operation and maintenance and their important return results.
First of all, whether you are running a single instance or a cluster, I suggest you focus on the return results of the four parameters stat, commandstat, cpu and memory, which include the execution of the command (such as the number of executions and the execution time of the command). , CPU resources used by commands), memory resource usage (such as memory usage, memory fragmentation rate), CPU resource usage, etc., which can help us judge the running status and resource consumption of the instance.
In addition, when you enable the RDB or AOF function, you need to focus on the return result of the persistence parameter, through which you can view the execution of the RDB or AOF.
If you are using a master-slave cluster, you should focus on the return result of the replication parameter, which includes the real-time status of master-slave synchronization.
However, the INFO command only provides monitoring results in the form of text, without visualization. Therefore, in practical applications, we can also use some third-party open source tools to visualize the return results of the INFO command. Next, I will talk about Prometheus, which can visualize the statistical results of Redis through plug-ins. Redis performance indicator monitoring! Do you know geometry?
Redis-exporter monitoring for Prometheus
Prometheus is an open source system monitoring and alerting framework. Its core function is to pull monitoring data from the monitored system and combine it with the Grafana tool for visual display.
Moreover, the monitoring data can be saved in the time series database, so that the operation and maintenance personnel can perform historical query. At the same time, Prometheus will detect whether the monitoring indicators of the system exceed the preset threshold. Once the threshold is exceeded, Prometheus will trigger an alarm.
These functions are very important for the daily operation and maintenance management of the system. And Prometheus has implemented a tool framework to use these functions. As long as we can obtain monitoring data from the monitored system, we can use Prometheus to implement operation and maintenance monitoring.
Prometheus just provides the plug-in function to monitor a system. We call the plug-in exporter. Each exporter is actually a component that collects monitoring data. The data format collected by the exporter meets the requirements of Prometheus. After Prometheus obtains the data, it can be displayed and saved.
Redis-exporter is used to monitor Redis. It provides the running status and various statistical information monitored by the INFO command to Prometheus for visual display and alarm settings. At present, Redis-exporter can support Redis 2.0 to 6.0 versions, and the scope of application is relatively wide.
In addition to obtaining the running status of the Redis instance, Redis-exporter can also monitor the size of key-value pairs and the number of elements of collection type data. This can be achieved by using the check-keys command line option when running Redis-exporter.
In addition, we can develop a Lua script to customize the collection of data to be monitored. Then, we use the scripts command line option to let Redis-exporter run this specific script, which can meet the diverse monitoring needs of the business layer.
Finally, I would like to share with you two more gadgets: redis-stat and Redis Live. Compared with Redis-exporter, both of these are lightweight monitoring tools. They are developed in Ruby and Python respectively, and also visualize the running status information of the instance provided by the INFO command.
Although these two tools have rarely been updated, they are good references if you want to develop your own Redis monitoring tools.
In addition to monitoring the running status of Redis, another common operation and maintenance task is data migration. Next, let's learn about the tools for data migration.
Data migration tool Redis-shake
Sometimes, we need to migrate data between different instances. At present, a commonly used data migration tool is Redis-shake, which is a tool developed by Alibaba Cloud Redis and MongoDB teams for Redis data synchronization.
The basic operating principle of Redis-shake is to start the Redis-shake process first, which simulates a Redis instance.
Then, the Redis-shake process and the source instance from which the data is migrated perform full data synchronization.
This process is similar to the full synchronization of Redis master-slave instances.
The source instance is equivalent to the main library, and Redis-shake is equivalent to the slave library. The source instance first transmits the RDB file to Redis-shake, and Redis-shake will send the RDB file to the destination instance. Then, the source instance will send incremental commands to Redis-shake, and Redis-shake is responsible for resynchronizing these incremental commands to the destination instance.
The following picture shows the process of data migration with Redis-shake:
One of the great advantages of Redis-shake is that it supports multiple types of migrations.
First, it supports both data migration between individual instances and cluster-to-cluster data migration.
Secondly, some Redis slicing clusters (such as Codis) will use proxy to receive request operations, and Redis-shake also supports data migration with proxy.
In addition, because Redis-shake is developed by the Alibaba Cloud team, in addition to supporting the open-source Redis version, Redis-shake also supports the migration of Redis instances under the cloud and Redis instances on the cloud, which can help us realize the Redis service on the cloud The goal.
After data migration, we usually need to compare whether the data in the source instance and the destination instance are consistent. If there are inconsistent data, we need to find them out, remove them from the target instance, or migrate the inconsistent data again.
Here, I will introduce you another tool for data consistency comparison, which is Redis-full-check developed by the Alibaba Cloud team.
The working principle of Redis-full-check is very simple, which is to perform a full comparison of the data in the source instance and the destination instance to complete data verification. However, in order to reduce the comparison overhead of data verification, Redis-full-check adopts the method of multiple rounds of comparison.
- In the first round of verification, Redis-full-check will find all the keys on the source instance, and then find out the corresponding values from the source instance and the destination instance for comparison. After the first comparison, Redis-full-check will record the inconsistent data in the destination instance and the source instance into the sqlite database.
- Starting from the second round of verification, Redis-full-check only compares the inconsistent data recorded in the database after the previous round.
In order to avoid affecting the normal request processing of the instance, Redis-full-check will pause for a period of time after each round of comparison. As the incremental synchronization of Redis-shake progresses, the inconsistent data between the source instance and the destination instance will gradually decrease, so we don't need many rounds of verification and comparison.
We can set the number of rounds of comparison by ourselves. The specific method is to set the value of the parameter comparetimes to the number of rounds we want to compare when running the Redis-full-check command.
After all rounds are compared, the data recorded in the database is the final difference result between the source instance and the destination instance.
One thing to note here is that Redis-full-check provides three comparison modes, which we can set through the comparemode parameter. The comparemode parameter has three values, the meanings are as follows:
- KeyOutline , only compares whether the key values are equal;
- ValueOutline , only compares the length of the value value to be equal;
- FullValue , which compares the key value, value length, and value if they are equal.
When we apply Redis-full-check, we can choose the corresponding comparison mode according to the requirements of the business on the degree of data consistency. If consistency is high, set the comparemode parameter to FullValue.
Well, finally, I will introduce to you CacheCloud, a tool for Redis cluster operation and maintenance management.
Cluster management tool CacheCloud
CacheCloud is a cloud platform developed by Sohu for Redis operation and maintenance management. It realizes the automatic deployment and management of master-slave clusters, sentinel clusters and Redis clusters. Users can operate directly on the management interface of the platform.
For common cluster operation and maintenance requirements, CacheCloud provides five operation and maintenance operations.
- Offline instance: Shut down the instance and monitor tasks related to the instance.
- Online instance: Restart the offline instance and monitor it.
- Add slave node: Add a slave node to the master node in the master-slave cluster.
- Failover: Manually complete the failover of Redis Cluster master and slave nodes.
- Configuration management: After the user submits the work order for configuration modification, the administrator will review and complete the configuration modification.
Of course, as an operation and maintenance management platform, CacheCloud not only provides operation and maintenance operations, but also provides a wealth of monitoring information.
CacheCloud not only collects the real-time running status information of the instance provided by the INFO command and displays it visually, but also saves the running status information of the instance, such as memory usage, number of client connections, and data volume of key-value pairs. In this way, when there is a problem with the operation of Redis, the operation and maintenance personnel can query the saved historical records and analyze them in combination with the running status information at that time.
CacheCloud is a good tool if you want a unified platform to centrally host tasks related to Redis instance management.
For more learning about the Redis technology stack, you can refer to the Redis technology series column articles of the technology road of migrant workers: Redis technology study notes summary ( I will direct)