Virtual machine configuration script execution method and device, computer equipment and storage medium
By storing the virtual machine configuration script in the global image library and obtaining and executing the image file when the virtual machine is powered on, the problem of low virtual machine configuration efficiency in high-availability host migration is solved and the efficiency and transparency of automated virtual machine configuration are achieved. .
Patent Information
- Application Number
- CN202410842106.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-26
- Publication Date
- 2024-10-01
AI Technical Summary
In the existing technology, when a virtual machine is migrated to a high-availability host, the scripts and script image files stored locally on the host become invalid, resulting in low efficiency in automated virtual machine configuration and opaque configuration script execution processes and results.
Store the configuration scripts required for the virtual machine in the global image library, and mount the global image library on all hosts on the cloud platform. By obtaining the script directory configuration items when the virtual machine is powered on for the first time, the target secondary level is filtered out from the global image library. Configure the directory, package it into an image file, and mount it to the virtual machine CD-ROM drive to realize automatic configuration of the virtual machine.
Even in the case of high-availability host migration, virtual machines can still access the global image library, which improves the efficiency of automated virtual machine configuration and ensures high availability and transparency of configuration scripts.
Smart Images

Figure CN118733197A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of cloud computing technology, and in particular to a method and device for executing a virtual machine configuration script, a computer device and a storage medium. Background Art
[0002] With the development of information technology, cloud computing has gradually become a hot topic in the industry. As a management platform for cloud computing services, the cloud platform carries various businesses, and the automatic configuration of virtual machines is an important part of achieving efficient operation of the cloud platform.
[0003] In the related art, after a virtual machine is started for the first time, many configurations that the virtual machine needs to perform to meet its own business needs are written into scripts, and the automatic configuration of the virtual machine is achieved by executing the scripts.
[0004] However, in the related art, scripts and script image files are stored in the local storage of the host. When a high-availability (HA) host migration occurs for the virtual machine, the scripts and script image files stored in the local host will become invalid. The scripts and script image files need to be migrated to the host where the virtual machine is located, resulting in low efficiency in the automatic configuration of the virtual machine. Summary of the invention
[0005] In view of this, the present invention provides a method, apparatus, computer device and storage medium for executing a virtual machine configuration script to solve the problem of low efficiency of virtual machine automatic configuration in the related art.
[0006] In a first aspect, the present invention provides a method for executing a virtual machine configuration script, the method comprising:
[0007] When the virtual machine is powered on for the first time, obtaining a script directory configuration item of the virtual machine;
[0008] Based on the script directory configuration item, a target secondary configuration directory is screened out from a target global image library, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, the script directory includes at least one secondary configuration directory, and each of the secondary configuration directories includes a configuration script required for a type of virtual machine;
[0009] Packaging the configuration scripts in the target secondary configuration directory to obtain an image file;
[0010] Mounting the image file to the optical drive of the virtual machine;
[0011] When the virtual machine completes the boot operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, and the configuration script in the image file is executed in the virtual machine.
[0012] The virtual machine configuration script execution method provided in this embodiment obtains the script directory configuration item of the virtual machine when the virtual machine is powered on for the first time, and based on the script directory configuration item, selects the target secondary configuration directory from the target global image library, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, the script directory includes at least one secondary configuration, each secondary configuration directory includes a configuration script required for a type of virtual machine, the configuration script under the target secondary configuration directory is packaged and processed, the image file is obtained, the image file is mounted to the optical drive of the virtual machine, and when the virtual machine completes the power-on operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, and the configuration script in the image file is executed in the virtual machine. By mounting the global image library on all hosts of the cloud platform, this embodiment can access the global image library even if the virtual machine undergoes high-availability host migration, obtain the configuration script under the target secondary configuration directory in the global image library, and then execute the configuration script to realize the automatic configuration of the virtual machine, thereby improving the efficiency of the automatic configuration of the virtual machine and ensuring that the virtual machine can complete the automatic configuration normally.
[0013] In an optional implementation, the step of filtering out a target secondary configuration directory from a target global image library based on the script directory configuration item includes:
[0014] Obtain the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library;
[0015] Based on the global image library identifier, determining the target global image library;
[0016] The target secondary configuration directory is determined based on the absolute path of the secondary configuration directory in the target global image repository.
[0017] The virtual machine configuration script execution method provided in this embodiment obtains the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library, determines the target global image library based on the global image library identifier, and determines the target secondary configuration directory based on the absolute path of the secondary configuration directory in the target global image library, thereby achieving the effect of quickly locating the target global image library and the target secondary configuration directory, and improving the efficiency of virtual machine automatic configuration.
[0018] In an optional embodiment, the method further includes:
[0019] After the virtualization environment of the cloud platform is initialized, detecting whether there is a global image library in the virtualization environment of the cloud platform;
[0020] In the case where a global image library exists in the virtualized environment of the cloud platform, establishing a first script directory in the global image library;
[0021] In response to the upload operation, at least one secondary configuration directory under the first script directory is obtained, wherein the secondary configuration directory includes at least one main configuration script named according to the first agreed rule, and the main configuration script is used to constrain the execution order of other configuration scripts under the secondary configuration directory except the main configuration script;
[0022] In response to the query operation, displaying the corresponding secondary configuration directory under the first script directory;
[0023] In response to the deletion operation, deleting the corresponding secondary configuration directory under the first script directory;
[0024] In the case where there is no global image library in the virtualized environment of the cloud platform, a new global image library is established, and a second script directory is established in the new global image library;
[0025] In response to the upload operation, obtaining at least one secondary configuration directory under the second script directory;
[0026] In response to the query operation, displaying the corresponding secondary configuration directory under the second script directory;
[0027] In response to the deletion operation, the corresponding secondary configuration directory under the second script directory is deleted.
[0028] The virtual machine configuration script execution method provided in this embodiment ensures the orderly storage of configuration scripts by detecting the existence of a global image library and deciding whether to create a new global image library accordingly, thereby ensuring that the virtual machine is automatically configured according to the configuration script in the global image library. At the same time, the establishment of the first script directory and the second script directory, as well as the upload, query and deletion operations of the secondary configuration directory, realize the efficient management and flexible calling of the configuration script.
[0029] In an optional implementation, after obtaining the image file, the method further includes:
[0030] The image file is named according to the second agreed rule.
[0031] The virtual machine configuration script execution method provided in this embodiment facilitates obtaining the correct image file by naming the image file according to the second agreed rule, thereby ensuring the accuracy of the virtual machine automatic configuration.
[0032] In an optional implementation, before importing the image file in the optical drive of the virtual machine into the virtual machine, the method further includes:
[0033] Detecting whether there is an image file named according to the second agreed rule in the optical drive of the virtual machine;
[0034] The step of importing the image file in the optical drive of the virtual machine into the virtual machine includes:
[0035] In the case that the optical drive of the virtual machine has an image file named according to the second convention, the image file named according to the second convention is imported into the virtual machine.
[0036] The virtual machine configuration script execution method provided in this embodiment obtains an image file named according to the second agreed rule and imports the image file named according to the second agreed rule into the virtual machine, thereby ensuring the accuracy of the virtual machine automatic configuration.
[0037] In an optional implementation, executing the configuration script in the image file in the virtual machine includes:
[0038] Obtain the main configuration script in the image file;
[0039] Execute the main configuration script to determine the execution order of other configuration scripts in the image file except the main configuration script;
[0040] Execute other configuration scripts in the image file according to the execution order.
[0041] The virtual machine configuration script execution method provided in this embodiment automatically controls the execution order of other configuration scripts through the main configuration script, thereby realizing the automation of virtual machine configuration and improving the efficiency of virtual machine automatic configuration.
[0042] In an optional embodiment, the method further includes:
[0043] Acquire execution information of the configuration script in the image file being executed in real time;
[0044] The execution information is periodically filled into a target file of the host where the virtual machine is located, so that a user can obtain the execution information through the target file.
[0045] The virtual machine configuration script execution method provided in this embodiment realizes the persistence of the configuration script execution progress, log and results by periodically filling the execution information of the configuration script in the image file into the target file of the host where the virtual machine is located, so that the user can obtain the execution information through the target file, thereby ensuring the reliability of the configuration script execution and the transparency of the configuration script execution process and results.
[0046] In a second aspect, the present invention provides a virtual machine configuration script execution device, the device comprising:
[0047] A first acquisition module is used to acquire a script directory configuration item of the virtual machine when the virtual machine is powered on for the first time;
[0048] A screening module is used to screen out a target secondary configuration directory from a target global image library based on the script directory configuration item, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, the script directory includes at least one secondary configuration directory, and each of the secondary configuration directories includes a configuration script required for a type of virtual machine;
[0049] A second acquisition module is used to package the configuration scripts under the target secondary configuration directory to obtain an image file;
[0050] A mounting module, used for mounting the image file to the optical drive of the virtual machine;
[0051] The execution module is used to import the image file in the optical drive of the virtual machine into the virtual machine when the virtual machine completes the boot operation, and execute the configuration script in the image file in the virtual machine.
[0052] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the virtual machine configuration script execution method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0053] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the virtual machine configuration script execution method of the first aspect or any corresponding embodiment thereof.
[0054] In a fifth aspect, the present invention provides a computer program product, including computer instructions, where the computer instructions are used to enable a computer to execute the virtual machine configuration script execution method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0055] In order to more clearly illustrate the specific embodiments of the present invention or the technical solutions in the related technologies, the drawings required for use in the specific embodiments or the related technical descriptions will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0056] Figure 1 is a flow chart of a method for executing a virtual machine configuration script according to an embodiment of the present invention;
[0057] Figure 2 is a flow chart of another virtual machine configuration script execution method according to an embodiment of the present invention;
[0058] Figure 3 is a schematic diagram of managing a global image library by a script management device according to an embodiment of the present invention;
[0059] Figure 4 It is a schematic diagram of a probe device acquiring execution information and a script execution query device reading and writing execution information according to an embodiment of the present invention;
[0060] Figure 5 is a structural block diagram of a virtual machine configuration script execution device according to an embodiment of the present invention;
[0061] Figure 6 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0062] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0063] With the development of information technology, cloud computing has gradually become a hot topic in the industry. Cloud computing service platforms have also begun to be used in many fields such as science, education, culture, health, high-performance computing, e-commerce, and the Internet of Things. Cloud computing includes the following levels of services: Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS). At the infrastructure as a service level, the cloud platform, as a management platform for cloud computing services, carries various businesses and plays an important role in it. The large number of virtual machines managed by the cloud platform, which carry a variety of functional businesses, are the working units of cloud computing. The automated configuration of virtual machines is an important link in achieving efficient operation of the cloud platform.
[0064] In the related art, after the first startup of a virtual machine in a production environment, it is usually necessary to perform a lot of internal configurations to meet its own business needs, such as configuring the network, configuring the firewall, injecting initialization data into related files, and initializing business-related applications. If this process is completed manually, it will not only generate a lot of workload, but also increase the risk of configuration errors due to cumbersome operations. At the same time, as the scale of the virtualization environment increases, the difficulty of manually configuring the virtual machines in the environment will also increase sharply.
[0065] Therefore, the important configurations of the virtual machine to meet its own business needs are written into scripts, and the virtual machine is automatically configured by executing the scripts. However, there are some shortcomings in the script execution method process in the related art:
[0066] 1. When creating a virtual machine, the script and the script image file (ISO) are created. However, the script ISO is not actually loaded until the virtual machine is started. During this period, redundant storage space is actually occupied. As the scale of the virtual machine environment expands and the number of virtual machines increases, the resulting storage loss cannot be ignored.
[0067] 2. Store scripts and script ISO files in the local storage of the host. Once the virtual machine undergoes HA host migration, the scripts and script image files stored in the local host will become invalid. The scripts and script image files need to be migrated to the host where the virtual machine is located, resulting in low efficiency in virtual machine automatic configuration. At the same time, scripts distributed in the local storage of each host are not conducive to management. Among them, after the HA function of the cluster is enabled, the virtual machines in the cluster will automatically restart when they encounter a fault. When the host in the cluster fails, the virtual machines on the failed host will automatically migrate to other hosts to ensure the continuity and high availability of the services on the virtual machines.
[0068] 3. The script execution process and results are not transparent. To obtain the script execution results, you still need to manually execute commands inside the virtual machine to view them, which increases the workload.
[0069] In summary, the configuration script execution process of related technologies has problems such as script discreteness, storage redundancy, low high availability and opaque results.
[0070] An embodiment of the present invention provides a method for executing a virtual machine configuration script. By storing the configuration scripts required by different types of virtual machines in a global image library, and mounting the global image library on all hosts of a cloud platform, even if an HA host migration occurs to the virtual machine, the global image library can be accessed to obtain the configuration script under the target secondary configuration directory in the global image library, and then the configuration script is executed to realize the automatic configuration of the virtual machine, so as to ensure that the automatic configuration of the virtual machine is completed normally and improve the efficiency of the automatic configuration of the virtual machine.
[0071] According to an embodiment of the present invention, an embodiment of a method for executing a virtual machine configuration script is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0072] In this embodiment, a virtual machine configuration script execution method is provided, which can be used in mobile terminals, such as servers, central processing units, etc. Figure 1 is a flowchart of a method for executing a virtual machine configuration script according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0073] Step S101, when the virtual machine is powered on for the first time, a script directory configuration item of the virtual machine is obtained.
[0074] The script directory configuration item is configured when the virtual machine is created. The script directory configuration item includes two parameters: a global image library identifier and an absolute path of the secondary configuration directory in the target global image library.
[0075] It should be noted that there can be multiple global image libraries in a virtualized environment, so the target global image library is determined by the global image library identifier. Among them, the global image library identifier can be a global image library identity identifier (Identity document, referred to as: ID). Each global image library has a unique global image library ID.
[0076] After the virtual machine is created, the script directory configuration items of the virtual machine will be persisted to the database and associated with the virtual machine.
[0077] The cloud platform of this embodiment includes a script management device, a script execution query device and a probe device inside the virtual machine. Through these three devices, the flexibility of configuration script execution can be improved, and the high availability during configuration script execution and the reliability of script execution results can be guaranteed.
[0078] When the virtual machine is powered on for the first time, in the preprocessing stage of the power-on process, the script management device will perform a logical cut-in to check whether there is a script directory configuration item associated with the virtual machine in the database. If so, the script directory configuration item of the virtual machine is obtained from the database.
[0079] Step S102: based on the script directory configuration item, a target secondary configuration directory is screened out from the target global image library.
[0080] The global image library is mounted on all hosts in the cloud platform. The global image library includes a script directory, which includes at least one secondary configuration directory. Each secondary configuration directory includes a configuration script required for a type of virtual machine.
[0081] When the script directory configuration item of the virtual machine is obtained, a target global image library is determined from the virtualization environment, and a target secondary configuration directory is screened out from the target global image library.
[0082] It is understandable that the configuration script under the target secondary configuration directory is the configuration script required for automatic configuration of the virtual machine.
[0083] Step S103, packaging the configuration script in the target secondary configuration directory to obtain an image file.
[0084] After the target secondary configuration directory is screened out, the configuration script under the target secondary configuration directory is obtained, and the configuration script under the target secondary configuration directory is packaged to obtain an image file. The image file has open read and execute permissions.
[0085] Step S104, mounting the image file to the optical drive of the virtual machine.
[0086] After the image file is obtained, the image file is mounted to the optical drive of the virtual machine.
[0087] Step S105, when the virtual machine completes the boot operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, and the configuration script in the image file is executed in the virtual machine.
[0088] In this embodiment, when the virtual machine completes the boot operation, the probe device inside the virtual machine will start automatically and perform a mount operation on the image file in the optical drive of the virtual machine (which may vary depending on the virtual machine operating system, and a Linux-like operating system is taken as an example here) to import the image file into the virtual machine and execute the configuration script in the image file in the virtual machine.
[0089] The virtual machine configuration script execution method provided in the present embodiment obtains the script directory configuration items of the virtual machine when the virtual machine is powered on for the first time, and based on the script directory configuration items, selects the target secondary configuration directory from the target global image library, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, the script directory includes at least one secondary configuration, each secondary configuration directory includes a configuration script required for a type of virtual machine, the configuration scripts in the target secondary configuration directory are packaged to obtain an image file, the image file is mounted to the optical drive of the virtual machine, and when the virtual machine completes the power-on operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, and the configuration script in the image file is executed in the virtual machine. In the actual startup phase of resource scheduling after the startup process, the virtual machine may undergo HA host migration due to various reasons, such as current host failure, current host insufficient memory, etc. Since this embodiment mounts the global image library on all hosts of the cloud platform, even if the virtual machine undergoes high-availability host migration, it can still access the global image library and obtain the configuration script under the target secondary configuration directory in the global image library, thereby meeting high availability, and then executing the configuration script to realize automatic configuration of the virtual machine, thereby improving the efficiency of automatic configuration of the virtual machine, ensuring that the virtual machine can complete the automatic configuration normally, and flexibly executing any custom script.
[0090] This embodiment manages the configuration script in the dimension of the script directory, stores it in the global image library, and decouples it from the virtual machine, thereby improving flexibility and facilitating unified management. The timing of mounting the script image file to the virtual machine is delayed until the virtual machine is powered on, and high availability is provided for the configuration script execution process based on the global image library, so that even if the virtual machine undergoes HA host migration, the configuration script execution is not affected.
[0091] In this embodiment, a virtual machine configuration script execution method is provided, which can be used in mobile terminals, such as servers, central processing units, etc. Figure 2 is a flowchart of a method for executing a virtual machine configuration script according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0092] Step S201, when the virtual machine is powered on for the first time, obtain the script directory configuration item of the virtual machine. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0093] Step S202: based on the script directory configuration item, filter out a target secondary configuration directory from the target global image library.
[0094] Specifically, the above step S202 includes:
[0095] Step S2021, obtaining the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library.
[0096] Among them, when the virtual machine is powered on for the first time, the script management device detects that there is a script directory configuration item associated with the virtual machine in the database, and then obtains the script directory configuration item, which is essentially to obtain the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library.
[0097] Step S2022: Determine the target global image repository based on the global image repository identifier.
[0098] After obtaining the global image library identifier, the script management device will determine the target global image library based on the global image library identifier, that is, obtain the global image library whose global image library identifier is the same as the global image library identifier in the script configuration directory item from the cloud platform, and use the global image library with the same identifier as the target image library.
[0099] Step S2023: Determine the target secondary configuration directory based on the absolute path of the secondary configuration directory in the target global image repository.
[0100] After obtaining the absolute path of the secondary configuration directory in the target global image library, the target secondary configuration directory in the target global image library can be determined according to the absolute path of the secondary configuration directory in the target global image library and the target global image library.
[0101] Step S203: Pack the configuration scripts in the target secondary configuration directory to obtain an image file. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0102] Step S204: Mount the image file to the CD-ROM drive of the virtual machine. Figure 1 Step S104 of the illustrated embodiment will not be described in detail here.
[0103] Step S205, when the virtual machine completes the boot operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, and the configuration script in the image file is executed in the virtual machine.
[0104] Specifically, the above step S205 includes:
[0105] Step S2051, obtaining the main configuration script in the image file.
[0106] Among them, to execute the configuration script in the image file in the virtual machine, the probe device inside the virtual machine first needs to obtain the main configuration script in the image file. The main configuration script is the entry point for the configuration script execution to constrain the execution order of the configuration script in a multi-script scenario.
[0107] Step S2052, executing the main configuration script, and determining the execution order of other configuration scripts in the image file except the main configuration script.
[0108] The probe device inside the virtual machine can determine the execution order of other configuration scripts except the main configuration script in the image file by executing the main configuration script.
[0109] Step S2053: execute other configuration scripts in the image file in the execution order.
[0110] The probe device inside the virtual machine executes other configuration scripts in the image file according to the execution order of other configuration scripts to realize the automatic configuration of the virtual machine.
[0111] The virtual machine configuration script execution method provided in this embodiment obtains the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library, determines the target global image library based on the global image library identifier, and determines the target secondary configuration directory based on the absolute path of the secondary configuration directory in the target global image library, thereby achieving the effect of quickly locating the target global image library and the target secondary configuration directory, and improving the efficiency of virtual machine automatic configuration.
[0112] The main configuration script automatically controls the execution order of other configuration scripts, thereby realizing the automation of virtual machine configuration and improving the efficiency of virtual machine automatic configuration.
[0113] In some optional implementations, the virtual machine configuration script execution method further includes:
[0114] Step a1: after the virtualization environment of the cloud platform is initialized, it is detected whether there is a global image library in the virtualization environment of the cloud platform.
[0115] Among them, a cloud platform usually has multiple host nodes. The global image library is mounted on all hosts in the cloud platform and is a storage pool available to all host nodes.
[0116] After the virtualization environment of the cloud platform is initialized, the script management device first detects whether there is a global image library in the virtualization environment of the cloud platform.
[0117] Step a2: When a global image library exists in the virtualized environment of the cloud platform, a first script directory is established in the global image library.
[0118] in, Figure 3 FIG. 1 is a schematic diagram of a script management device managing a global image library according to an embodiment of the present invention. Figure 3 As shown, when the script management device detects that there is a global image library in the virtualized environment of the cloud platform, it directly creates a first script directory, i.e., the script directory in the figure, in the global image library, and then manages the first script directory, specifically including uploading, querying, and deleting secondary configuration directories and configuration scripts. The script management device provides a management interface to the outside, so that users can upload, query, and delete secondary configuration directories and configuration scripts through the management interface.
[0119] Step a3, in response to the upload operation, obtain at least one secondary configuration directory under the first script directory, wherein the secondary configuration directory includes at least one main configuration script named according to the first agreed rule, and the main configuration script is used to constrain the execution order of other configuration scripts in the secondary configuration directory except the main configuration script.
[0120] Among them, the user sets the secondary configuration directory under the first script directory according to the type of virtual machine, and uploads the corresponding configuration script under the secondary configuration directory. It should be noted that a secondary configuration directory and the configuration script under the secondary configuration directory correspond to a type of virtual machine and the configuration script required by the type of virtual machine. There can be one or more configuration scripts under a secondary configuration directory.
[0121] For example, Figure 3 As shown, the user sets two secondary configuration directories under the first script directory according to the type of virtual machine, namely, secondary configuration directory-1 and secondary configuration directory-2. Scripts 1-1 and 1-2 are uploaded to secondary configuration directory-1, and scripts 2-1 and 2-2 are uploaded to secondary configuration directory-2. Among them, scripts 1-1 and 1-2 are configuration scripts required for virtual machines of one type, and scripts 2-1 and 2-2 are configuration scripts required for virtual machines of another type.
[0122] In this way, the differentiated configuration scripts required for different types of virtual machines are aggregated into the script directory at the granularity of the secondary configuration directory for unified management.
[0123] At the same time, each secondary configuration directory includes at least one main configuration script named according to the first agreed rule, which serves as the entry for subsequent script execution to constrain the execution order of configuration scripts in a multi-script scenario, that is, to constrain the execution order of other configuration scripts in the secondary configuration directory except the main configuration script.
[0124] It should be noted that the first agreed rule is set by a technical staff to distinguish the main configuration script from other configuration scripts, so that the main configuration script and other configuration scripts can be distinguished according to different naming methods to achieve automatic execution of the configuration scripts.
[0125] Step a4: in response to the query operation, display the corresponding secondary configuration directory under the first script directory.
[0126] In which, in response to the user's query operation on the secondary configuration directory under the first script directory, the script management device displays the corresponding secondary configuration directory under the first script directory, that is, the secondary configuration directory that the user wants to query, and can also display the configuration script under the secondary configuration directory.
[0127] Step a5: In response to the deletion operation, the corresponding secondary configuration directory under the first script directory is deleted.
[0128] In response to the user's deletion operation on the secondary configuration directory under the first script directory, the script management device deletes the corresponding secondary configuration directory under the first script directory, that is, the secondary configuration directory that the user wants to delete.
[0129] Of course, in response to the user's deletion operation on the configuration script under the secondary configuration directory, the script management device can delete the configuration script corresponding to the secondary configuration directory under the first script directory, that is, the configuration script that the user wants to delete.
[0130] Step a6: If there is no global image library in the virtualized environment of the cloud platform, a new global image library is established, and a second script directory is established in the new global image library.
[0131] Among them, when the script management device detects that there is no global image library in the virtualization environment of the cloud platform, it establishes a new global image library, establishes a second script directory in the new global image library, and then manages the second script directory, specifically including uploading, querying and deleting secondary configuration directories and configuration scripts.
[0132] Step a7: in response to the upload operation, obtaining at least one secondary configuration directory under the second script directory.
[0133] The user sets the secondary configuration directory under the second script directory according to the type of the virtual machine, and uploads the corresponding configuration script under the secondary configuration directory. The description of the secondary configuration directory is the same as above, and will not be repeated here.
[0134] Step a8: In response to the query operation, display the corresponding secondary configuration directory under the second script directory.
[0135] In which, in response to the user's query operation on the secondary configuration directory under the second script directory, the script management device displays the corresponding secondary configuration directory under the second script directory, that is, the secondary configuration directory that the user wants to query, and can also display the configuration script under the secondary configuration directory.
[0136] Step a9: in response to the deletion operation, delete the corresponding secondary configuration directory under the second script directory.
[0137] In response to the user's deletion operation on the secondary configuration directory under the second script directory, the script management device deletes the corresponding secondary configuration directory under the second script directory, that is, the secondary configuration directory that the user wants to delete.
[0138] Of course, in response to the user's deletion operation on the configuration script under the secondary configuration directory, the script management device can delete the configuration script corresponding to the secondary configuration directory under the second script directory, that is, the configuration script that the user wants to delete.
[0139] The virtual machine configuration script execution method provided in this embodiment ensures the orderly storage of configuration scripts by detecting the existence of a global image library and deciding whether to create a new global image library accordingly, thereby ensuring that the virtual machine is automatically configured according to the configuration script in the global image library. At the same time, the establishment of the first script directory and the second script directory, as well as the upload, query and deletion operations of the secondary configuration directory, realize the efficient management and flexible calling of the configuration script.
[0140] In some optional implementations, after obtaining the image file, the virtual machine configuration script execution method further includes:
[0141] Step b1, naming the image file according to the second agreed rule.
[0142] After obtaining the image file, the script management device also needs to name the image file according to the second agreed rule. After naming the image file according to the second agreed rule, the image file named according to the second agreed rule is mounted to the optical drive of the virtual machine.
[0143] It should be noted that the second agreed rule is set by a technical staff and is used to indicate that the image file is a file for realizing automatic configuration of a virtual machine.
[0144] The virtual machine configuration script execution method provided in this embodiment facilitates obtaining the correct image file by naming the image file according to the second agreed rule, thereby ensuring the accuracy of the virtual machine automatic configuration.
[0145] In some optional implementations, before importing the image file in the optical drive of the virtual machine into the virtual machine, the virtual machine configuration script execution method further includes:
[0146] Step c1, detecting whether there is an image file named according to the second agreed rule in the optical drive of the virtual machine.
[0147] When the virtual machine completes the boot operation, the probe device inside the virtual machine will start automatically to detect whether there is an image file named according to the second agreed rule in the optical drive of the virtual machine.
[0148] The above step S205 includes:
[0149] Step d1: if there is an image file named according to the second agreed rule in the optical drive of the virtual machine, import the image file named according to the second agreed rule into the virtual machine.
[0150] When the probe device inside the virtual machine detects that there is an image file named according to the second agreed rule in the optical drive of the virtual machine, the image file named according to the second agreed rule is imported into the virtual machine.
[0151] The virtual machine configuration script execution method provided in this embodiment obtains an image file named according to the second agreed rule and imports the image file named according to the second agreed rule into the virtual machine, thereby ensuring the accuracy of the virtual machine automatic configuration.
[0152] In some optional implementations, the virtual machine configuration script execution method further includes:
[0153] Step e1, obtaining execution information of the configuration script in the image file being executed in real time.
[0154] When the virtual machine executes the configuration script of the image file, the probe device inside the virtual machine will obtain the execution information of the configuration script in the image file being executed in real time. The execution information includes the execution progress, execution log and execution result of the configuration script.
[0155] Figure 4 This is a schematic diagram of the probe device acquiring execution information and the script execution query device reading and writing execution information according to an embodiment of the present invention. Figure 4 As shown, the probe device inside the virtual machine will obtain the execution information of the configuration script in the image file being executed by the corresponding virtual machine in real time. For example, the probe device in virtual machine-1 obtains the execution information of the configuration script in the image file being executed by virtual machine-1, the probe device in virtual machine-2 obtains the execution information of the configuration script in the image file being executed by virtual machine-2, and the probe device in virtual machine-3 obtains the execution information of the configuration script in the image file being executed by virtual machine-3.
[0156] Step e2, periodically filling the execution information into the target file of the host where the virtual machine is located, so that the user can obtain the execution information through the target file.
[0157] The probe device inside the virtual machine periodically reports the execution information of the configuration script to the script execution query device by calling back the script execution query device of the cloud platform. The script execution query device overwrites the acquired execution information of the configuration script to a designated file specific to the virtual machine under the host machine for persistence.
[0158] like Figure 4 As shown, the probe device periodically feeds back the acquired execution information to the script execution query device. The script execution query device overwrites the execution information to a designated file specific to the virtual machine under the host machine for persistence. For example, the execution information of the configuration script in the image file being executed by virtual machine-1 is overwritten to the execution result file-1, the execution information of the configuration script in the image file being executed by virtual machine-2 is overwritten to the execution result file-2, and the execution information of the configuration script in the image file being executed by virtual machine-3 is overwritten to the execution result file-3.
[0159] The execution result file is the target file, that is, a designated file specific to the virtual machine on the host machine.
[0160] It should be noted that the host machine is the host where the virtual machine is located. The target file is a designated file under the host machine that is specific to the virtual machine. The target file is available for external query at any time, making the script execution process transparent. In other words, the user can query the execution information of the configuration script through the target file. After receiving the user's execution information query request, the script execution query device will read the execution information in the target file and return the execution information in the target file to the user.
[0161] like Figure 4 As shown, the script execution query device provides a query interface, through which the user queries the execution information of the configuration script being executed by any virtual machine. The script execution query device receives the user's query request, reads the execution information in the target file, and returns the execution information in the target file to the user through the query interface.
[0162] It should be further explained that the last report will be made after all configuration scripts in the image file are executed.
[0163] The virtual machine configuration script execution method provided in this embodiment realizes the persistence of the configuration script execution progress, log and results by periodically filling the execution information of the configuration script in the image file into the target file of the host where the virtual machine is located, and provides a query interface to the outside world, so that the user can obtain the execution information through the target file, thereby ensuring the reliability of the configuration script execution and the transparency of the configuration script execution process and results.
[0164] In some optional implementations, in response to the upload operation, obtaining at least one secondary configuration under the first script directory includes:
[0165] Get the user's permission information.
[0166] When the permission information indicates that the user has permission to manage the global image library, in response to the user's upload operation, a secondary configuration directory under the first script directory set according to the type of the virtual machine and a corresponding configuration script under the secondary configuration directory are obtained.
[0167] In the case where the permission information indicates that the user does not have the permission to manage the global image library, access failure information is returned to prompt the user that the user does not have the permission to manage the global image library.
[0168] It is understandable that, when the permission information indicates that the user has the permission to manage the global image library, in response to the user's query operation, the corresponding secondary configuration directory under the first script directory is displayed.
[0169] When the permission information indicates that the user has the permission to manage the global image library, in response to the deletion operation, the corresponding secondary configuration directory under the first script directory is deleted.
[0170] The virtual machine configuration script execution method provided in this embodiment realizes fine permission control of the global image library by obtaining user permission information and executing corresponding operations according to whether the user has the permission to manage the global image library. Only users with management permissions can perform operations such as upload, query and delete, which protects the security and integrity of the global image library.
[0171] In some optional implementations, before mounting the image file to the optical drive of the virtual machine, the virtual machine configuration script execution method further includes:
[0172] The image file is compressed to obtain a compressed image file.
[0173] Mount the compressed image file to the virtual machine's CD-ROM drive.
[0174] It is understandable that, when the virtual machine completes the boot operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, the image file is decompressed in the virtual machine to obtain the decompressed image file, and the configuration script in the image file is executed.
[0175] The virtual machine configuration script execution method provided in this embodiment saves storage space for large-scale virtual machine deployment environments by compressing the image file and then mounting it to the virtual machine. Smaller compressed files can be transferred to the virtual machine's optical drive more quickly, thereby improving transmission efficiency and reducing deployment time.
[0176] In this embodiment, a virtual machine configuration script execution device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0177] This embodiment provides a virtual machine configuration script execution device, such as Figure 5 As shown, including:
[0178] The first acquisition module 501 is used to acquire the script directory configuration item of the virtual machine when the virtual machine is powered on for the first time.
[0179] The screening module 502 is used to screen out a target secondary configuration directory from a target global image library based on a script directory configuration item, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, and the script directory includes at least one secondary configuration directory, and each secondary configuration directory includes a configuration script required for a type of virtual machine.
[0180] The second acquisition module 503 is used to package the configuration scripts in the target secondary configuration directory to obtain an image file.
[0181] The mounting module 504 is used to mount the image file to the optical drive of the virtual machine.
[0182] The execution module 505 is used to import the image file in the optical drive of the virtual machine into the virtual machine when the virtual machine completes the boot operation, and execute the configuration script in the image file in the virtual machine.
[0183] In some optional implementations, the screening module 502 includes:
[0184] The first acquisition unit is used to acquire the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library.
[0185] The first determining unit is configured to determine a target global image library based on the global image library identifier.
[0186] The second determining unit is used to determine the target secondary configuration directory based on the absolute path of the secondary configuration directory in the target global image library.
[0187] In some optional implementations, the virtual machine configuration script execution device further includes:
[0188] The first detection unit is used to detect whether there is a global image library in the virtualization environment of the cloud platform after the virtualization environment of the cloud platform is initialized.
[0189] The first establishing unit is used to establish a first script directory in the global image library when there is a global image library in the virtualization environment of the cloud platform.
[0190] The second acquisition unit is used to obtain at least one secondary configuration directory under the first script directory in response to the upload operation, wherein the secondary configuration directory includes at least one main configuration script named according to the first agreed rule, and the main configuration script is used to constrain the execution order of other configuration scripts in the secondary configuration directory except the main configuration script.
[0191] The first display unit is used to display the corresponding secondary configuration directory under the first script directory in response to the query operation.
[0192] The first deleting unit is used to delete the corresponding secondary configuration directory under the first script directory in response to the deletion operation.
[0193] The second establishing unit is used to establish a new global image library when the global image library does not exist in the virtualization environment of the cloud platform, and to establish a second script directory in the new global image library.
[0194] The third obtaining unit is used to obtain at least one secondary configuration directory under the second script directory in response to the upload operation.
[0195] The second display unit is used to display the corresponding secondary configuration directory under the second script directory in response to the query operation.
[0196] The second deleting unit is used to delete the corresponding secondary configuration directory under the second script directory in response to the deletion operation.
[0197] In some optional implementations, after obtaining the image file, the virtual machine configuration script execution device further includes:
[0198] The naming unit is used to name the image file according to the second convention rule.
[0199] In some optional implementations, before importing the image file in the optical drive of the virtual machine into the virtual machine, the virtual machine configuration script execution device further includes:
[0200] The second detection unit is used to detect whether there is an image file named according to the second agreed rule in the optical drive of the virtual machine.
[0201] The execution module 505 includes:
[0202] The importing unit is used to import the image file named according to the second agreed rule into the virtual machine when the image file named according to the second agreed rule exists in the optical drive of the virtual machine.
[0203] In some optional implementations, the execution module 505 includes:
[0204] The fourth obtaining unit is used to obtain the main configuration script in the image file.
[0205] The first execution unit is used to execute the main configuration script and determine the execution order of other configuration scripts in the image file except the main configuration script.
[0206] The second execution unit is used to execute other configuration scripts in the image file according to the execution order.
[0207] In some optional implementations, the virtual machine configuration script execution device further includes:
[0208] The fifth acquisition unit is used to acquire the execution information of the configuration script in the image file being executed in real time.
[0209] The filling unit is used to periodically fill the execution information into the target file of the host where the virtual machine is located, so that the user can obtain the execution information through the target file.
[0210] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0211] The virtual machine configuration script execution device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0212] The embodiment of the present invention also provides a computer device having the above Figure 5 The virtual machine configuration script execution device is shown.
[0213] See also Figure 6 , Figure 6 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 6As shown, the computer device includes: one or more processors 601, memory 602, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components utilize different buses to communicate with each other, and can be installed on a common mainboard or installed in other ways as required. The processor can process the instructions executed in the computer device, including instructions stored in the memory or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides part of the necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 6 A processor 601 is taken as an example.
[0214] The processor 601 may be a central processing unit, a network processor or a combination thereof. The processor 601 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0215] The memory 602 stores instructions executable by at least one processor 601 , so that the at least one processor 601 executes the method shown in the above embodiment.
[0216] The memory 602 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 602 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 602 may optionally include a memory remotely arranged relative to the processor 601, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0217] The memory 602 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 602 may also include a combination of the above types of memory.
[0218] The computer device also includes a communication interface 603, which is used for the computer device to communicate with other devices or a communication network.
[0219] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0220] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0221] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A method for executing a virtual machine configuration script, characterized in that: The method comprises: When the virtual machine is powered on for the first time, obtaining a script directory configuration item of the virtual machine; Based on the script directory configuration item, a target secondary configuration directory is screened out from a target global image library, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, the script directory includes at least one secondary configuration directory, and each of the secondary configuration directories includes a configuration script required for a type of virtual machine; Packaging the configuration scripts in the target secondary configuration directory to obtain an image file; Mounting the image file to the optical drive of the virtual machine; When the virtual machine completes the boot operation, the image file in the optical drive of the virtual machine is imported into the virtual machine, and the configuration script in the image file is executed in the virtual machine.
2. The method according to claim 1, characterized in that: The step of filtering out a target secondary configuration directory from a target global image library based on the script directory configuration item includes: Obtain the global image library identifier in the script directory configuration item and the absolute path of the secondary configuration directory in the target global image library; Based on the global image library identifier, determining the target global image library; The target secondary configuration directory is determined based on the absolute path of the secondary configuration directory in the target global image repository.
3. The method according to claim 1, characterized in that The method further comprises: After the virtualization environment of the cloud platform is initialized, detecting whether there is a global image library in the virtualization environment of the cloud platform; In the case where a global image library exists in the virtualized environment of the cloud platform, establishing a first script directory in the global image library; In response to the upload operation, at least one secondary configuration directory under the first script directory is obtained, wherein the secondary configuration directory includes at least one main configuration script named according to the first agreed rule, and the main configuration script is used to constrain the execution order of other configuration scripts under the secondary configuration directory except the main configuration script; In response to the query operation, displaying the corresponding secondary configuration directory under the first script directory; In response to the deletion operation, deleting the corresponding secondary configuration directory under the first script directory; In the case where there is no global image library in the virtualized environment of the cloud platform, a new global image library is established, and a second script directory is established in the new global image library; In response to the upload operation, obtaining at least one secondary configuration directory under the second script directory; In response to the query operation, displaying the corresponding secondary configuration directory under the second script directory; In response to the deletion operation, the corresponding secondary configuration directory under the second script directory is deleted.
4. The method according to claim 1, characterized in that: After obtaining the image file, the method further includes: The image file is named according to the second agreed rule.
5. The method according to claim 1, characterized in that Before importing the image file in the optical drive of the virtual machine into the virtual machine, the method further includes: Detecting whether there is an image file named according to the second agreed rule in the optical drive of the virtual machine; The step of importing the image file in the optical drive of the virtual machine into the virtual machine includes: In the case that the optical drive of the virtual machine has an image file named according to the second convention, the image file named according to the second convention is imported into the virtual machine.
6. The method according to claim 1, characterized in that The executing the configuration script in the image file in the virtual machine includes: Obtain the main configuration script in the image file; Execute the main configuration script to determine the execution order of other configuration scripts in the image file except the main configuration script; Execute other configuration scripts in the image file according to the execution order.
7. The method according to claim 1, characterized in that The method further comprises: Acquire execution information of the configuration script in the image file being executed in real time; The execution information is periodically filled into a target file of the host where the virtual machine is located, so that a user can obtain the execution information through the target file.
8. A virtual machine configuration script execution device, characterized in that: The device comprises: A first acquisition module is used to acquire a script directory configuration item of the virtual machine when the virtual machine is powered on for the first time; A screening module is used to screen out a target secondary configuration directory from a target global image library based on the script directory configuration item, wherein the global image library is mounted on all hosts in the cloud platform, the global image library includes a script directory, the script directory includes at least one secondary configuration directory, and each of the secondary configuration directories includes a configuration script required for a type of virtual machine; A second acquisition module is used to package the configuration scripts under the target secondary configuration directory to obtain an image file; A mounting module, used for mounting the image file to the optical drive of the virtual machine; The execution module is used to import the image file in the optical drive of the virtual machine into the virtual machine when the virtual machine completes the boot operation, and execute the configuration script in the image file in the virtual machine.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the virtual machine configuration script execution method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the virtual machine configuration script execution method according to any one of claims 1 to 7.
