CN112099902A - Network adapter configuration method and device of virtual machine, electronic device and storage medium - Google Patents

Network adapter configuration method and device of virtual machine, electronic device and storage medium Download PDF

Info

Publication number
CN112099902A
CN112099902A CN202010825980.4A CN202010825980A CN112099902A CN 112099902 A CN112099902 A CN 112099902A CN 202010825980 A CN202010825980 A CN 202010825980A CN 112099902 A CN112099902 A CN 112099902A
Authority
CN
China
Prior art keywords
network adapter
virtual machine
network
configuration file
configuration
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010825980.4A
Other languages
Chinese (zh)
Inventor
曾建东
李乐乐
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Anheng Information Security Technology Co Ltd
Original Assignee
Hangzhou Anheng Information Security Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Anheng Information Security Technology Co Ltd filed Critical Hangzhou Anheng Information Security Technology Co Ltd
Priority to CN202010825980.4A priority Critical patent/CN112099902A/en
Publication of CN112099902A publication Critical patent/CN112099902A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/455Emulation; Interpretation; Software simulation, e.g. virtualisation or emulation of application or operating system execution engines
    • G06F9/45533Hypervisors; Virtual machine monitors
    • G06F9/45558Hypervisor-specific management and integration aspects
    • G06F2009/45595Network integration; Enabling network access in virtual machine instances

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

The application relates to a network adapter configuration method and device of a virtual machine, an electronic device and a storage medium. The network adapter configuration method of the virtual machine comprises the following steps: after the virtual machine is started, detecting the communication state of a network adapter of the virtual machine; under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal, network configuration information of a real host where the virtual machine is located is obtained; configuring a configuration file of the network adapter according to the network configuration information; restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to be effective. By the method and the device, the working efficiency of operation and maintenance personnel can be improved, and the problem that the configuration of the network adapter of the virtual machine needs to be manually operated by professional technical personnel through professional technical means and a user cannot operate the network adapter by himself/herself is solved.

Description

Network adapter configuration method and device of virtual machine, electronic device and storage medium
Technical Field
The present application relates to the field of internet technologies, and in particular, to a method and an apparatus for configuring a network adapter of a virtual machine, an electronic apparatus, and a storage medium.
Background
The virtual machine technology is widely applied in the fields of computers and the internet, wherein the most common virtual machine technology is the virtualization of a memory in an operating system, a memory space required by a user during actual operation is possibly far larger than the memory size of a physical machine, and by utilizing the memory virtualization technology, the user can virtualize a part of hard disks into the memory, which is transparent to the user. In addition, a secure, stable "tunnel" can be virtualized in a public network using Virtual Private Network (VPN), which the user feels like using a private network. However, the virtual machine technology also has some communication problems during the use process, for example, abnormal problems such as missing of configuration files of the network adapter and damage may occur after the virtual machine is started, so that the system cannot communicate with the outside.
In order to solve the problem of network adapter exception, some strategy methods for solving the problem have been developed. For example, the modification processing is performed manually to generate a new network adapter and create own network adapter configuration file content, or the configuration file of the existing network adapter is modified and adjusted manually and corrected. However, the method of manually solving the problem requires a professional technician and a professional technical means, and the user cannot solve the problem by himself.
At present, no effective solution is provided for the problem that the configuration of the network adapter of the virtual machine in the related art needs to be manually operated by a professional technician through a professional technical means and the user cannot operate the network adapter by himself.
Disclosure of Invention
The embodiment of the application provides a method, a device, an electronic device and a storage medium for configuring a network adapter of a virtual machine, so as to solve at least the problem that an exception such as missing, damage and the like of a configuration file of the network adapter may occur after the virtual machine is started in the related art.
In a first aspect, an embodiment of the present application provides a method for configuring a network adapter of a virtual machine, including:
step A, after a virtual machine is started, detecting the communication state of a network adapter of the virtual machine;
step B, under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal, network configuration information of a real host where the virtual machine is located is obtained;
step C, configuring the configuration file of the network adapter according to the network configuration information;
and D, restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to take effect.
In one embodiment, before the step a, the method further comprises:
generating a script program for executing the steps A to D;
writing the script program into the virtual machine, and setting to run the script program when the virtual machine is started.
In one embodiment, the step C includes:
judging whether a configuration file of the network adapter exists or not;
and generating the configuration file and writing the configuration information into the configuration file when judging that the configuration file of the network adapter does not exist.
In one embodiment, the step C further includes:
and under the condition that the configuration file of the network adapter is judged to exist, updating the configuration file according to the configuration information.
In one embodiment, determining whether the configuration file of the network adapter exists comprises:
inquiring whether the configuration file exists in a system of the virtual machine under a/etc/sysconfig/network-scripts path;
determining that the configuration file of the network adapter does not exist under the condition that the configuration file does not exist under the/etc/sysconfig/network-scripts path; otherwise, determining that the configuration file of the network adapter exists.
In one embodiment, the network configuration information of the real host includes at least one of: the physical address of the network adapter, the name of the network adapter, the type of the network adapter, and the start configuration information of the service corresponding to the network adapter.
In one embodiment, the step B includes:
and under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal, acquiring the network configuration information of the real host by executing an ip addr command.
In a second aspect, an embodiment of the present application provides a network adapter configuration device for a virtual machine, including:
the detection module is used for detecting the communication state of a network adapter of the virtual machine after the virtual machine is started;
the acquisition module is used for acquiring the network configuration information of the real host where the virtual machine is located under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal;
the configuration module is used for configuring the configuration file of the network adapter according to the network configuration information;
and the restarting module is used for restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to take effect.
In a third aspect, an embodiment of the present application provides an electronic apparatus, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the network adapter configuring method for a virtual machine according to the first aspect is implemented.
In a fourth aspect, an embodiment of the present application provides a storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method for configuring a network adapter of a virtual machine according to the first aspect.
Compared with the related technology, the method and the system can improve the working efficiency of the operation and maintenance personnel, and effectively avoid the problem that the operation and maintenance personnel with poor network service foundation need to spend a large amount of time to consult and investigate.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
fig. 1 is a terminal hardware configuration block diagram of a network adapter configuration method of a virtual machine according to an embodiment of the present application;
FIG. 2 is a flowchart of a method for configuring a network adapter of a virtual machine according to an embodiment of the present application;
fig. 3 is a flowchart of a method for configuring a network adapter of a virtual machine according to a first preferred embodiment of the present application;
fig. 4 is a flowchart of a network adapter configuration method for a virtual machine according to a second preferred embodiment of the present application;
fig. 5 is a block diagram of a configuration apparatus of a network adapter of a virtual machine according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments provided in the present application without any inventive step are within the scope of protection of the present application. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the specification. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of ordinary skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments without conflict.
Unless defined otherwise, technical or scientific terms referred to herein shall have the ordinary meaning as understood by those of ordinary skill in the art to which this application belongs. Reference to "a," "an," "the," and similar words throughout this application are not to be construed as limiting in number, and may refer to the singular or the plural. The present application is directed to the use of the terms "including," "comprising," "having," and any variations thereof, which are intended to cover non-exclusive inclusions; for example, a process, method, system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or elements, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. Reference to "connected," "coupled," and the like in this application is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Reference herein to "a plurality" means greater than or equal to two. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. Reference herein to the terms "first," "second," "third," and the like, are merely to distinguish similar objects and do not denote a particular ordering for the objects.
The method provided by the embodiment can be executed in a terminal, a computer or a similar operation device. Taking an example of running on a terminal, fig. 1 is a hardware structure block diagram of the terminal of the network adapter configuration method of a virtual machine according to the embodiment of the present application. As shown in fig. 1, the terminal may include one or more (only one shown in fig. 1) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, and optionally, a transmission device 106 for communication functions and an input-output device 108. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration and is not intended to limit the structure of the terminal. For example, the terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store a computer program, for example, a software program and a module of application software, such as a computer program corresponding to the network adapter configuration method of the virtual machine in the embodiment of the present application, and the processor 102 executes the computer program stored in the memory 104 to execute various functional applications and data processing, i.e., to implement the method described above. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
The embodiment provides a network adapter configuration method of a virtual machine. Fig. 2 is a flowchart of a method for configuring a network adapter of a virtual machine according to an embodiment of the present application, where, as shown in fig. 2, the flowchart includes the following steps:
in step S201, after the virtual machine is started, the communication state of the network adapter of the virtual machine is detected.
In this embodiment, the virtual machine may be a Linux or Windows system, or may be another operating system based on the virtual machine technology.
Step S202, when the communication state of the network adapter of the virtual machine is detected to be abnormal, acquiring network configuration information of the real host where the virtual machine is located.
Step S203, configuring the configuration file of the network adapter according to the network configuration information.
Step S204, restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to take effect.
In this embodiment, the function of restarting the service corresponding to the network adapter is that installation of a part of the program requires rewriting of the computer system registry, and the service corresponding to the network adapter can be used normally after restarting. Meanwhile, various network parameters such as a network IP address, a subnet mask and the like can be changed in the script operation process, and the service corresponding to the network adapter is restarted to acquire the parameter information again. The function of restarting the service corresponding to the network adapter is realized through a certain computer instruction. The computer instruction includes, but is not limited to, a network restart instruction, a root instruction, and other program instructions that enable a service corresponding to a network adapter of the computer system to be restarted.
In some of these embodiments. The network configuration information of the real host at least comprises: the physical address of the network adapter, the name of the network adapter, the type of the network adapter, and the start configuration information of the service corresponding to the network adapter.
In some of these embodiments, step S202 includes: and under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal, acquiring the network configuration information of the real host by executing the ip addr command. In this embodiment, the script obtains the network configuration information of the real host through the ip addr command, so that the network configuration information of the real host is conveniently compared with the current network configuration information in the subsequent steps, whether the network configuration information of the real host is consistent with the current network configuration information is judged, different processing is performed according to the judgment condition, the network configuration information of the virtual machine is always correct, and the normal communication of the virtual machine is ensured.
In some embodiments, a Virtual Machine (Virtual Machine) refers to a complete computer system with complete hardware system functionality, which is emulated by software and runs in a completely isolated environment. The network uses physical link to connect each isolated workstation or host to form data link, so as to achieve the purpose of resource sharing and communication. Communication is the communication and transfer of information from person to person through some medium. The network communication is realized by connecting each isolated device through a network and realizing the communication between people, between people and computers and between computers through information exchange. The virtual system has the same functions as a real operating system by generating a brand new virtual mirror image of the existing operating system, all operations are carried out in the brand new independent virtual system after the virtual system is accessed, running software can be independently installed, data can be stored, an independent desktop is owned, the real system cannot be influenced, and the virtual system has an operating system capable of flexibly switching between the existing system and the virtual mirror image.
In one embodiment, the Script (Script) is an executable file written according to a certain format using a particular descriptive language. Before the steps, the written executable script file is imported into the virtual machine system, and the pre-imported executable script file is synchronously executed when the system is started. The script file is the key content of the present application, and specifically includes: acquiring a correct configuration file of the network adapter, and comparing configuration contents of the existing system, wherein one of the two conditions is that the configuration file of the network adapter does not exist, and then the system automatically creates a corresponding configuration file of the network adapter according to a program written by a script and edits the contents of the configuration file, and network configuration information of a real host is edited into the configuration file; and secondly, if the configuration file of the corresponding network adapter exists, the system can adjust the content of the configuration file of the network adapter according to the program content of the script and write the acquired network configuration information of the real host into the specific content of the configuration file.
In the using process of the virtual machine, when the virtual system is started again after being led into a virtual environment, the problem that the virtual machine cannot normally communicate with the outside exists, and the main sources of the problem are two categories, namely that the virtual machine lacks configuration files of all network adapters, so that the virtual machine cannot normally communicate; the second is that the configuration file of the network adapter exists but the network configuration information thereof is abnormal, and the abnormal content includes the network card name inconsistency, the mac address inconsistency and other network configuration inconsistency. If the virtual system is kept in normal communication, the configuration file of the network adapter needs to be added or modified to the content of the normal communication requirement, and then normal communication can be realized. Through the steps, the edited script file is pre-imported into the system, and the script file can detect the configuration file state of the network adapter after the system is started and repair the abnormal or damaged configuration file of the network adapter, so that the normal communication of the system is ensured.
Through the steps, the configuration file of the network adapter can be automatically configured synchronously in the system starting process, normal communication can be realized after the service corresponding to the network adapter is restarted, the resources of the virtual system cannot be occupied, the starting time of the virtual system cannot be prolonged, and the problem that operation and maintenance personnel with poor network service bases need to spend a large amount of time to consult and investigate is effectively solved.
The script file in the embodiments of the present application is described and illustrated below by the preferred embodiments.
Preferred embodiment 1
In the preferred embodiment, a method for configuring a network adapter of a virtual machine is provided. Fig. 3 is a flowchart of a method for configuring a network adapter of a virtual machine according to a first preferred embodiment of the present application, where as shown in fig. 3, the flowchart includes the following steps:
in step S301, a script program is generated.
Step S302, writing the script program into the virtual machine, and setting the running of the script program when the virtual machine is started.
Step S303 is to detect a communication state of the network adapter of the virtual machine after the virtual machine is started.
In this embodiment, the virtual machine may be a Linux or Windows system, or may be another operating system based on the virtual machine technology.
Step S304, when the communication state of the network adapter of the virtual machine is detected to be abnormal, acquiring network configuration information of the real host where the virtual machine is located.
Step S305, configuring the configuration file of the network adapter according to the network configuration information.
Step S306, restart the service corresponding to the network adapter, so that the configuration file of the network adapter becomes effective.
Through the steps, the script file which is edited and imported into the system in advance is used for detecting whether the configuration file of the network adapter exists in the computer system, and then the configuration file of the network adapter existing in the system is compared with the acquired configuration file of the network adapter to judge the configuration information of the configuration files of the two network adapters. When the configuration information of the configuration files of the two network adapters is inconsistent, the configuration information in the configuration files of the network adapters in the system is deleted, and then the service information corresponding to the correct network adapter is synchronously updated into the configuration files of the existing network adapters, so that the configuration information of the configuration files of the network adapters is kept correct.
Through the operation of the script file, the script can automatically acquire the configuration file information of the network adapter in the virtual system and the correct service information corresponding to the network adapter through operating the computer program in the script file, and the correctness of the script file in the system is judged according to the configuration file information of the network adapter in the virtual system and the correct service information corresponding to the network adapter.
Preferred embodiment two
Fig. 4 is a flowchart of a method for configuring a network adapter of a virtual machine according to a second preferred embodiment of the present application, where as shown in fig. 4, the flowchart includes the following steps:
in step S401, a script program is generated.
Step S402, writing the script program into the virtual machine, and setting the script program to run when the virtual machine is started.
In step S403, after the virtual machine is started, the communication state of the network adapter of the virtual machine is detected.
In this embodiment, the virtual machine may be a Linux or Windows system, or may be another operating system based on the virtual machine technology.
Step S404, when the communication state of the network adapter of the virtual machine is detected to be abnormal, acquiring network configuration information of the real host where the virtual machine is located.
Step S405, determine whether the configuration file of the network adapter exists.
In step S406, if it is determined that the configuration file of the network adapter does not exist, a configuration file is generated, and the configuration information is written in the configuration file.
In this embodiment, if the comparison result indicates that the configuration file of the network adapter does not exist, the configuration file of the network adapter is generated, and the content of the configuration file of the network adapter is updated, which includes the following specific steps: the method comprises the following specific steps: checking and acquiring the content of the configuration file of the real network adapter in the system; generating a configuration file of the network adapter to a/etc/sysconfig/network-scripts directory of the system; editing and generating a configuration file of the network adapter, and updating the content of the configuration file of the real network adapter to the configuration file of the generated network adapter; the editing mode is exited after saving. The system creates a new configuration file of the network adapter according to the file directory specified by the computer program in the script file, ensures that service information corresponding to the network adapter of the configuration file of the network adapter is correct, and ensures that the virtual system can normally communicate.
In step S407, if it is determined that the configuration file of the network adapter already exists, the configuration file is updated according to the configuration information.
In this embodiment, if the comparison result indicates that the configuration file of the network adapter already exists, the configuration file is updated according to the configuration information, and the specific steps are as follows: checking and acquiring the content of the configuration file of the real network adapter in the system; synchronously updating the content of the configuration file of the real network adapter into the configuration file of the network adapter, wherein the content of the configuration file of the original network adapter in the configuration file of the network adapter needs to be deleted when the synchronization is updated, and then the content of the configuration file of the real network adapter is updated; save and exit the editing mode. Through the steps, the virtual system updates the previously acquired network configuration information of the real host to the configuration file of the network adapter under the condition that the configuration file of the network adapter exists, so that the correctness of the configuration file of the network adapter is ensured.
In this embodiment, when the comparison result shows that the configuration file of the network adapter exists in the system, which indicates that the configuration file of the network adapter may be damaged in the virtual system starting process, the computer program of the system according to the script may revise and edit the configuration information in the configuration file of the network adapter according to the configuration information acquired in the previous step, so as to ensure that the configuration information in the configuration file of the system network adapter is correct.
Step S408, restart the service corresponding to the network adapter, so that the configuration file of the network adapter becomes effective.
In this embodiment, when the comparison result indicates that the configuration file of the network adapter does not exist in the system, which indicates that the configuration file of the network adapter has been lost during the startup of the virtual system, the system may recreate a new blank configuration file of the network adapter under the specified path according to the computer program of the script. After creating the configuration file for the network adapter is complete, the system updates the previously obtained configuration information for the new blank network adapter's configuration file according to the computer program of the script.
In one embodiment, determining whether a configuration file for the network adapter exists comprises: inquiring whether a configuration file exists in a system of the virtual machine under a/etc/sysconfig/network-scripts path; determining that the configuration file of the network adapter does not exist under the condition that the configuration file does not exist under the/etc/sysconfig/network-scripts path; otherwise, determining that the configuration file of the network adapter exists. In this embodiment, the method is used to determine whether the configuration file of the network adapter exists, and the method is used to detect the state of the network adapter of the current virtual machine, so that the configuration file of the network adapter is configured according to the state of the network adapter of the current virtual machine in the subsequent steps, and the normal communication function of the virtual machine is ensured.
The present embodiment further provides a network adapter configuration device of a virtual machine, where the device is used to implement the foregoing embodiments and preferred embodiments, and details of which have been already described are omitted. As used hereinafter, the terms "module," "unit," "subunit," and the like may implement a combination of software and/or hardware for a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 5 is a block diagram of a configuration apparatus of a network adapter of a virtual machine according to an embodiment of the present application. As shown in fig. 5, the apparatus includes:
the detection module 51 is configured to detect a communication state of a network adapter of a virtual machine after the virtual machine is started;
an obtaining module 52, coupled to the detecting module 51, configured to obtain network configuration information of a real host where the virtual machine is located when the communication state of the network adapter of the virtual machine is detected to be abnormal;
a configuration module 53, coupled to the obtaining module 52, configured to configure a configuration file of the network adapter according to the network configuration information;
and the restarting module 54 is coupled to the configuration module 53, and is configured to restart the service corresponding to the network adapter, so as to validate the configuration file of the network adapter.
In some of these embodiments, the configuration module comprises: the judging unit is used for judging whether the configuration file of the network adapter exists or not; and the writing unit is coupled to the judging unit and used for generating the configuration file and writing the configuration information into the configuration file under the condition that the configuration file of the network adapter is judged not to exist.
In one embodiment, the configuration module further comprises: and the updating unit is coupled to the judging unit and used for updating the configuration file according to the configuration information under the condition that the configuration file of the network adapter is judged to exist.
In one embodiment, the determining unit includes: the query subunit is configured to query whether the configuration file exists in the system of the virtual machine under the/etc/sysconfig/network-scripts path; a determining subunit, coupled to the querying subunit, configured to determine that the configuration file of the network adapter does not exist in a case that the configuration file does not exist in the/etc/sysconfig/network-scripts path; otherwise, determining that the configuration file of the network adapter exists.
In one embodiment, the network configuration information of the real host includes at least one of: the physical address of the network adapter, the name of the network adapter, the type of the network adapter, and the start configuration information of the service corresponding to the network adapter.
In one embodiment, the obtaining module is configured to obtain the network configuration information of the real host by executing an ip addr command when detecting that a communication state of the network adapter of the virtual machine is abnormal.
The above modules may be functional modules or program modules, and may be implemented by software or hardware. For a module implemented by hardware, the modules may be located in the same processor; or the modules can be respectively positioned in different processors in any combination.
The embodiment also provides a network adapter configuration device of a virtual machine, which includes a memory and a processor, and is characterized in that the memory stores a computer program, and the processor is configured to execute the computer program to perform the network adapter configuration method of any virtual machine in the foregoing steps.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
Optionally, in this embodiment, the processor may be configured to execute the following steps by a computer program:
s1, after the virtual machine is started, detects a communication state of the network adapter of the virtual machine.
S2, when detecting that the communication state of the network adapter of the virtual machine is abnormal, acquires the network configuration information of the real host in which the virtual machine is located.
And S3, configuring the configuration file of the network adapter according to the network configuration information.
And S4, restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to be effective.
It should be noted that, for specific examples in this embodiment, reference may be made to examples described in the foregoing embodiments and optional implementations, and details of this embodiment are not described herein again.
The present embodiment further provides a storage medium for configuring a network adapter of a virtual machine, where the storage medium stores a computer program, and the computer program is configured to execute the method for configuring a network adapter of a virtual machine in any one of the above steps when the computer program runs.
Compared with the prior art, the method and the system have the advantages that the network adapter configuration of the virtual machine is realized by introducing the script into the system in advance, meanwhile, the missing configuration file of the network adapter can be generated under the condition that professional technicians do not need to operate, the damaged configuration file of the network adapter is repaired, and after the configuration file of the abnormal network adapter is repaired, the corresponding IP address and communication parameters can be set manually or through a third-party program, so that the method and the system have higher flexibility, a user without professional knowledge in the fields of Internet and computers can also automatically solve the problem of abnormal network adapter configuration of the virtual machine, the IP address of the network where the user is located is set, and the system can be ensured to realize a normal communication function.
In summary, the above embodiments or preferred embodiments provided by the present application have the following advantages:
1. in the embodiment of the application, the script file is pre-imported into the virtual system, and the script file automatically runs along with the starting of the virtual system. Therefore, the operation of the script file does not need manual operation, the computer program codes in the script file can be directly and automatically operated, a large amount of working benefits can be brought to operation and maintenance personnel, and a large amount of time is saved for technical personnel and the operation and maintenance personnel.
2. In the embodiment of the application, only the script is required to be imported into the computer, and the server is not required to be changed, so that the waste of human resources is reduced, and the change range is reduced.
It should be understood by those skilled in the art that various features of the above embodiments can be combined arbitrarily, and for the sake of brevity, all possible combinations of the features in the above embodiments are not described, but should be considered as within the scope of the present disclosure as long as there is no contradiction between the combinations of the features.
The above examples only represent one embodiment of the present application, and the description thereof is more specific and detailed, but not to be construed as limiting the claims. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A method for configuring a network adapter of a virtual machine is characterized by comprising the following steps:
step A, after a virtual machine is started, detecting the communication state of a network adapter of the virtual machine;
step B, under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal, network configuration information of a real host where the virtual machine is located is obtained;
step C, configuring the configuration file of the network adapter according to the network configuration information;
and D, restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to take effect.
2. The method of claim 1, wherein prior to step a, the method further comprises:
generating a script program for executing the steps A to D;
writing the script program into the virtual machine, and setting to run the script program when the virtual machine is started.
3. The method of claim 1, wherein step C comprises:
judging whether a configuration file of the network adapter exists or not;
and generating the configuration file and writing the configuration information into the configuration file when judging that the configuration file of the network adapter does not exist.
4. The method of claim 3, wherein step C further comprises:
and under the condition that the configuration file of the network adapter is judged to exist, updating the configuration file according to the configuration information.
5. The method of claim 3, wherein determining whether the configuration file for the network adapter exists comprises:
inquiring whether the configuration file exists in a system of the virtual machine under a/etc/sysconfig/network-scripts path;
determining that the configuration file of the network adapter does not exist under the condition that the configuration file does not exist under the/etc/sysconfig/network-scripts path; otherwise, determining that the configuration file of the network adapter exists.
6. The method of claim 1, wherein the network configuration information of the real host comprises at least one of: the physical address of the network adapter, the name of the network adapter, the type of the network adapter, and the start configuration information of the service corresponding to the network adapter.
7. The method according to any one of claims 1 to 6, wherein the step B comprises:
and under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal, acquiring the network configuration information of the real host by executing an ip addr command.
8. A network adapter configuring apparatus for a virtual machine, comprising:
the detection module is used for detecting the communication state of a network adapter of the virtual machine after the virtual machine is started;
the acquisition module is used for acquiring the network configuration information of the real host where the virtual machine is located under the condition that the communication state of the network adapter of the virtual machine is detected to be abnormal;
the configuration module is used for configuring the configuration file of the network adapter according to the network configuration information;
and the restarting module is used for restarting the service corresponding to the network adapter so as to enable the configuration file of the network adapter to take effect.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the computer program to perform the network adapter configuration method of the virtual machine according to any one of claims 1 to 7.
10. A storage medium having stored thereon a computer program, wherein the computer program is configured to execute the network adapter configuration method of a virtual machine according to any one of claims 1 to 7 when running.
CN202010825980.4A 2020-08-17 2020-08-17 Network adapter configuration method and device of virtual machine, electronic device and storage medium Pending CN112099902A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010825980.4A CN112099902A (en) 2020-08-17 2020-08-17 Network adapter configuration method and device of virtual machine, electronic device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010825980.4A CN112099902A (en) 2020-08-17 2020-08-17 Network adapter configuration method and device of virtual machine, electronic device and storage medium

Publications (1)

Publication Number Publication Date
CN112099902A true CN112099902A (en) 2020-12-18

Family

ID=73754478

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010825980.4A Pending CN112099902A (en) 2020-08-17 2020-08-17 Network adapter configuration method and device of virtual machine, electronic device and storage medium

Country Status (1)

Country Link
CN (1) CN112099902A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113839815A (en) * 2021-09-18 2021-12-24 浪潮电子信息产业股份有限公司 Server network port configuration method and device, server and readable storage medium
CN115150298A (en) * 2021-03-31 2022-10-04 北京金山云网络技术有限公司 Virtual gateway testing method and device, storage medium and electronic equipment

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115150298A (en) * 2021-03-31 2022-10-04 北京金山云网络技术有限公司 Virtual gateway testing method and device, storage medium and electronic equipment
CN115150298B (en) * 2021-03-31 2023-11-03 北京金山云网络技术有限公司 Virtual gateway testing method and device, storage medium and electronic equipment
CN113839815A (en) * 2021-09-18 2021-12-24 浪潮电子信息产业股份有限公司 Server network port configuration method and device, server and readable storage medium

Similar Documents

Publication Publication Date Title
CN113419815B (en) Method, system, equipment and medium for pre-starting operation environment installation
WO2017185954A1 (en) Method, host, and system for implementing usb device management
WO2019062635A1 (en) Update method and device
CN109587005B (en) Connection detection method and device, computer equipment and readable storage medium
CN106919485B (en) System based on hardware testing tool configured on server
CN112099902A (en) Network adapter configuration method and device of virtual machine, electronic device and storage medium
WO2019085290A1 (en) Test preparation method and apparatus, terminal device, and storage medium
CN112272246A (en) Out-of-band network IP automatic configuration method and device, electronic equipment and storage medium
CN108282369A (en) A kind of physical machine remote deployment method and device based on openstack
CN108259305A (en) A kind of physical machine remote dummy lan handover method and device based on openstack
US20240155023A1 (en) Method and system for implementing bare metal inspection process, device, and storage medium
CN114866515A (en) IP address configuration method, device, electronic equipment and storage medium
CN113448688B (en) Method, system and computer medium for automatically correcting network configuration of cloud migration scene
CN114995888A (en) Intelligent network card deployment method, device and medium
CN108234174B (en) Management method and device of virtual network function
CN110413311A (en) ' In System Reconfiguration Method and server
CN113992739B (en) Local area network OTA firmware upgrading device, method and system
CN113886153B (en) Network card pressure testing method and device based on container
CN111147400B (en) Method and device for command line configuration synchronization and electronic equipment
CN107911816A (en) Startup method, multimode IoT equipment and storage medium for multimode IoT equipment
CN113708954A (en) Network switching method and device, electronic equipment and storage medium
CN108847975B (en) Communication method, device, computer equipment and medium based on NFV (network function virtualization) architecture
CN109981365A (en) Data decryptor method, apparatus, user equipment and storage medium
CN114443150B (en) Method, system, terminal and storage medium for synchronizing factory information of switch
CN110489134A (en) A kind of dispositions method and system of PXE server and High-Performance Computing Cluster environment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination