Socket technology-based method for rapidly acquiring KVM virtual machine address
Technical Field
The invention relates to the field of virtual machine address acquisition, in particular to a Socket technology-based method for rapidly acquiring a KVM (keyboard video mouse) virtual machine address.
Background
With the improvement of hardware capability of a server and the popularization of cloud computing technology, virtualization technology is applied to more and more occasions. Among various virtualization platforms, such as VMWare, openStack, VSphere platform, deep belief super fusion platform, etc., the information of the KVM virtual machine is generally obtained by installing a proxy tool in the KVM virtual machine.
KVM (Kernel-based Virtual Machine for short) is an open-source system virtualization module, which is integrated in each main release of Linux after Linux 2.6.20. It uses the Linux's own scheduler for management, so its core source code is very small compared to Xen. KVM has become one of the mainstream VMMs in the academic world, and is widely used in computer virtualization applications. Socket is a convention or a manner of communication between computers, through which a computer may receive data from or send data to other computers, and is an abstraction layer through which an application may send or receive data, and which allows an application to insert I/O into a network and communicate with other applications in the network.
In the existing cloud platform, the method for obtaining the IP address of the virtual machine generally comprises the steps of installing a proxy tool in the virtual machine, enabling a computing node to obtain information of the virtual machine through the proxy tool, and enabling a management platform to obtain the IP address of the virtual machine by calling related services provided by the cloud platform. However, in the Linux native virtualization KVM system, there is no corresponding agent, so the management platform cannot obtain the address of the KVM virtual machine.
Therefore, in order to solve the above problems, the present invention is urgently needed to provide a method for quickly obtaining the KVM virtual machine address based on Socket technology.
Disclosure of Invention
The invention aims to provide a Socket technology-based method for quickly acquiring a KVM (virtual machine) address, which solves the technical problem that a management platform cannot acquire the address of a KVM virtual machine in a Linux original virtualization KVM system without a corresponding agent in the prior art.
The invention provides a method for rapidly acquiring a KVM virtual machine address based on Socket technology, which comprises the following steps:
after the KVM virtual machine obtains the network adapter information of the KVM virtual machine, the KVM virtual machine obtains the address information of the KVM virtual machine, and the KVM virtual machine broadcasts a broadcast message containing the address information of the virtual machine to a designated port in the network;
the server monitors the appointed port information in the network, acquires the broadcast message containing the address information sent by the KVM virtual machine, extracts the address information in the broadcast message, and stores the address information.
Preferably also comprises
After receiving the broadcast message containing the address information sent by the KVM virtual machine, the server sends a confirmation message to the KVM virtual machine according to the address information;
after receiving the confirmation message, the virtual machine stops sending the broadcast message to the server.
Preferably also comprises
The server acquires the network adapter information of the server to obtain server address information, and the server sends the server address information to the KVM virtual machine while sending the confirmation message to the KVM virtual machine;
after receiving the server address information, the KVM virtual machine stores the server address information.
Preferably, the virtual machine address information and the server address information each include a MAC address and an IP address.
Preferably, the broadcast message is a UDP broadcast packet.
Preferably, the server monitors the broadcast message sent by the appointed port in the network, and if the broadcast message is the broadcast message sent by the virtual machine, extracts the address information in the broadcast message and stores the address information; if the broadcast message is not the broadcast message sent by the virtual machine, continuing to monitor the broadcast message broadcasted by the appointed port in the network.
Preferably, the KVM virtual machine receives the acknowledgement message sent by the server in real time, and if the server acknowledgement message is the same, the KVM virtual machine stops sending the broadcast message; if the message is not the confirmation message sent by the server, continuing to send the broadcast message containing the address information.
Preferably, the KVM virtual machine and the server are accessed into the same lan.
Preferably, the UDP broadcast packet sent by the virtual machine has a fixed data format, where the data format is net device < network card name > < line feed > IP: < IPv4 address > < line feed > MAC: < MAC address > < line feed >, and after receiving the UDP broadcast packet of the specified port, the server verifies whether the UDP broadcast packet conforms to the format, so as to determine whether the UDP broadcast packet is broadcast information sent by the virtual machine.
Preferably, the format of the acknowledgement message sent by the server is fixed as a string "ip_found_ack"; after receiving the confirmation message sent by the server, the virtual machine determines whether the character string in the confirmation message is "IP_FOUND_ACK", if so, the virtual machine determines that the character string is the confirmation message sent by the server.
Compared with the prior art, the method for rapidly acquiring the KVM virtual machine address based on the Socket technology provided by the invention has the following steps:
1. the invention provides a Socket technology-based method for rapidly acquiring an address of a KVM virtual machine, wherein the KVM virtual machine circularly transmits a broadcast message to a network appointed port to broadcast own address information, and a server stores the address information of the virtual machine after monitoring the address information, so that the technical problem of acquiring an IP address of the virtual machine in a KVM system is effectively solved, an agent tool is not required to be installed in the KVM virtual machine, and an IP address is not required to be acquired through a computing node, thereby realizing the acquisition of the IP address of the virtual machine in the KVM system.
2. The invention provides a method for rapidly acquiring an address of a KVM virtual machine based on Socket technology, which comprises the steps that after a server receives a broadcast message containing address information and sent by the KVM virtual machine, a confirmation message is sent to the KVM virtual machine according to the address information; after the virtual machine receives the confirmation message, the virtual machine stops sending the broadcast message to the server, so that the control of the message sent by the KVM virtual machine is realized, and when the server receives the address information of the KVM virtual machine, the broadcast message containing the address information does not need to be recycled, and the broadcast is stopped, so that the running speed of the server and the virtual machine is prevented from being influenced.
3. The invention provides a method for rapidly acquiring a KVM virtual machine address based on Socket technology, which comprises the steps that a server acquires network adapter information of a local machine to obtain server address information, and the server sends the server address information to the KVM virtual machine while sending a confirmation message to the KVM virtual machine; after receiving the server address information, the KVM virtual machine stores the server address information. After the server obtains the network adaptation information of the server, the server address information is obtained, the address information is sent to the virtual machine, the virtual machine receives the address information of the server, and the address information of the server is stored, so that the communication between the virtual machine and the server is facilitated.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are needed in the description of the embodiments or the prior art will be briefly described, and it is obvious that the drawings in the description below are some embodiments of the present invention, and other drawings can be obtained according to the drawings without inventive effort for a person skilled in the art.
FIG. 1 is a block diagram of a method for quickly obtaining an address of a KVM virtual machine based on Socket technology according to the present invention;
FIG. 2 is a flow chart of server monitoring according to the present invention;
FIG. 3 is a flow chart of the broadcast of the KVM according to the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made apparent and fully in view of the accompanying drawings, in which some, but not all embodiments of the invention are shown. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In the description of the present invention, it should be noted that the directions or positional relationships indicated by the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc. are based on the directions or positional relationships shown in the drawings, are merely for convenience of describing the present invention and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a specific orientation, be configured and operated in a specific orientation, and thus should not be construed as limiting the present invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance.
In the description of the present invention, it should be noted that, unless explicitly specified and limited otherwise, the terms "mounted," "connected," and "connected" are to be construed broadly, and may be either fixedly connected, detachably connected, or integrally connected, for example; can be mechanically or electrically connected; can be directly connected or indirectly connected through an intermediate medium, and can be communication between two elements. The specific meaning of the above terms in the present invention will be understood in specific cases by those of ordinary skill in the art.
As shown in fig. 1, a method for quickly obtaining a KVM virtual machine address based on Socket technology in this embodiment includes the following steps:
s1) after the KVM virtual machine obtains the network adapter information of the local machine, obtaining the address information of the KVM virtual machine, and broadcasting a broadcasting message containing the address information of the virtual machine to a designated port in the network by the KVM virtual machine;
s2) the server monitors the appointed port information in the network, acquires the broadcast message containing the address information sent by the KVM virtual machine, extracts the address information in the broadcast message, and stores the address information.
Through the steps, the KVM virtual machine circularly sends broadcast messages to the network designated port to broadcast own address information, and the server stores the address information of the virtual machine after monitoring the address information, so that the technical problem of obtaining the IP address of the virtual machine in the KVM system is effectively solved, an agent tool is not required to be installed in the KVM virtual machine, the IP address is not required to be obtained through a computing node, and the IP address of the virtual machine is obtained in the KVM system.
In some cases, the method for quickly obtaining the address of the KVM virtual machine based on the Socket technology further includes that after receiving a broadcast message containing address information sent by the KVM virtual machine, the server sends a confirmation message to the KVM virtual machine according to the address information; after the virtual machine receives the confirmation message, the virtual machine stops sending the broadcast message to the server, so that the control of sending the broadcast message to the KVM virtual machine is realized, and when the server receives the address information of the KVM virtual machine, the broadcast message containing the address information does not need to be recycled to be broadcast, and the playing is stopped, thereby avoiding affecting the operation speed of the server and the virtual machine.
In some cases, the method for quickly acquiring the address of the KVM virtual machine based on Socket technology further includes that a server acquires network adapter information of the server to obtain server address information, and the server sends the server address information to the KVM virtual machine while sending a confirmation message to the KVM virtual machine; after receiving the server address information, the KVM virtual machine stores the server address information. After the server obtains the network adaptation information of the server, the server address information is obtained, the address information is sent to the virtual machine, the virtual machine receives the address information of the server, and the address information of the server is stored, so that the communication between the virtual machine and the server is facilitated.
Specifically, the address information of the virtual machine and the address information of the server both comprise an MAC address and an IP address, the virtual machine continuously broadcasts the IP address of the virtual machine, and after the server receives the IP address, the IP address of the virtual machine is stored and is used for communicating with the virtual machine; when the server sends a confirmation message to the KVM virtual machine, the IP address of the server is simultaneously sent, and the KVM virtual machine stores the IP of the server and is used for communicating with the server.
Specifically, the broadcast message is a UDP broadcast packet.
Specifically, the server monitors a broadcast message sent by a designated port in the network, and if the broadcast message is a broadcast message sent by the virtual machine, extracts address information in the broadcast message and stores the address information; if the broadcast message is not the broadcast message sent by the virtual machine, continuing to monitor the broadcast message broadcasted by the appointed port in the network.
Specifically, the KVM virtual machine receives the confirmation message sent by the server in real time, and if the confirmation message is the server confirmation message, the broadcast message is stopped to be sent; if the message is not the confirmation message sent by the server, continuing to send the broadcast message containing the address information.
Specifically, the KVM virtual machine and the server are accessed to the same lan. The validity of the IP address of the virtual machine is ensured.
In a specific embodiment, the UDP broadcast packet sent by the virtual machine has a fixed data format, where the data format is netdevice < network card name > < line feed > IP: < IPv4 address > < line feed > MAC: < MAC address > < line feed >, and after receiving the UDP broadcast packet with the specified port, the server verifies whether the UDP broadcast packet conforms to the format, so as to determine whether the UDP broadcast packet is broadcast information sent by the virtual machine.
In a specific embodiment, the format of the acknowledgement message sent by the server is fixed as a character string "ip_found_ack"; after receiving the confirmation message sent by the server, the virtual machine determines whether the character string in the confirmation message is "IP_FOUND_ACK", if so, the virtual machine determines that the character string is the confirmation message sent by the server.
Finally, it should be noted that: the above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some or all of the technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit of the invention.