A method for virtual machine machine-id synchronization
Patent Information
- Application Number
- CN202211083929.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-09-06
- Publication Date
- 2026-10-30
- Estimated Expiration
- 2042-09-06
AI Technical Summary
[0006]在实际应用中,图1所示的方法存在以下不足:1.Step2、Step3和Step4都需要在系统启动完成后手动执行,对于需要批量部署虚拟机的云计算业务场景,需要专门定制脚本在启动后自动完成该操作以避免重复操作和人为遗漏,增加了部署复杂性和维护工作量,尤其是要确保Step4对所有依赖machine-id的服务都进行重新初始化则比较困难
[0024]1.避免经历原方案在手动更新machine-id之前使用错误machine-id完成初始化的过程,减少系统环境的隐患;
Smart Images

Figure CN115437745B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of virtual machine technology, and in particular to a method for synchronizing virtual machine machine IDs. Background Technology
[0002] Cloud computing is a crucial foundation of the current information industry, and virtualization technology is a powerful support for cloud computing. Therefore, installing Linux virtual machines is becoming increasingly common in cloud computing services based on clusters. To improve installation and deployment efficiency, cloud computing scenarios often use virtual machine cloning to achieve batch deployment of virtual hosts. This involves exporting a fixed-format disk image file from a pre-installed virtual machine environment, and then directly importing this disk image into other installation environments to create identical Linux virtual hosts, eliminating the complex process of installing the system.
[0003] While using cloned virtual machine disk images allows for more efficient installation and deployment, it also introduces new problems. Because a disk image clones the entire virtual machine environment, all files on the reinstalled system are identical to those in the original system, including all files in the ` / etc` directory. For Linux systems managed by systemd, the contents of ` / etc / machine-id` (i.e., the machine-id, the unique identifier for a single machine system) no longer reflect the uniqueness of the newly installed system. This can lead to unavoidable conflicts and unpredictable runtime errors when other services on the local machine, which rely on the uniqueness of the machine-id, communicate with other hosts. For example, in DHCP mode, when the IPv6 local address generation policy is stable-privacy, the address is calculated using a hash algorithm, and ` / etc / machine-id` is one of the keys in this hash algorithm. If two environments have the same machine-id, it will cause an IP address conflict.
[0004] When installing a virtual machine using a non-disk image file, the machine-id is regenerated by systemd based on the unique UUID of the virtual machine domain created by qemu-kvm and saved to the file / etc / machine-id. Therefore, for scenarios where virtual machines are built using disk images, an effective implementation method is needed to synchronously update the system's machine-id using the newly created domain UUID at system startup, ensuring that the new system's / etc / machine-id can uniquely identify the current system environment.
[0005] In a Linux environment, the systemd program only checks the existence of the machine-id during system startup, without verifying its correctness. It only updates the machine-id if it's missing. Given this issue, the commonly used method is to utilize the systemd component `systemd-machine-id-setup` to resolve this problem. After importing the cloned virtual machine's disk image and booting the system, you need to manually delete or clear the system file ` / etc / machine-id` on the Linux command line, then execute the command `systemd-machine-id-setup` to update the system's unique identifier `machine-id` using the domain UUID and save it to the ` / etc / machine-id` file. The overall process is illustrated below. Figure 1 As shown.
[0006] In practical applications, Figure 1 The method described has the following shortcomings: 1. Steps 2, 3, and 4 all need to be manually executed after system startup. For cloud computing business scenarios that require batch deployment of virtual machines, a specially customized script is needed to automatically complete this operation after startup to avoid repetitive operations and human error, increasing deployment complexity and maintenance workload. In particular, ensuring that Step 4 reinitializes all services that depend on machine-id is quite difficult. 2. Between Steps 1 and 4, after system startup, various services have already completed initialization and started working using incorrect machine-ids. In a multi-host and complex cloud computing cluster environment, this is likely to cause more unpredictable problems, seriously affecting the stability of the system and cluster.
[0007] Therefore, how to provide an efficient and secure machine-id synchronization method has become an urgent technical problem to be solved. Summary of the Invention
[0008] In view of this, in order to improve the efficiency and security of machine-id synchronization, the present invention provides a method for synchronizing virtual machine machine-ids.
[0009] This invention provides a method for synchronizing virtual machine machine-ids, comprising:
[0010] Step S1: The Linux system first enters the early boot stage and executes the systemd program;
[0011] Step S2: The systemd program starts initialization and calls the machine-id-setup program;
[0012] Step S3: Execute the machine-id-setup program to regenerate the virtual machine's machine-id and save it in the memory file / run / machine-id;
[0013] Step S4: Complete switch root by executing the systemd program, ending the early boot phase;
[0014] Step S5: Update the value saved in the memory file / run / machine-id to the disk file / etc / machine-id;
[0015] Step S6: Initialize all system services and complete system startup.
[0016] Further, step S3 of the virtual machine machine-id synchronization method of the present invention includes: executing the machine-id-setup program, regenerating the virtual machine machine-id based on the virtual machine domainuuid stored in the / sys / class / dmi / id / product_uuid file, and storing the newly generated machine-id in the memory file / run / machine-id.
[0017] Furthermore, step S4 of the virtual machine-id synchronization method of the present invention includes: completing switch root by executing the systemd program, changing the permissions of the / etc directory from read-only to writable, and ending the early boot stage.
[0018] Furthermore, step S5 of the virtual machine-id synchronization method of the present invention includes: updating the machine-id of the regenerated virtual machine stored in the memory file / run / machine-id to the disk file / etc / machine-id.
[0019] Furthermore, step S6 of the virtual machine-id synchronization method of the present invention includes: using the process of the systemd program as the parent process of other processes, and using the systemd program to manage all user-mode processes.
[0020] Furthermore, step S6 of the virtual machine-id synchronization method of the present invention includes: using the systemd program to start other services of the system to complete the system startup.
[0021] The present invention also provides a computer storage medium storing a computer program thereon, wherein when the computer program is executed, the steps of the method are performed.
[0022] Finally, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the steps of the method when executing the program.
[0023] The virtual machine-id synchronization method of the present invention has the following beneficial effects:
[0024] 1. This avoids the original solution's process of using an incorrect machine-id to complete initialization before manually updating the machine-id, reducing potential system environment risks;
[0025] 2. Ensure that the machine-id and domain UUID are synchronized each time the virtual machine starts, so as to ensure that the machine-id can uniquely identify the current system and improve the stability of the cluster environment.
[0026] 3. It helps simplify the disk image deployment process of cloned virtual machines, avoids introducing custom scripts to increase maintenance difficulty, and improves the efficiency of large-scale virtual machine deployment. Attached Figure Description
[0027] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0028] Figure 1 This is a flowchart of a method for synchronizing virtual machine machine-ids in the prior art.
[0029] Figure 2 This is a flowchart illustrating a virtual machine machine-id synchronization method according to an exemplary first embodiment of the present invention. Detailed Implementation
[0030] The embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0031] It should be noted that, in the absence of conflict, the following embodiments and features can be combined with each other; and, based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.
[0032] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this disclosure, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number of aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.
[0033] The following definitions of terms used in the embodiments are as follows:
[0034] Linux System: Linux is a free and open-source Unix-like operating system. It is primarily used in server environments and is a stable, multi-user network operating system.
[0035] The early boot phase: This is the process of loading device drivers using a temporarily mounted memory file system during the initial startup of the Linux system. Since the system needs to load device drivers to recognize the file system on the disk during startup, and the device drivers are stored on the disk file system, the initial boot is first completed using a temporary root file system that can be mounted in memory. After loading the device drivers within it, the disk can be recognized and its file system mounted. Then, the system switches to the root file system on the disk, thus completing the early boot process.
[0036] machine-id: A unique ID for a computer system, used to indicate the uniqueness of the current system, and has functions such as identity recognition and authentication.
[0037] The systemd program: The systemd initializer is the mother of all processes. It is responsible for booting the Linux host into a state where it can perform productive tasks. Its main tasks include mounting file systems, managing hardware, handling timers, and starting and managing the system services required for the production host.
[0038] The machine-id-setup program is a component of the systemd program. It is responsible for checking the current system's machine-id and other data, and deciding whether to refactor the machine-id based on the check results.
[0039] The / sys / class / dmi / id / product_uuid file contains the operating system ID generated by the kernel based on a combination of software and hardware factors. It can be used as a data source for the machine-id.
[0040] Virtual machine domain UUID: A universally unique identifier for the virtual machine environment built on the physical host.
[0041] The memory file / run / machine-id is a volatile file stored in memory, which temporarily stores newly generated machine-ids.
[0042] The disk file / etc / machine-id is a non-volatile file stored on a disk and used to permanently store the machine-id.
[0043] Figure 1 This is a flowchart of a virtual machine machine-id synchronization method according to an exemplary first embodiment of the present invention, as shown below. Figure 1 As shown, the method in this embodiment includes:
[0044] Step S1: The Linux system first enters the early boot stage and executes the systemd program;
[0045] Step S2: The systemd program starts initialization and calls the machine-id-setup program;
[0046] Step S3: Execute the machine-id-setup program to regenerate the virtual machine's machine-id and save it in the memory file / run / machine-id;
[0047] Step S4: Complete switch root by executing the systemd program, ending the early boot phase;
[0048] Step S5: Update the value saved in the memory file / run / machine-id to the disk file / etc / machine-id;
[0049] Step S6: Initialize all system services and complete system startup.
[0050] Step S4 in this embodiment includes: completing switch root by executing the systemd program, changing the permissions of the / etc directory from read-only to writable, and ending the early boot stage.
[0051] Step S5 of the method in this embodiment includes: updating the machine-id of the regenerated virtual machine saved in the memory file / run / machine-id to the disk file / etc / machine-id.
[0052] Step S6 of this embodiment includes: using the systemd program's process as the parent process of other processes, and managing all user-mode processes using the systemd program. At this point, the synchronized machine-id can correctly identify the uniqueness of the current system environment, ensuring the correctness of system service initialization.
[0053] Step S6 of the method in this embodiment includes: using the systemd program to start other services of the system to complete the system startup.
[0054] The present invention provides a method for synchronizing virtual machine machine-ids in an exemplary second embodiment. This embodiment is... Figure 1 In a preferred embodiment of the method shown, step S3 of the virtual machine machine-id synchronization method in this embodiment includes: executing the machine-id-setup program, regenerating the virtual machine machine-id based on the virtual machine domain uuid stored in the / sys / class / dmi / id / product_uuid file, and storing the newly generated machine-id in the memory file / run / machine-id.
[0055] In step S3 of this embodiment, since the system is still in the early boot stage and the permissions of the / etc directory are read-only, the newly generated machine-id is first saved in the memory file / run / machine-id. Step S3 of this embodiment is the basis for ensuring the machine-id.
[0056] In practical applications, the method of this embodiment has the following advantages:
[0057] Ensure that system services initialize with the correct system-unique identifier machine-id during startup to avoid conflicts when different nodes interact, and prevent other unforeseen problems caused by this, thereby enhancing the stability of system operation.
[0058] When multiple virtual machines are created on a host, the host can modify the domain UUID as needed according to custom rules. The proposed virtual machine-id synchronization method ensures that ` / etc / machine-id` is updated in real-time each time a virtual machine starts. By uniformly orchestrating the virtual machine-ids according to their functions and roles, the efficiency of managing complex virtual machine clusters can be significantly improved.
[0059] In a cloud computing cluster environment, the machine-id serves as a unique identifier for a local node and is a crucial basis for node authentication. It plays a vital role in interactions such as role identification, data synchronization, and load balancing among multiple nodes. Therefore, the method in this embodiment ensures the real-time correspondence between the system's machine-id and the domain UUID, providing essential support for the stable operation of cluster-related services.
[0060] The present invention also provides a computer storage medium storing a computer program thereon, wherein when the computer program is executed, the steps of the method are performed.
[0061] Finally, the present invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the steps of the method when executing the program.
[0062] This computer device has the same technical effects as the aforementioned virtual machine-id synchronization method.
[0063] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for synchronizing virtual machine machine-ids, characterized in that, The method includes: Step S1: The Linux system first enters the early boot stage and executes the systemd program; Step S2: The systemd program starts initialization and calls the machine-id-setup program; Step S3: Execute the machine-id-setup program to regenerate the virtual machine's machine-id and save it in the memory file / run / machine-id; Step S4: Complete switch root by executing the systemd program, ending the early boot phase; Step S5: Update the value saved in the memory file / run / machine-id to the disk file / etc / machine-id; Step S6: Initialize all system services to complete system startup; Step S4 includes: completing the switch root by executing the systemd program, changing the permissions of the / etc directory from read-only to write, and ending the early boot phase; Step S5 includes updating the machine-id of the regenerated virtual machine, which is saved in the memory file / run / machine-id, to the disk file / etc / machine-id.
2. The method for synchronizing virtual machine machine-id according to claim 1, characterized in that, Step S3 includes: executing the machine-id-setup program, regenerating the virtual machine's machine-id based on the virtual machine domain uuid stored in the / sys / class / dmi / id / product_uuid file, and storing the newly generated machine-id in the memory file / run / machine-id.
3. The method for synchronizing virtual machine machine-ids according to claim 1, characterized in that, Step S6 includes: setting the systemd program's process as the parent process of other processes, and using the systemd program to manage all user-mode processes.
4. The method for synchronizing virtual machine machine-id according to claim 1, characterized in that, Step S6 includes: using the systemd program to start other system services and complete the system startup.
5. A computer storage medium, characterized in that, The computer storage medium stores a computer program, which, when executed, performs the steps of the method as described in any one of claims 1-4.
6. A computer device, characterized in that, The computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to perform the steps of the method as described in any one of claims 1-4.