Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the remote access of libvirt

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

How to achieve remote access to libvirt, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.

/ etc/libvirt/libvirtd.conf is the configuration file of libvirt daemon libvirtd, which configures many settings when libvirtd starts, including whether to establish TCP, UNIX domain socket and other connection methods and their maximum number of connections, as well as the authentication mechanism of these connections, and so on. After modification, you need to have libvirtd reload the configuration file (or restart libvirtd) before it will take effect. If you open libvirtd.conf, you will find that many of the default options are used. In order to achieve remote control access. Several parameters that have been commented out need to be opened and modified:

Listen_tls = 0listen_tcp = 1tcp_port = "16509" auth_tcp = "none"

For TCP, TLS, and other connections to take effect, you need to add the-listen parameter (abbreviated to-l) when starting libvirtd. The default service libvirtd start command starts the libvirtd service without the-listen parameter, so if you want to use a connection method such as TCP, you can use the following command to start libvirtd

Libvirtd-listen-d

Verification, which can be verified by virsh:

Virsh-c qemu+tcp://localhost:16509/system

If it is another machine, you need to change the corresponding localhost to ip or hostname. And pay attention to opening port 16509.

The following is a c-implemented program that lists all virtual host names. Password-less connection via tcp.

/ * compile with: gcc test.c-o test-lvirt * / # include # include # include int main (int argc, char * argv []) {int numofdom; int i; virDomainPtr * namelist=NULL; int flags= VIR_CONNECT_LIST_DOMAINS_ACTIVE | VIR_CONNECT_LIST_DOMAINS_INACTIVE; virConnectPtr conn; / / use actual ip address conn=virConnectOpenAuth ("qemu+tcp://192.168.234.128/system", virConnectAuthPtrDefault,0) If (conn = = NULL) {fprintf (stderr, "Failed to open connection to qemu:///system\ n"); return-1;} numofdom=virConnectListAllDomains (conn,&namelist,flags); if (numofdom==-1) {fprintf (stderr, "Failed to get numof domain:\ n"); return-1;} for

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report