Method and system for multi-mode automatic deployment starting of redis

Through automated deployment systems, the complexity and security vulnerabilities of Redis deployment in different CPU architectures and deployment modes are solved, efficient and secure automated deployment and startup are achieved, and management and maintenance costs are reduced.

CN120029996AInactive Publication Date: 2025-05-23SHANDONG LANGCHAO YUNTOU INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510097159.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-22
Publication Date
2025-05-23
Estimated Expiration
Not applicable · inactive patent

Smart Images

  • Figure CN120029996A_ABST
    Figure CN120029996A_ABST
Patent Text Reader

Abstract

The invention discloses a multi-mode automatic deployment starting method and system for redis, and belongs to the technical field of memory databases, and the method comprises the following steps: an early-stage preparation work part: making a redis binary executable program compatible under different CPU (Central Processing Unit) architectures; the resource verification part is used for verifying node information, a node memory and node disk information configured in the configuration file; the storage configuration part is used for configuring a storage directory according to the storage information configured in the configuration file, and automatically creating and mounting a data disk for a redis working directory; and the self-deployment part is used for installing a binary executable program into each node according to node information configured in the configuration file, modifying necessary parameters of the redis configuration file, and pushing the redis configuration file to a data directory of each node. According to the method and the device, the redis can be automatically deployed and started according to different CPU architectures and deployment modes under the condition of different CPU architectures and deployment modes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of in-memory database, and in particular to a method and system for automatically deploying and starting a multi-mode redis. Background Art

[0002] Redis (Remote Dictionary Server) is an open source, high-performance key-value storage database. Its data structure supports strings, lists, sets, ordered sets, hash tables, etc. It is fast, stable, and reliable. Redis is often used as a cache, message queue, real-time data analysis, and other scenarios. It can persist data to disk and supports advanced features such as master-slave replication and data sharding. Redis has become the first choice for storage solutions for many Internet companies and projects.

[0003] When using Redis, you need to distinguish different CPU architectures and redis deployment modes, and use different compiled versions to deploy on specified nodes. Manual deployment of Redis requires installation and configuration, which takes time and requires certain technical knowledge. Especially for those who are not familiar with Redis, it may take more learning and practice to correctly install and configure. Manual deployment may increase security risks because of possible configuration errors or security vulnerabilities. Moreover, manual installation may cause some security measures to be ignored or omitted. If Redis needs to be deployed on multiple servers, manual deployment on each server will lead to duplication of work and time consumption. Summary of the invention

[0004] The technical task of the present invention is to address the above shortcomings and provide a method and system for multi-mode automatic deployment and startup of redis, so as to realize automatic deployment and startup of redis according to different CPU architectures and deployment modes under different CPU architectures and deployment modes, thereby improving efficiency, reducing errors, ensuring consistency, and reducing management and maintenance costs.

[0005] The technical solution adopted by the present invention to solve the technical problem is:

[0006] A method for automatically deploying and starting a multi-mode redis system, comprising:

[0007] 1) Preliminary preparation: Make a redis binary executable program compatible with different CPU architectures;

[0008] 2) Resource verification part: Verify the node information, node memory and node disk information configured in the configuration file;

[0009] 3) In the storage configuration part, the storage directory is configured according to the storage information configured in the configuration file, and the data disk is automatically created and mounted for the redis working directory, avoiding the repeated operation of creating nodes one by one;

[0010] 4) In the self-deployment part, according to the node information configured in the configuration file, the binary executable program is installed in each node, the necessary parameters of the redis configuration file are modified, and it is pushed to the data directory of each node. If it is a sentinel mode deployment, the necessary parameters of the sentinel configuration file are modified and pushed to the data directory of each node.

[0011] When only a host is provided, this method automatically determines the CPU architecture and operating system of the host, selects the appropriate redis binary program, and then reads the deployment mode, node information, port, specification and other information in the configuration file, automatically installs the redis service of each node, starts the service, and then automatically configures the redis node information to achieve the purpose of multi-mode automatic deployment and startup.

[0012] Furthermore, the preliminary preparation work specifically includes:

[0013] Build compilation environments under different CPU architectures, and use the compilation environments under different CPU architectures to compile binary executable programs, obtain binary executable programs redis-server, redis-cli, redis-benchmark, redis-sentinel, create folders according to the names of different CPU architectures such as x86-64, aarch64, loongarch, etc., and put the compiled binary executable programs into different architecture folders;

[0014] This section also includes writing the default method configuration file, which includes deployment mode, instance specifications, data directory, node information, etc. If different versions of redis are required, different versions of redis source code need to be compiled separately.

[0015] Furthermore, the resource verification part includes:

[0016] Use ssh to test node connectivity to ensure that nodes can communicate with each other. If a node is not accessible, a node access failure message will be thrown and the method will be exited immediately.

[0017] Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If the rules are not met, the method will be exited by throwing the message "Redis related ports are not open";

[0018] If the memory information obtained by lsmem is compared with the instance specification information, if the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits;

[0019] Compare the free disk size with the size of the memory specification. According to the ratio, the minimum value of the free disk should be greater than 4 times the memory specification. If the free disk size is smaller than this value, the message of insufficient free disk will be thrown and the method will exit.

[0020] Furthermore, in the storage configuration part, if the configuration file stores a directory address, the directory is directly used as the data directory address of redis; if the configuration file stores a disk device and storage size, a disk of the corresponding size is automatically created and mounted on the data directory.

[0021] Furthermore, the storage configuration part is implemented as follows:

[0022] 3.1) Read the storage configuration part of the configuration file. If only the data directory is configured, check whether the directory exists. If not, create the data directory;

[0023] 3.2) If the data directory and disk device are configured, check whether the disk device is mounted to the data directory. If not, check whether the disk device has been loaded and formatted. If volume partitioning and formatting have not been performed, create volumes and format the data disk, and mount it to the data directory.

[0024] Furthermore, in the self-deployment part, after the binary files and configuration files are installed, the redis.service file is generated and installed to / etc / systemd / system; if it is sentinel mode, the sentinel.service file needs to be generated and installed to / etc / system / system;

[0025] After the above work is completed, execute the systemctl start redis command to start redis. If you need to deploy the sentinel mode, you also need to execute the systemctl start sentinel command to start the sentinel. Set up the corresponding stand-alone, sentinel, or cluster mode according to the required deployment mode.

[0026] Furthermore, the preliminary preparation work is implemented as follows:

[0027] 1.1) Prepare hosts with different CPU architectures, such as x86-64, aarch64, and loongarch, and install the redis compilation environment for the hosts, including gcc, make, etc.;

[0028] 1.2) Download the redis source code on different hosts respectively. According to different versions, put the redis source code folder in the working directory of the compilation environment with the name of redis-version number;

[0029] 1.3) Compile different versions of redis on different CPU architectures. The compilation process is to compile redis deps first, and then compile the redis source code;

[0030] 1.4) Create cpu architecture directories in the working directory of each host, including x86-64, aarch64, and loongarch, and create directories for each version under redis-bin, and place the compiled source code and template configuration files corresponding to each version into the directory of the corresponding version according to the version;

[0031] 1.5) Use the tar command to compress the redis directories of each version under the architecture directory, delete the version directory, and store only the compressed redis executable binary files and template configuration files under the architecture directory; use the tar command to compress the architecture directory to generate compressed files of different versions of redis under the CPU architecture;

[0032] 1.6) Create a redis-install directory in the working directory of the preparation machine, create a redis-bin directory in this directory, copy the architecture compression files generated under all CPU architectures to the redis-install / redis-bin directory of the preparation machine, and create config.yaml in the redis-install directory, which includes node information, storage information, specification information, and deployment mode information; then put the edited detection, configuration, deployment scripts and the main scheduling script redis-install.sh in the redis-install directory;

[0033] 1.7) Compress the redis-install directory to generate a compressed file named "redis-install-timestamp". When you need to deploy it later, copy the compressed file to the environment where you need to deploy, decompress it, modify the configuration file, and execute redis-install.sh to deploy it;

[0034] The resource verification is implemented as follows:

[0035] 2.1) After executing redis-install.sh, the first step is to check the node information, rule information, and storage information configured in the configuration file;

[0036] 2.2) Read the node information in the configuration file, including the node IP, ssh port, ssh account password or key, use the ssh command to remotely connect to each node, and determine whether each node can be connected. If ssh fails, the node access failure information is thrown and the method is exited;

[0037] 2.3) Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If it does not meet the rules, it will throw a message that the redis-related port is not open and the method will exit;

[0038] 2.4) Check the memory size of each node, and compare the memory information obtained by lsmem with the instance specification information. If the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits;

[0039] 2.5) Check the remaining space of each node. If a directory is provided, check the remaining disk size and memory size under the existing directory. The minimum value of the remaining disk should be greater than 4 times the memory size. If the remaining disk size is less than this value, throw out the message of insufficient remaining disk and exit the method. If a disk device is provided, use lsblk to obtain the remaining space of the corresponding disk and compare it according to the above comparison method.

[0040] The self-deployment implementation process is as follows:

[0041] 4.1) Unzip the redis-bin compressed file, obtain the CPU architecture through lscpu, such as x86-64, aarch64, loogarch, and decompress the compressed file of the corresponding CPU architecture in the redis-bin directory according to the obtained CPU structure, thereby obtaining the binary executable file of the corresponding architecture;

[0042] 4.2) According to the version of redis to be deployed in the configuration file, obtain the compressed file of the corresponding version of redis in the directory of the corresponding cpu architecture, decompress it, and obtain the required binary executable file and configuration template of redis;

[0043] 4.3) Replace the corresponding attributes of the redis template configuration file according to the redis configuration of the method configuration file; if it is sentinel mode, you also need to replace the corresponding attributes of the sentinel template configuration file according to the configuration in the method configuration file;

[0044] 4.4) Use the scp command to copy the redis binary executable program to the / usr / bin directory of each node, and copy the redis template configuration file to the redis data directory of each node; if it is sentinel mode, you also need to copy the sentinel template configuration to the data directory of each node;

[0045] 4.5) Generate the redis.service file and copy it to / etc / systemd / system of each node. If it is sentinel mode, you also need to generate the sentinel.service file and copy it to / etc / system / system;

[0046] 4.6) Use ssh remote execution command to execute systemctl reload-deamon on each node to load the new configuration file;

[0047] 4.7) Use SSH to remotely execute commands and execute systemctl enable redis on each node to make redis.service effective. If it is sentinel mode, you also need to execute systemctl enable sentinel.service to make it effective.

[0048] 4.8) Use ssh remote execution command to execute the start redis command on each node, systemctl startredis;

[0049] 4.9) According to the specific redis deployment mode, execute the build command. No operation is required for a single node. If it is sentinel mode, you need to log in to each slave node and execute slaveof host port to build the master-slave relationship. After the master-slave relationship is established, use the ssh remote command to execute the systemctl start sentinel command to start the sentinel. If it is cluster mode, use the redis-cli--cluster create command to create a cluster.

[0050] 4.10) Check that the redis instances in each deployment mode are started and successfully built according to the specified mode.

[0051] The present invention also claims a multi-mode automatic deployment and startup system of redis, comprising:

[0052] Resource verification module, used to verify the node information, node memory and node disk information configured in the configuration file;

[0053] The storage configuration module configures the storage directory according to the storage information configured in the configuration file, automatically creates and mounts the data disk for the redis working directory, avoiding the repeated operation of creating nodes one by one;

[0054] The self-deployment module installs the binary executable program into each node according to the node information configured in the configuration file, modifies the necessary parameters of the redis configuration file, and pushes it to the data directory of each node; if it is deployed in sentinel mode, modify the necessary parameters of the sentinel configuration file and push it to the data directory of each node;

[0055] The system performs preliminary preparations based on the above-mentioned method for multi-mode automatic deployment and startup of redis to achieve multi-mode automatic deployment and startup of redis.

[0056] The present invention also claims a device for multi-mode automatic deployment and startup of redis, comprising: at least one memory and at least one processor;

[0057] The at least one memory is used to store a machine-readable program;

[0058] The at least one processor is used to call the machine-readable program to implement the above method.

[0059] The present invention also claims protection for a computer-readable medium having computer instructions stored thereon, which, when executed by a processor, causes the processor to perform the above method.

[0060] Compared with the prior art, the multi-mode automatic deployment and startup method and system of redis of the present invention have the following beneficial effects:

[0061] The present invention automatically selects the required redis version for automatic deployment according to the CPU architecture and deployment mode, simplifies the manual deployment process, and speeds up the deployment delivery.

[0062] Automated deployment can greatly improve the efficiency of the deployment process. By using automated tools, Redis instances can be quickly deployed in a short time without the need to manually install and configure them one by one, and automated deployment can reduce human errors. Since the deployment process is performed by automated tools, the possibility of human intervention is reduced, thus reducing the risk of configuration errors. Automated deployment of Redis has the advantages of improving efficiency, reducing errors, ensuring consistency, reducing management and maintenance costs, and improving scalability. BRIEF DESCRIPTION OF THE DRAWINGS

[0063] Figure 1It is a flowchart of a method for multi-mode automatic deployment and startup of redis provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0064] The present invention will be further described below in conjunction with the accompanying drawings and specific embodiments.

[0065] The embodiment of the present invention provides a method for multi-mode automatic deployment and startup of redis, including a preliminary preparation part, a resource verification part, a storage configuration part and a self-deployment part:

[0066] 1. In the preliminary preparation part, make a redis binary executable program compatible with different CPU architectures.

[0067] This part requires setting up a compilation environment under different CPU architectures, and using the compilation environment under different CPU architectures to compile binary executable programs, obtain the binary executable programs redis-server, redis-cli, redis-benchmark, and redis-sentinel, and create folders according to the names of different CPU architectures such as x86-64, aarch64, loongarch, etc., and put the compiled binary executable programs into different architecture folders.

[0068] This part also requires writing the default method configuration file, which includes deployment mode, instance specifications, data directory, node information, etc. If different versions of redis are required, different versions of redis source code need to be compiled separately.

[0069] 2. Resource verification part: Verify the node information, node memory and node disk information configured in the method configuration file.

[0070] Use ssh to test node connectivity to ensure that nodes can communicate with each other. If a node is not accessible, a node access failure message will be thrown and the method will be exited immediately.

[0071] Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If the rules are not met, the method will be exited by throwing the message "Redis related ports are not open";

[0072] If the memory information obtained by lsmem is compared with the instance specification information, if the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits;

[0073] Compare the free disk size with the size of the memory specification. According to the ratio, the minimum value of the free disk should be greater than 4 times the memory specification. If the free disk size is smaller than this value, the message of insufficient free disk will be thrown and the method will exit.

[0074] 3. In the storage configuration part, the storage directory is configured according to the storage information configured in the configuration file. If the directory address is saved in the configuration file, the directory is directly used as the data directory address of redis. If the disk device and storage size are stored, a disk of the corresponding size is automatically created and mounted to the data directory. The storage configuration work can automatically create and mount the data disk for the working directory of redis, avoiding the repeated operation of creating nodes one by one.

[0075] 4. In the self-deployment part, according to the node information configured in the method configuration file, install the binary executable program into each node, modify the necessary parameters of the redis configuration file, and push it to the data directory of each node. If it is a sentinel mode deployment, modify the necessary parameters of the sentinel configuration file and push it to the data directory of each node.

[0076] After the binary files and configuration files are installed, generate the redis.service file and install it to / etc / systemd / system. If it is sentinel mode, you also need to generate the sentinel.service file and install it to / etc / system / system. After the above work is completed, execute the systemctl start redis command to start redis. If you need to deploy sentinel mode, you also need to execute systemctl start sentinel to start sentinel. Build the corresponding stand-alone, sentinel or cluster mode according to the required deployment mode.

[0077] As attached Figure 1 As shown, the specific steps to implement this method are as follows:

[0078] 1. Prerequisites:

[0079] (1) Prepare hosts with different CPU architectures, such as x86-64, aarch64, and loongarch, and install redis compilation environments such as gcc and make for the hosts;

[0080] (2) Download the redis source code on different hosts respectively. According to different versions, put the redis source code folder in the working directory of the compilation environment with the name of redis-version number;

[0081] (3) Compile different versions of redis on different CPU architectures. The compilation process is to compile redis deps first, and then compile the redis source code;

[0082] (4) Create a cpu architecture directory such as x86-64, aarch64, and loongarch in the working directory of each host, and create a directory for each version under redis-bin, and place the compiled source code and the template configuration files corresponding to each version into the directory of the corresponding version according to the version;

[0083] (5) Compress the redis directories of each version under the architecture directory using the tar command, and delete the version directory. Only the compressed redis executable binary files and template configuration files are stored in the architecture directory; compress the architecture directory using the tar command to generate compressed files of different versions of redis under the CPU architecture;

[0084] (6) Create a redis-install directory in the working directory of the preparation machine, create a redis-bin directory in this directory, copy the architecture compression files generated under all CPU architectures to the redis-install / redis-bin directory of the preparation machine, and create config.yaml in the redis-install directory, which includes node information, storage information, specification information, and deployment mode information; then place the edited detection, configuration, deployment scripts and the main scheduling script redis-install.sh in the redis-install directory;

[0085] (7) Compress the redis-install directory to generate a compressed file named "redis-install-timestamp". When you need to deploy it later, copy the compressed file to the environment where you need to deploy it, decompress it, modify the configuration file, and execute redis-install.sh to deploy it.

[0086] 2. Resource inspection:

[0087] (1) After executing redis-install.sh, the first step is to check the node information, rule information, and storage information configured in the configuration file;

[0088] (2) Read the node information in the configuration file, including the node IP, SSH port, SSH account password or key, use the SSH command to remotely connect to each node, and determine whether each node can be connected. If SSH fails, throw out the node access failure information and exit the method;

[0089] (3) Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If the rules are not met, the method will be thrown out of the state that the redis-related port is not open, and the method will exit;

[0090] (4) Check the memory size of each node and compare the memory information obtained by lsmem with the instance specification information. If the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits;

[0091] (5) Check the remaining space of each node. If a directory is provided, check the remaining disk space and memory size under the existing directory. The minimum value of the remaining disk space should be greater than 4 times the memory size. If the remaining disk space is less than this value, the message "Insufficient free disk space" is thrown and the method is exited. If a disk device is provided, use lsblk to obtain the remaining space of the corresponding disk and perform comparison according to the above comparison method.

[0092] 3. Storage Configuration:

[0093] (1) Read the storage configuration part of the configuration file. If only the data directory is configured, check whether the directory exists. If not, create the data directory.

[0094] (2) If the data directory and disk device are configured, check whether the disk device is mounted to the data directory. If not, check whether the disk device has been loaded and formatted. If volume partitioning and formatting have not been performed, create volumes and format the data disk, and mount it to the data directory.

[0095] 4. Automatic deployment:

[0096] (1) Decompress the redis-bin compressed file and obtain the CPU architecture through lscpu, such as x86-64, aarch64, and loogarch. Decompress the compressed file of the corresponding CPU architecture in the redis-bin directory according to the obtained CPU structure, thereby obtaining the binary executable file of the corresponding architecture;

[0097] (2) According to the version of redis to be deployed in the configuration file, obtain the compressed file of the corresponding version of redis in the directory of the corresponding CPU architecture, decompress it, and thereby obtain the required binary executable file and configuration template of redis;

[0098] (3) Replace the corresponding attributes of the redis template configuration file according to the redis configuration in the method configuration file; if it is sentinel mode, you also need to replace the corresponding attributes of the sentinel template configuration file according to the configuration in the method configuration file;

[0099] (4) Use the scp command to copy the redis binary executable program to the / usr / bin directory of each node, and copy the redis template configuration file to the redis data directory of each node; if it is sentinel mode, you also need to copy the sentinel template configuration to the data directory of each node;

[0100] (5) Generate the redis.service file and copy it to / etc / systemd / system on each node. If it is sentinel mode, you also need to generate the sentinel.service file and copy it to / etc / system / system.

[0101] (6) Use ssh remote execution command to execute systemctl reload-deamon on each node to load the new configuration file;

[0102] (7) Use SSH to remotely execute commands and execute systemctl enable redis on each node to make redis.service effective. If it is in sentinel mode, you also need to execute systemctl enable sentinel.service to make it effective.

[0103] (8) Use ssh remote execution command to execute the start redis command on each node, systemctl startredis;

[0104] (9) According to the specific redis deployment mode, execute the build command. No operation is required for a single node. If it is sentinel mode, you need to log in to each slave node and execute slaveof host port to build the master-slave relationship. After the master-slave relationship is established, use the ssh remote command to execute the systemctl start sentinel command to start the sentinel. If it is cluster mode, use the redis-cli--cluster create command to create a cluster.

[0105] (10) Check that the Redis instances in each deployment mode are started and successfully built according to the specified mode.

[0106] This method can realize the automatic deployment of corresponding redis instances under different redis CPU architectures, provide options for different deployment modes, and determine the deployment mode based on the selection; when only the host is provided, it automatically determines the CPU architecture and operating system of the host, selects the adapted redis binary program, and then reads the deployment mode, node information, port, specification and other information in the configuration file, automatically installs the redis service of each node, starts the service, and then automatically configures the redis node information to achieve the purpose of multi-mode automatic deployment and startup.

[0107] The embodiment of the present invention also provides a multi-mode automatic deployment and startup system of redis, including:

[0108] Resource verification module, used to verify the node information, node memory and node disk information configured in the configuration file;

[0109] The storage configuration module configures the storage directory according to the storage information configured in the configuration file, automatically creates and mounts the data disk for the redis working directory, avoiding the repeated operation of creating nodes one by one;

[0110] The self-deployment module installs the binary executable program into each node according to the node information configured in the configuration file, modifies the necessary parameters of the redis configuration file, and pushes it to the data directory of each node; if it is deployed in sentinel mode, modify the necessary parameters of the sentinel configuration file and push it to the data directory of each node;

[0111] The system performs preliminary preparations based on the above-mentioned method for multi-mode automatic deployment and startup of redis to achieve multi-mode automatic deployment and startup of redis.

[0112] Preliminary preparations require building a compilation environment under different CPU architectures, and using the compilation environment under different CPU architectures to compile binary executable programs, obtain binary executable programs redis-server, redis-cli, redis-benchmark, redis-sentinel, create folders according to the names of different CPU architectures such as x86-64, aarch64, loongarch, etc., and put the compiled binary executable programs into different architecture folders. You also need to write a default method configuration file, which includes deployment mode, instance specifications, data directory, node information, etc.; if different versions of redis are required, you need to compile different versions of redis source code separately.

[0113] The resource verification module uses ssh to test node connectivity to ensure that nodes can communicate with each other. If a node is not accessible, a node access failure message is thrown and the method is exited immediately.

[0114] Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If the rules are not met, the method will be exited by throwing the message "Redis related ports are not open";

[0115] If the memory information obtained by lsmem is compared with the instance specification information, if the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits;

[0116] Compare the free disk size with the size of the memory specification. According to the ratio, the minimum value of the free disk should be greater than 4 times the memory specification. If the free disk size is smaller than this value, the message of insufficient free disk will be thrown and the method will exit.

[0117] The storage configuration module configures the storage directory according to the storage information configured in the configuration file. If the directory address is saved in the configuration file, it will be directly used as the data directory address of redis. If the disk device and storage size are stored, a disk of the corresponding size will be automatically created and mounted to the data directory. The storage configuration work can automatically create and mount the data disk for the working directory of redis, avoiding the repeated operation of creating nodes one by one.

[0118] The self-deployment module installs the binary executable program into each node according to the node information configured in the method configuration file, modifies the necessary parameters of the redis configuration file, and pushes it to the data directory of each node. If it is deployed in sentinel mode, modify the necessary parameters of the sentinel configuration file and push it to the data directory of each node.

[0119] After the binary files and configuration files are installed, generate the redis.service file and install it to / etc / systemd / system. If it is sentinel mode, you also need to generate the sentinel.service file and install it to / etc / system / system. After the above work is completed, execute the systemctl start redis command to start redis. If you need to deploy sentinel mode, you also need to execute systemctl start sentinel to start sentinel. Build the corresponding stand-alone, sentinel or cluster mode according to the required deployment mode.

[0120] The specific steps for the system to realize multi-mode automatic deployment and startup of redis are as follows:

[0121] 1. Prerequisites:

[0122] (1) Prepare hosts with different CPU architectures, such as x86-64, aarch64, and loongarch, and install redis compilation environments such as gcc and make for the hosts;

[0123] (2) Download the redis source code on different hosts respectively. According to different versions, put the redis source code folder in the working directory of the compilation environment with the name of redis-version number;

[0124] (3) Compile different versions of redis on different CPU architectures. The compilation process is to compile redis deps first, and then compile the redis source code;

[0125] (4) Create a cpu architecture directory such as x86-64, aarch64, and loongarch in the working directory of each host, and create a directory for each version under redis-bin, and place the compiled source code and the template configuration files corresponding to each version into the directory of the corresponding version according to the version;

[0126] (5) Compress the redis directories of each version under the architecture directory using the tar command, and delete the version directory. Only the compressed redis executable binary files and template configuration files are stored in the architecture directory; compress the architecture directory using the tar command to generate compressed files of different versions of redis under the CPU architecture;

[0127] (6) Create a redis-install directory in the working directory of the preparation machine, create a redis-bin directory in this directory, copy the architecture compression files generated under all CPU architectures to the redis-install / redis-bin directory of the preparation machine, and create config.yaml in the redis-install directory, which includes node information, storage information, specification information, and deployment mode information; then place the edited detection, configuration, deployment scripts and the main scheduling script redis-install.sh in the redis-install directory;

[0128] (7) Compress the redis-install directory to generate a compressed file named "redis-install-timestamp". When you need to deploy it later, copy the compressed file to the environment where you need to deploy it, decompress it, modify the configuration file, and execute redis-install.sh to deploy it.

[0129] 2. Resource inspection:

[0130] (1) After executing redis-install.sh, the first step is to check the node information, rule information, and storage information configured in the configuration file;

[0131] (2) Read the node information in the configuration file, including the node IP, SSH port, SSH account password or key, use the SSH command to remotely connect to each node, and determine whether each node can be connected. If SSH fails, throw out the node access failure information and exit the method;

[0132] (3) Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If the rules are not met, the method will be thrown out of the state that the redis-related port is not open, and the method will exit;

[0133] (4) Check the memory size of each node and compare the memory information obtained by lsmem with the instance specification information. If the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits;

[0134] (5) Check the remaining space of each node. If a directory is provided, check the remaining disk space and memory size under the existing directory. The minimum value of the remaining disk space should be greater than 4 times the memory size. If the remaining disk space is less than this value, the message "Insufficient free disk space" is thrown and the method is exited. If a disk device is provided, use lsblk to obtain the remaining space of the corresponding disk and perform comparison according to the above comparison method.

[0135] 3. Storage Configuration:

[0136] (1) Read the storage configuration part of the configuration file. If only the data directory is configured, check whether the directory exists. If not, create the data directory.

[0137] (2) If the data directory and disk device are configured, check whether the disk device is mounted to the data directory. If not, check whether the disk device has been loaded and formatted. If volume partitioning and formatting have not been performed, create volumes and format the data disk, and mount it to the data directory.

[0138] 4. Automatic deployment:

[0139] (1) Decompress the redis-bin compressed file and obtain the CPU architecture through lscpu, such as x86-64, aarch64, and loogarch. Decompress the compressed file of the corresponding CPU architecture in the redis-bin directory according to the obtained CPU structure, thereby obtaining the binary executable file of the corresponding architecture;

[0140] (2) According to the version of redis to be deployed in the configuration file, obtain the compressed file of the corresponding version of redis in the directory of the corresponding CPU architecture, decompress it, and thereby obtain the required binary executable file and configuration template of redis;

[0141] (3) Replace the corresponding attributes of the redis template configuration file according to the redis configuration in the method configuration file; if it is sentinel mode, you also need to replace the corresponding attributes of the sentinel template configuration file according to the configuration in the method configuration file;

[0142] (4) Use the scp command to copy the redis binary executable program to the / usr / bin directory of each node, and copy the redis template configuration file to the redis data directory of each node; if it is sentinel mode, you also need to copy the sentinel template configuration to the data directory of each node;

[0143] (5) Generate the redis.service file and copy it to / etc / systemd / system on each node. If it is sentinel mode, you also need to generate the sentinel.service file and copy it to / etc / system / system.

[0144] (6) Use ssh remote execution command to execute systemctl reload-deamon on each node to load the new configuration file;

[0145] (7) Use SSH to remotely execute commands and execute systemctl enable redis on each node to make redis.service effective. If it is in sentinel mode, you also need to execute systemctl enable sentinel.service to make it effective.

[0146] (8) Use ssh remote execution command to execute the start redis command on each node, systemctl startredis;

[0147] (9) According to the specific redis deployment mode, execute the build command. No operation is required for a single node. If it is sentinel mode, you need to log in to each slave node and execute slaveof host port to build the master-slave relationship. After the master-slave relationship is established, use the ssh remote command to execute the systemctl start sentinel command to start the sentinel. If it is cluster mode, use the redis-cli--cluster create command to create a cluster.

[0148] (10) Check that the Redis instances in each deployment mode are started and successfully built according to the specified mode.

[0149] The embodiment of the present invention also provides a device for automatically deploying and starting a multi-mode redis, comprising: at least one memory and at least one processor;

[0150] The at least one memory is used to store a machine-readable program;

[0151] The at least one processor is used to call the machine-readable program to implement the multi-mode automatic deployment and startup method of redis described in the above embodiment.

[0152] The embodiment of the present invention also provides a computer-readable medium, on which computer instructions are stored, and when the computer instructions are executed by a processor, the processor executes the method for multi-mode automatic deployment and startup of redis described in the above embodiment. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code that implements the functions of any of the above embodiments is stored, and a computer (or CPU or MPU) of the system or device reads and executes the program code stored in the storage medium.

[0153] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.

[0154] The storage medium embodiments for providing the program code include a floppy disk, a hard disk, a magneto-optical disk, an optical disk (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), a magnetic tape, a non-volatile memory card, and a ROM. Alternatively, the program code can be downloaded from a server computer by a communication network.

[0155] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.

[0156] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.

[0157] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.

Claims

1. A method for automatically deploying and starting multi-mode redis, characterized in that: include: 1) Preliminary preparation: Make a redis binary executable program compatible with different CPU architectures; 2) Resource verification part: Verify the node information, node memory and node disk information configured in the configuration file; 3) In the storage configuration part, the storage directory is configured according to the storage information configured in the configuration file, and the data disk is automatically created and mounted for the redis working directory; 4) In the self-deployment part, according to the node information configured in the configuration file, the binary executable program is installed in each node, the necessary parameters of the redis configuration file are modified, and it is pushed to the data directory of each node. If it is a sentinel mode deployment, the necessary parameters of the sentinel configuration file are modified and pushed to the data directory of each node.

2. According to claim 1, a method for multi-mode automatic deployment and startup of redis is characterized in that: The preliminary preparation work specifically includes: Build compilation environments under different CPU architectures, and use the compilation environments under different CPU architectures to compile binary executable programs, obtain binary executable programs redis-server, redis-cli, redis-benchmark, and redis-sentinel, create folders according to the names of different CPU architectures, and put the compiled binary executable programs into folders of different architectures; This section also includes writing the default method configuration file, which includes deployment mode, instance specifications, data directory, and node information; if different versions of redis are required, different versions of redis source code need to be compiled separately.

3. According to claim 1, a method for multi-mode automatic deployment and startup of redis is characterized in that: The resource verification part includes: Use ssh to test node connectivity to ensure that nodes can communicate with each other. If a node is not accessible, a node access failure message will be thrown and the method will be exited immediately. Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If the rules are not met, the method will be exited by throwing the message "Redis related ports are not open"; If the memory information obtained by lsmem is compared with the instance specification information, if the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits; Compare the free disk size with the size of the memory specification. According to the ratio, the minimum value of the free disk should be greater than 4 times the memory specification. If the free disk size is smaller than this value, the message of insufficient free disk will be thrown and the method will exit.

4. According to claim 1, a method for multi-mode automatic deployment and startup of redis is characterized in that: In the storage configuration part, if the configuration file stores a directory address, the directory is directly used as the redis data directory address; if the configuration file stores a disk device and storage size, a disk of the corresponding size is automatically created and mounted on the data directory.

5. According to claim 4, a method for multi-mode automatic deployment and startup of redis is characterized in that: The storage configuration part is implemented as follows: 3.1) Read the storage configuration part of the configuration file. If only the data directory is configured, check whether the directory exists. If not, create the data directory; 3.2) If the data directory and disk device are configured, check whether the disk device is mounted to the data directory. If not, check whether the disk device has been loaded and formatted. If volume partitioning and formatting have not been performed, create volumes and format the data disk, and mount it to the data directory.

6. According to claim 1, a method for multi-mode automatic deployment and startup of redis, characterized in that: In the self-deployment part, after the binary files and configuration files are installed, the redis.service file is generated and installed to / etc / systemd / system; if it is sentinel mode, the sentinel.service file also needs to be generated and installed to / etc / system / system; After the above work is completed, execute the systemctl start redis command to start redis. If you need to deploy the sentinel mode, you also need to execute the systemctl start sentinel command to start the sentinel. Set up the corresponding stand-alone, sentinel, or cluster mode according to the required deployment mode.

7. According to claim 1, a method for multi-mode automatic deployment and startup of redis is characterized in that: The preliminary preparation process is as follows: 1.1) Prepare hosts with different CPU architectures, such as x86-64, aarch64, and loongarch, and install the redis compilation environment for the hosts, including gcc and make; 1.2) Download the redis source code on different hosts respectively. According to different versions, put the redis source code folder in the working directory of the compilation environment with the name of redis-version number; 1.3) Compile different versions of redis on different CPU architectures. The compilation process is to compile redis deps first, and then compile the redis source code; 1.4) Create cpu architecture directories in the working directory of each host, including x86-64, aarch64, and loongarch, and create directories for each version under redis-bin, and place the compiled source code and template configuration files corresponding to each version into the directory of the corresponding version according to the version; 1.5) Use the tar command to compress the redis directories of each version under the architecture directory, delete the version directory, and store only the compressed redis executable binary files and template configuration files under the architecture directory; Compress the architecture directory using the tar command to generate compressed files of different versions of redis under the CPU architecture; 1.6) Create a redis-install directory in the working directory of the preparation machine, create a redis-bin directory in this directory, copy the architecture compression files generated under all CPU architectures to the redis-install / redis-bin directory of the preparation machine, and create config.yaml in the redis-install directory, which includes node information, storage information, specification information, and deployment mode information; Then put the edited detection, configuration, deployment scripts and main scheduling script redis-install.sh into the redis-install directory; 1.7) Compress the redis-install directory to generate a compressed file named "redis-install-timestamp". When you need to deploy it later, copy the compressed file to the environment where you need to deploy, decompress it, modify the configuration file, and execute redis-install.sh to deploy it; The resource verification is implemented as follows: 2.1) After executing redis-install.sh, the first step is to check the node information, rule information, and storage information configured in the configuration file; 2.2) Read the node information in the configuration file, including the node IP, ssh port, ssh account password or key, use the ssh command to remotely connect to each node, and determine whether each node can be connected. If ssh fails, the node access failure information is thrown and the method is exited; 2.3) Check whether the firewall of each node is closed or the access port of redis, the communication port between nodes, and the sentinel port are open. If it does not meet the rules, it will throw a message that the redis-related port is not open and the method will exit; 2.4) Check the memory size of each node, and compare the memory information obtained by lsmem with the instance specification information. If the size obtained by lsmem is smaller than the specification size, an error message indicating that the memory is smaller than the specification size is thrown and the method exits; 2.5) Check the remaining space of each node. If a directory is provided, check the remaining disk size and memory size under the existing directory. The minimum value of the remaining disk should be greater than 4 times the memory size. If the remaining disk size is less than this value, throw out the message of insufficient remaining disk and exit the method. If a disk device is provided, use lsblk to obtain the corresponding remaining disk space and compare it according to the above comparison method. The self-deployment implementation process is as follows: 4.1) Unzip the redis-bin compressed file, obtain the CPU architecture through lscpu, and decompress the compressed file of the corresponding CPU architecture in the redis-bin directory according to the obtained CPU structure, thereby obtaining the binary executable file of the corresponding architecture; 4.2) According to the version of redis to be deployed in the configuration file, obtain the compressed file of the corresponding version of redis in the directory of the corresponding cpu architecture, decompress it, and obtain the required binary executable file and configuration template of redis; 4.3) According to the redis configuration of the method configuration file, replace the corresponding attributes of the redis template configuration file; If it is sentinel mode, you also need to replace the corresponding properties of the sentinel template configuration file according to the configuration in the method configuration file; 4.4) Use the scp command to copy the redis binary executable program to the / usr / bin directory of each node, and copy the redis template configuration file to the redis data directory of each node; If it is sentinel mode, you also need to copy the sentinel template configuration to the data directory of each node; 4.5) Generate the redis.service file and copy it to / etc / systemd / system of each node. If it is sentinel mode, you also need to generate the sentinel.service file and copy it to / etc / system / system; 4.6) Use ssh remote execution command to execute systemctl reload-deamon on each node to load the new configuration file; 4.7) Use SSH to remotely execute commands and execute systemctl enable redis on each node to make redis.service effective. If it is sentinel mode, you also need to execute systemctl enable sentinel.service to make it effective. 4.8) Use ssh remote execution command to execute the start redis command on each node, systemctlstart redis; 4.9) According to the specific redis deployment mode, execute the build command. No operation is required for a single node. If it is sentinel mode, you need to log in to each slave node and execute slaveof host port to build the master-slave relationship. After the master-slave relationship is established, use the ssh remote command to execute the systemctlstart sentinel command to start the sentinel. If it is cluster mode, use the redis-cli--cluster create command to create a cluster. 4.10) Check that the redis instances in each deployment mode are started and successfully built according to the specified mode.

8. A multi-mode automatic deployment and startup system for redis, characterized in that: include: Resource verification module, used to verify the node information, node memory and node disk information configured in the configuration file; The storage configuration module configures the storage directory according to the storage information configured in the configuration file, and automatically creates and mounts the data disk for the redis working directory; The self-deployment module installs the binary executable program into each node according to the node information configured in the configuration file, modifies the necessary parameters of the redis configuration file, and pushes it to the data directory of each node; If it is deployed in sentinel mode, modify the necessary parameters in the sentinel configuration file and push it to the data directory of each node; The system implements multi-mode automatic deployment and startup of redis based on the preliminary preparation work performed by the method for multi-mode automatic deployment and startup of redis as described in any one of claims 1 to 7, thereby realizing multi-mode automatic deployment and startup of redis.

9. A multi-mode automatic deployment and startup device for redis, characterized in that: include: at least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is used to call the machine-readable program to implement the method described in any one of claims 1 to 7.

10. A computer-readable medium, characterized in that The computer readable medium stores computer instructions, which, when executed by a processor, cause the processor to execute the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Security configuration synchronization method for gateway equipment and client

    CN121333932A