Active / standby virtual machine session synchronization method, device and storage medium
By using shared memory to synchronize session data between virtual machines, the problem of low synchronization efficiency of primary and backup virtual machines in the prior art is solved, and faster and more efficient data synchronization is achieved.
Patent Information
- Application Number
- CN202411185320.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2044-08-27
AI Technical Summary
In the prior art, the synchronization efficiency of sessions between the main and standby virtual machines is not high, mainly because the communication path is long and multiple context switching and data copying is required.
By pre-creating shared files on the host and mounting their directories to the virtual shared directories of the main virtual machine and the standby virtual machine, the main and standby virtual machines can achieve fast synchronization of session data through shared memory.
Session data synchronization is achieved through shared memory, which significantly improves the session synchronization efficiency between the master and standby virtual machines and reduces the number of communication paths and context switching times.
Smart Images

Figure CN119127394B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data synchronization, and in particular to a method, device and storage medium for synchronizing sessions of a primary and a backup virtual machine. Background Art
[0002] A virtualized security network element is a virtual machine with security assurance capabilities. It runs in a security resource pool and can provide users with security functions such as firewalls, intrusion detection and defense to ensure the security of virtual machines and virtual networks. During the operation of a virtualized security network element, an abnormal operation state of the network element may occur, causing its network forwarding function to be unavailable, which in turn causes network interruption in the user's virtual machine. Therefore, the high availability function of the virtualized security network element comes into being. Based on a high availability cluster system composed of two or more devices, when an abnormality occurs in the main device and it cannot operate normally, the backup device takes over the main device to perform the corresponding service functions, thereby achieving the purpose of providing uninterrupted service.
[0003] For a virtualized security network element based on a session table, in order to ensure that the network session is not interrupted when the standby virtual machine takes over the work of the primary virtual machine, it is necessary to synchronize the session data of the primary virtual machine and the standby virtual machine in real time.
[0004] At present, the session synchronization method between the main and standby virtual machines is mainly based on the IP network. The main virtual machine encapsulates the session information in an IP message and sends it to the standby virtual machine through the HA (High Availability) network port. After receiving the IP message, the standby virtual machine extracts the session information for synchronization. In this process, the session information needs to pass through the user space, kernel space and virtualization simulation process implemented by pure software inside the main virtual machine. Then the virtualization simulation process passes the data to the host kernel through the system call of the local driver of the host machine, and finally transmits the network data to the relevant process of the standby virtual machine through the reverse path. It can be seen that the above session data synchronization process not only has a long communication path, but also requires multiple context switches and data copies, resulting in low efficiency of session synchronization between the main and standby virtual machines. Summary of the invention
[0005] The purpose of the embodiments of the present application is to provide a method, device and storage medium for synchronizing sessions of primary and standby virtual machines, so as to improve the efficiency of synchronizing sessions of primary and standby virtual machines.
[0006] In a first aspect, an embodiment of the present application provides a method for synchronizing a session of a primary virtual machine and a standby virtual machine, comprising:
[0007] The shared directory where the pre-created shared file is located is mounted to the virtual shared directory of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories;
[0008] The primary virtual machine responds to the session synchronization request of the backup virtual machine and copies the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine, so that the backup virtual machine synchronizes the session data to the backup virtual machine based on the shared virtual memory of the backup virtual machine.
[0009] In an embodiment of the present application, by mounting the directories of shared files to the primary and standby virtual machines respectively, and mapping the shared files to the virtual memories of the primary and standby virtual machines respectively, the primary and standby virtual machines can quickly synchronize session data through shared memory, thereby effectively improving the efficiency of session synchronization between the primary and standby virtual machines.
[0010] In some possible embodiments, mounting the shared directory where the pre-created shared file is located to the virtual shared directories of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories, includes:
[0011] Based on a pre-configured virtual machine configuration file, determine an identification directory name corresponding to a shared directory where the shared file is located;
[0012] The identification directory name is mounted to the virtual shared directories of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories.
[0013] In an embodiment of the present application, by using the identification directory name to mount the shared file directory to the shared directory of the primary and standby virtual machines, the risk of the shared file directory being exposed can be reduced, and the security of the primary and standby session data synchronization can be further improved.
[0014] In some possible embodiments, the active-standby virtual machine session synchronization method further includes:
[0015] When a session update event occurs in the primary virtual machine, an update message corresponding to the session update event is sent to the standby virtual machine through the primary virtual machine, so that the standby virtual machine performs a session synchronization update operation based on the update message;
[0016] The session update event includes a new session event and a session deletion event.
[0017] In the embodiment of the present application, by real-time monitoring of the session update events of the primary virtual machine and timely sending messages to remind the backup virtual machine to synchronously perform the session update operation, the efficiency of the session synchronization between the primary and backup virtual machines is further improved.
[0018] In some possible embodiments, copying the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine includes:
[0019] The session data of the primary virtual machine is encrypted based on a preset encryption algorithm and then copied to the shared virtual memory of the primary virtual machine, so that the backup virtual machine obtains the session data based on the shared virtual memory of the backup virtual machine, and decrypts the session data based on a preset decryption algorithm and synchronizes it to the backup virtual machine.
[0020] In an embodiment of the present application, by adding encryption and decryption steps in the process of writing or reading session data between the primary and standby virtual machines respectively, the risk of session data leakage in shared files can be reduced, and the security of session synchronization between the primary and standby virtual machines can be further improved.
[0021] In some possible embodiments, the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories, including:
[0022] Mapping the shared file to the shared virtual memory of the primary virtual machine using the Mmap method using the primary virtual machine process; wherein the primary virtual machine process is a process running in the primary virtual machine;
[0023] The shared file is mapped to the shared virtual memory of the standby virtual machine by using the standby virtual machine process through the Mmap method; wherein the standby virtual machine process is a process running in the standby virtual machine.
[0024] In the embodiment of the present application, the Mmap method is combined with the VirtioFS technology to map the shared files to the virtual memory of the primary and standby virtual machines respectively, thereby further improving the efficiency of session synchronization between the primary and standby virtual machines.
[0025] In some possible embodiments, responding to the session synchronization request of the standby virtual machine by the primary virtual machine includes:
[0026] Using a pre-created socket file to establish a message transmission channel between the primary virtual machine and the standby virtual machine;
[0027] The primary virtual machine responds to the session synchronization request sent by the standby virtual machine using the message transmission channel.
[0028] In an embodiment of the present application, a message transmission channel is established for the primary and standby virtual machines by using a socket file so that the primary and standby virtual machines can communicate with each other during session data synchronization, thereby further improving the reliability and efficiency of session synchronization of the primary and standby virtual machines.
[0029] In some possible embodiments, copying the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine includes:
[0030] The session data of the primary virtual machine is copied to the shared virtual memory of the primary virtual machine, and a data-to-be-synchronized message is fed back to the standby virtual machine through the message transmission channel, so that the standby virtual machine responds to the data-to-be-synchronized message and synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine.
[0031] In the embodiment of the present application, the reliability and efficiency of session synchronization between the primary and standby virtual machines are further improved by timely feeding back a node completion message to the standby virtual machine when completing session replication.
[0032] In a second aspect, an embodiment of the present application provides a primary and standby virtual machine session synchronization device, including:
[0033] A shared directory mounting module is used to mount the shared directory where the pre-created shared file is located to the virtual shared directory of the primary virtual machine and the standby virtual machine through the host machine, so that the primary virtual machine and the standby virtual machine can map the shared file to their respective shared virtual memories;
[0034] A session data synchronization module is used to respond to the session synchronization request of the standby virtual machine through the primary virtual machine, and copy the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine, so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine.
[0035] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor can implement the method described in any embodiment of the first aspect when executing the program.
[0036] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method described in any embodiment of the first aspect can be implemented.
[0037] In a fifth aspect, an embodiment of the present application provides a computer program product, wherein the computer program product includes a computer program, wherein when the computer program is executed by a processor, the method described in any embodiment of the first aspect can be implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1 A flowchart of a method for synchronizing a primary and standby virtual machine session provided in an embodiment of the present application;
[0040] Figure 2 A schematic diagram of the memory mapping principle provided in an embodiment of the present application;
[0041] Figure 3 A schematic diagram of the structure of a primary-backup virtual machine session synchronization device provided in an embodiment of the present application;
[0042] Figure 4 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0043] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0044] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0045] It should be noted that with the development of virtualization technology, the form and demand of security protection have evolved from physical servers in traditional computer rooms to virtual network multi-tenant security cloud services in cloud environments, such as security resource pool management. The security resource pool is a multi-tenant management platform based on software-defined security. The security resource pool can use security function virtualization technology to virtualize multiple security devices and run them on a security device in the form of virtual machines. At the same time, it can use virtualization technologies such as software-defined networks (SDN) to achieve dynamic orchestration of security service chains, which can meet the needs of cloud virtual network boundary protection, dynamic elastic expansion of security capabilities, and provide differentiated security protection capabilities for different businesses on demand.
[0046] A virtualized security network element is a virtual machine with security capabilities. It runs in a security resource pool and provides security protection for the user's virtual machine. During the operation of the virtualized security network element, abnormal operation status may occur, which may cause its network forwarding function to be unavailable, and then cause network interruption of the user's virtual machine. Therefore, the high availability function of the virtualized security network element comes into being. High availability cluster refers to cluster technology for the purpose of reducing service interruption time. The high availability cluster system is generally composed of two or more devices. These devices can be divided into main devices and backup devices according to their respective functions. In general, the main device performs the service function of the system. When the main device cannot operate normally due to power failure or other abnormal reasons and is detected by the backup device, the backup device will take over the original work of the main device, thereby achieving uninterrupted service. For virtualized security network elements based on session tables, in order to ensure that the network session is not interrupted when the backup device takes over the work of the main device, it is necessary to synchronize the session table entries in the main device to the backup device.
[0047] In the prior art, the session synchronization between the main and standby virtual machines is mainly based on the IP network. The main device (main virtual machine) encapsulates the session information in an IP message and sends it to the standby device (standby virtual machine) through the HA network port. The standby device extracts the session information from the IP message for synchronization. Taking the network communication between virtual machines A and B as an example, if virtual machine A transfers data to virtual machine B, it needs to pass through the user space, kernel space and virtualization simulation process (such as QEMU) implemented by pure software inside virtual machine A. Then the virtualization simulation process passes the data to the host kernel through the system call of the local driver of the host machine, and finally passes the network data to the relevant process of virtual machine B through the reverse path. This process not only needs to go through a long communication path, but also needs to perform multiple context switching and data copying actions, resulting in low synchronization efficiency of session data.
[0048] In response to the problems existing in the above-mentioned prior art, an embodiment of the present application provides a method for synchronizing sessions between primary and standby virtual machines. A file on a host machine is shared with two virtual machines through the VirtioFS technology. The processes of the two virtual machines respectively map the file shared by the host machine to their respective virtual memory address spaces through Mmap system calls, thereby realizing memory sharing between the two virtual machine processes, thereby performing data synchronization through memory sharing, and effectively improving the efficiency of session synchronization between the primary and standby virtual machines.
[0049] like Figure 1 As shown, the embodiment of the present application provides a method for synchronizing a session of a primary virtual machine and a backup virtual machine, which may include the following steps:
[0050] S1. The shared directory where the pre-created shared file is located is mounted to the virtual shared directory of the primary virtual machine and the standby virtual machine through the host machine, so that the primary virtual machine and the standby virtual machine map the shared file to their respective shared virtual memories.
[0051] Specifically, when creating the primary virtual machine and the standby virtual machine, first, add the VirtioFS definition information in the XML configuration file for creating the virtual machine, including the directory information for sharing on the host machine, that is, the shared directory where the shared file is located. Among them, the shared file is a common file pre-created in the shared directory for sharing. Exemplarily, the directory / root / shared-files can be used as the shared directory where the shared file is located.
[0052] It should be noted that VirtioFS is a solution for sharing the file system directory on the host to the virtual machine. The VirtioFS solution uses the fuse protocol to communicate between the host (host) and the guest (client, that is, the virtual machine). A fuse server is implemented on the host to operate the files on the host, and then the guestkernel (virtual machine kernel) is used as a fuse client to mount fuse in the guest. Virtio is used as the transport layer between the server and the client to carry the fuse protocol, rather than the / dev / fuse device on the traditional structure.
[0053] Then, after the primary virtual machine and the standby virtual machine are started, the VirtioFS driver is loaded in the host machine, and the mount command is executed to mount the shared directory to a certain path of the primary virtual machine and the standby virtual machine respectively, so that the primary virtual machine and the standby virtual machine can map the shared files to their respective virtual memory address spaces through their respective virtual machine processes. At this point, for the primary virtual machine / standby virtual machine, the address space in its virtual memory address space mapped by the shared files is the shared virtual memory.
[0054] It should be noted that the mount command is a command used to mount the file system in the Linux system. It allows users to mount external storage devices (such as hard disk partitions, optical disks, network shares, etc.) to the directory tree of the Linux file system so that they can be accessed. Through mounting, users can access the contents of these external storage devices like accessing ordinary files and directories. For example, if you need to mount the shared directory to the / mnt directory of the primary virtual machine and the standby virtual machine, you can execute the following mount command: mount -t virtiofs / root / shared-files / mnt.
[0055] S2. The primary virtual machine responds to the session synchronization request of the standby virtual machine and copies the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine, so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine.
[0056] like Figure 2 As shown, after the primary virtual machine and the standby virtual machine respectively map the shared files to their respective virtual memory address spaces, a first shared virtual memory (i.e., the shared virtual memory of the primary virtual machine) is formed in the primary virtual machine and a second shared virtual memory (i.e., the shared virtual memory of the standby virtual machine) is formed in the standby virtual machine. It can be understood that after the directory mounting and shared file mapping in the previous step, the access to the first shared virtual memory and the second shared virtual memory can directly access the shared files.
[0057] Based on this, when the standby virtual machine needs to perform session synchronization, a message (session synchronization request) requesting synchronization of all sessions can be sent to the primary virtual machine through the process of the standby virtual machine. The process of the primary virtual machine responds to the session synchronization request sent by the standby virtual machine and only needs to copy the current session data to the first shared virtual memory (i.e., the shared file). The standby virtual machine can obtain these session data through the second shared virtual memory (i.e., the shared file). The process of the standby virtual machine can complete the process of synchronizing the session data of the primary virtual machine to the standby virtual machine by copying the session data in the second shared virtual memory to the virtual machine memory of the standby virtual machine process.
[0058] In some possible embodiments, step S1, mounting the shared directory where the pre-created shared file is located to the virtual shared directories of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories, may include:
[0059] S101, determining an identification directory name corresponding to a shared directory where a shared file is located based on a pre-configured virtual machine configuration file;
[0060] S102: Mount the identification directory name to the virtual shared directories of the primary virtual machine and the standby virtual machine through the host machine, so that the primary virtual machine and the standby virtual machine can map the shared files to their respective shared virtual memories.
[0061] It should be noted that when adding VirtioFS definition information in the XML configuration file for creating a virtual machine, you can also add the identification directory name corresponding to the shared directory. For example, the added VirtioFS definition information can be as follows:
[0062] <filesystem type='mount'accessmode='passthrough'>
[0063] <driver type='virtiofs' / >
[0064] <binary path=' / usr / libexec / virtiofsd'xattr='on' / >
[0065] <source dir=' root shared-files'>
[0066] <target dir='host-file-share' / >
[0067]
[0068] The value corresponding to "source dir" is the directory path where the shared files are located on the host machine; in this embodiment, the / root / shared-files directory on the host machine is configured as a shared directory shared with the primary virtual machine and the standby virtual machine. The value corresponding to "target dir" is the identification directory name corresponding to the shared directory. In this embodiment, the identification directory name is configured as "host-file-share", which is a directory name used to identify the shared directory. Therefore, host-file-share can be regarded as an alias for the / root / shared-files directory.
[0069] It is understandable that when executing the mount command to mount a directory, the identifier directory name can be directly used for configuration. For example, based on the VirtioFS definition information added above, if the shared directory " / root / shared-files" needs to be mounted to the / mnt directory of the primary virtual machine and the standby virtual machine, the following mount command can be executed: mount-tvirtiofs host-file-share / mnt.
[0070] Based on this, since the directory is mounted by using the identifier directory name of the directory where the shared file is located, direct exposure of the shared directory where the shared file is located during the mounting process is avoided, thereby further improving the security of the master-slave session data synchronization.
[0071] In some possible embodiments, the active / standby virtual machine session synchronization method may further include:
[0072] When a session update event occurs in the primary virtual machine, an update message corresponding to the session update event is sent to the standby virtual machine through the primary virtual machine, so that the standby virtual machine performs a session synchronization update operation based on the update message;
[0073] The session update events include new session creation events and session deletion events.
[0074] Specifically, the process of the primary virtual machine can monitor the session update events of the primary virtual machine in real time. When the primary virtual machine has an event of creating a new session or deleting a session, the process of the primary virtual machine can send the current session information and the session event type (create or delete) to the standby virtual machine. After receiving this information, the process of the standby virtual machine synchronously creates or deletes the corresponding session in the standby virtual machine. Among them, the process of the primary virtual machine can send the session information and the session event type to the standby virtual machine by means of Unix Socket.
[0075] In some possible embodiments, in step S2, copying the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine may include:
[0076] The session data of the primary virtual machine is encrypted based on a preset encryption algorithm and then copied to the shared virtual memory of the primary virtual machine, so that the standby virtual machine obtains the session data based on the shared virtual memory of the standby virtual machine, and decrypts the session data based on a preset decryption algorithm and synchronizes it to the standby virtual machine.
[0077] Specifically, the primary virtual machine and the standby virtual machine can pre-agree on an encryption algorithm and a corresponding decryption algorithm. The primary virtual machine needs to first encrypt the session data before copying it to the shared virtual memory (i.e., shared file) of the primary virtual machine; accordingly, the standby virtual machine obtains the encrypted session data from the shared virtual memory of the standby virtual machine, and after decrypting it using the corresponding decryption algorithm, the original session data can be obtained, thereby achieving session data synchronization between the primary and standby virtual machines.
[0078] Based on this, by encrypting and decrypting the session data when reading and writing shared files, even if the shared files are attacked and data is leaked, the actual session data will not be leaked, thereby improving the security of session synchronization between the primary and standby virtual machines.
[0079] In some possible embodiments, in step S1, the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories, which may include:
[0080] Using the main virtual machine process to map the shared file to the shared virtual memory of the main virtual machine through the Mmap method; wherein the main virtual machine process is a process running in the main virtual machine;
[0081] The shared file is mapped to the shared virtual memory of the standby virtual machine by using the standby virtual machine process through the Mmap method; wherein the standby virtual machine process is a process running in the standby virtual machine.
[0082] It should be noted that Mmap (Memory Map) in Linux is a memory mapping mechanism that allows part of a file or device to be mapped to the virtual memory space of a process. By using Mmap, the process can directly access the contents of the mapped object without performing traditional read and write operations.
[0083] Based on this, by using the Mmap method combined with VirtioFS sharing technology to map shared files to the virtual memory space of the primary and standby virtual machines respectively, memory sharing between the two virtual machines is achieved, so that the primary and standby virtual machines can quickly synchronize session data through memory sharing, effectively improving the efficiency of session synchronization between the primary and standby virtual machines.
[0084] In some possible embodiments, in step S2, responding to the session synchronization request of the standby virtual machine by the primary virtual machine may include:
[0085] Using the pre-created socket file to establish a message transmission channel between the primary virtual machine and the standby virtual machine;
[0086] The primary virtual machine responds to the session synchronization request sent by the standby virtual machine using the message transmission channel.
[0087] Specifically, when a common file for sharing is created in a shared directory, a socket file can be created in the directory. After the directory is mounted and the shared mapping is performed, the processes of the primary virtual machine and the standby virtual machine can achieve two-way communication by accessing the socket file. For example, when session synchronization is required, the process of the standby virtual machine can send a message requesting session synchronization to the process of the primary virtual machine through the socket.
[0088] In some possible embodiments, copying the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine includes:
[0089] The session data of the primary virtual machine is copied to the shared virtual memory of the primary virtual machine, and a data-to-be-synchronized message is fed back to the standby virtual machine through a message transmission channel, so that the standby virtual machine responds to the data-to-be-synchronized message and synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine.
[0090] It should be noted that the standby virtual machine can periodically synchronize session data from the shared virtual memory to the standby virtual machine according to a pre-set period. However, since the operation of the primary virtual machine copying the session data to the shared virtual memory has time uncertainty, the standby virtual machine can synchronize the session data when the primary virtual machine sends a message.
[0091] In addition, when the primary virtual machine is copying session data to the shared virtual memory, if a complete session data is not copied to the shared virtual memory, and the standby virtual machine is synchronized based on the incomplete session data of the shared virtual memory, there may be an abnormal connection problem between the two synchronized session data. Therefore, the standby virtual machine can synchronize the session data when the primary virtual machine sends a message.
[0092] Specifically, after the process of the primary virtual machine completes the operation of copying the session data to the shared virtual memory, the data to be synchronized message can be fed back to the backup virtual machine by accessing the socket file. Based on this, it is equivalent to the primary virtual machine notifying the backup virtual machine that there is session data that needs to be synchronized at this time. The backup virtual machine receives and responds to the data to be synchronized message, thereby completing the synchronization of the session data to the backup virtual machine.
[0093] Please refer to Figure 3 , Figure 3 FIG. 1 shows a block diagram of a primary and standby virtual machine session synchronization device provided in some embodiments of the present application. It should be understood that the primary and standby virtual machine session synchronization device is similar to the above-mentioned Figure 1 Corresponding to the method embodiment, each step involved in the above method embodiment can be executed. The specific functions of the active-standby virtual machine session synchronization device can be found in the above description. To avoid repetition, the detailed description is appropriately omitted here.
[0094] Figure 3 The active-standby virtual machine session synchronization device includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the active-standby virtual machine session synchronization device, and the active-standby virtual machine session synchronization device includes:
[0095] The shared directory mounting module 310 is used to mount the shared directory where the pre-created shared file is located to the virtual shared directory of the primary virtual machine and the standby virtual machine through the host machine, so that the primary virtual machine and the standby virtual machine can map the shared file to their respective shared virtual memory;
[0096] The session data synchronization module 320 is used to respond to the session synchronization request of the standby virtual machine through the primary virtual machine, and copy the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine, so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine.
[0097] It can be understood that the above-mentioned device item embodiment corresponds to the method item embodiment of the present invention. The primary and standby virtual machine session synchronization device provided by the embodiment of the present invention can implement the primary and standby virtual machine session synchronization method provided by any method item embodiment of the present invention.
[0098] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the device described above can refer to the corresponding process in the aforementioned method, and will not be described in detail here.
[0099] like Figure 4 As shown, some embodiments of the present application provide an electronic device 400, which includes: a memory 410, a processor 420, and a computer program stored in the memory 410 and executable on the processor 420, wherein the processor 420 can implement a method of any embodiment included in the above-mentioned master-standby virtual machine session synchronization method when reading the program from the memory 410 through a bus 430 and executing the program.
[0100] Processor 420 can process digital signals and can include various computing structures, such as complex instruction set computer structure, reduced instruction set computer structure, or a structure that implements a combination of multiple instruction sets. In some examples, processor 420 can be a microprocessor.
[0101] The memory 410 may be used to store instructions executed by the processor 420 or data related to the execution of instructions. These instructions and / or data may include codes for implementing some or all functions of one or more modules described in the embodiments of the present application. The processor 420 of the disclosed embodiment may be used to execute instructions in the memory 410 to implement the method shown above. The memory 410 includes a dynamic random access memory, a static random access memory, a flash memory, an optical memory, or other memory known to those skilled in the art.
[0102] Some embodiments of the present application further provide a computer-readable storage medium having a computer program stored thereon. The computer program is executed by a processor to execute the method described in the method embodiment.
[0103] Some embodiments of the present application further provide a computer program product, which, when executed on a computer, enables the computer to execute the method described in the method embodiment.
[0104] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0105] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0106] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0107] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0108] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.
[0109] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0110] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
Claims
1. A method for synchronizing a primary and standby virtual machine session, characterized in that: include: The shared directory where the pre-created shared file is located is mounted to the virtual shared directory of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories; The primary virtual machine responds to the session synchronization request of the standby virtual machine and copies the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine, so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine; The step of responding to the session synchronization request of the standby virtual machine by the primary virtual machine includes: Using a pre-created socket file to establish a message transmission channel between the primary virtual machine and the standby virtual machine; Responding, by the primary virtual machine, to a session synchronization request sent by the standby virtual machine using the message transmission channel; The step of copying the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine includes: The session data of the primary virtual machine is copied to the shared virtual memory of the primary virtual machine, and a data-to-be-synchronized message is fed back to the standby virtual machine through the message transmission channel, so that the standby virtual machine responds to the data-to-be-synchronized message and synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine.
2. The method for synchronizing a primary virtual machine session with a standby virtual machine according to claim 1, characterized in that: The method of mounting the shared directory where the pre-created shared file is located to the virtual shared directories of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories, includes: Based on a pre-configured virtual machine configuration file, determine an identification directory name corresponding to a shared directory where the shared file is located; The identification directory name is mounted to the virtual shared directories of the primary virtual machine and the standby virtual machine respectively through the host machine, so that the primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories.
3. The method for synchronizing a primary virtual machine session with a standby virtual machine according to claim 1, characterized in that: Also includes: When a session update event occurs in the primary virtual machine, an update message corresponding to the session update event is sent to the standby virtual machine through the primary virtual machine, so that the standby virtual machine performs a session synchronization update operation based on the update message; The session update event includes a new session event and a session deletion event.
4. The method for synchronizing a primary virtual machine session with a standby virtual machine according to claim 1, characterized in that: The step of copying the session data of the primary virtual machine to the shared virtual memory of the primary virtual machine so that the standby virtual machine synchronizes the session data to the standby virtual machine based on the shared virtual memory of the standby virtual machine includes: The session data of the primary virtual machine is encrypted based on a preset encryption algorithm and then copied to the shared virtual memory of the primary virtual machine, so that the backup virtual machine obtains the session data based on the shared virtual memory of the backup virtual machine, and decrypts the session data based on a preset decryption algorithm and synchronizes it to the backup virtual machine.
5. The method for synchronizing a primary virtual machine session with a standby virtual machine according to claim 1, characterized in that: The primary virtual machine and the standby virtual machine respectively map the shared file to their respective shared virtual memories, including: Mapping the shared file to the shared virtual memory of the primary virtual machine using the Mmap method using the primary virtual machine process; wherein the primary virtual machine process is a process running in the primary virtual machine; The shared file is mapped to the shared virtual memory of the standby virtual machine by using the standby virtual machine process through the Mmap method; wherein the standby virtual machine process is a process running in the standby virtual machine.
6. An electronic device, characterized in that: The invention comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor can implement the active-standby virtual machine session synchronization method as described in any one of claims 1 to 5 when executing the program.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the active-standby virtual machine session synchronization method according to any one of claims 1 to 5 is executed.
8. A computer program product, characterized in that The computer program product includes a computer program, and when the computer program is executed by a processor, the active-standby virtual machine session synchronization method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Method and device for realizing session synchronization, storage medium and program product
CN109413118A
Virtual machine management method, device and equipment under hyper-converged architecture
CN117193936A