Configuration and use of Libvirt, LIBVIRTD
1. Libvirt's configuration file
In the case of Rhel 6.3, the configuration files for the Libvirt configuration are in the/etc/libvirt/directory, as follows:
The code is as follows |
Copy Code |
[Root@rhel6u3-ga libvirt]# cd/etc/libvirt/
[Root@rhel6u3-ga libvirt]# ls
CIM libvirt.conf libvirtd.conf lxc.conf nwfilter qemu qemu.conf qemu-sanlock.conf Storage
[Root@rhel6u3-ga libvirt]# CD QEMU
[Root@rhel6u3-ga qemu]# ls
Networks Rhel6u3-1.xml Rhel6u3-2.xml |
The
briefly describes several of these important configuration files and directories:
(1)/etc/libvirt/libvirt.conf
libvirt.conf files are used to configure some common Libvirt An alias for a connection (usually a remote connection), as in a normal configuration file in Linux, where the line at the beginning of the number (#) in the profile is a comment, and the configuration file in this example is as follows:
code is as follows |
copy code |
[root@rhel6u3-ga kvm_demo]# cat/etc/libvirt/libvirt.conf # # This can is used to the setup URI aliases For frequently # used connection URIs. Aliases may contain only the # characters A-Z, 0-9, _,-. # # following the ' = ' May is any valid Libvirt connection # URI, including arbitrary parameters uri_aliases = [ "Remote1=qemu+ssh://root@192.168.93.201/system", ] |
In which, configure the alias of Remote1 to refer to the Qemu+ssh://root@192.168.93.201/system remote Libvirt connection, and with this alias, you can call libvirt by tools such as Virsh, or by writing your own code. The API uses this alias without having to write a full, verbose URI connection identifier. Use this alias with Virsh to connect to the remote Libvirt to inquire about the current client status that is already started, and then exit the connection, and the command line operates as follows:
The code is as follows |
Copy Code |
[Root@rhel6u3-ga kvm_demo]# Service LIBVIRTD Reload Reloading LIBVIRTD configuration: [OK] [Root@rhel6u3-ga kvm_demo]# virsh-c remote1 root@192.168.93.201′s Password: Welcome to Virsh, the virtualization interactive terminal.
Type: ' Help ' for help with commands ' Quit ' to quit
Virsh # List Id Name State —————————————————- 1 Rhel6u3-remote Running
Virsh # Quit
[Root@rhel6u3-ga kvm_demo]# |
Calling the Libvirt API in code can also be used to establish a connection, as in the following Python line of code that uses this alias to establish a connection:
conn = Libvirt.openreadonly (' remote1′)
(2)/etc/libvirt/libvirtd.conf
Libvirtd.conf is the Libvirt daemon libvirtd configuration file, which requires LIBVIRTD to reload the configuration file (or reboot LIBVIRTD) before it takes effect. In the libvirtd.conf file, the line that begins with the pound sign (#) is the annotation content, and the truly useful configuration is set in each row of the file using a pairing of "configuration item = value" (such as Tcp_port = "16509″"). The libvirtd.conf configuration values many of the settings for the LIBVIRTD startup, including whether to establish TCP, UNIX domain sockets, and their maximum number of connections, as well as the authentication mechanisms for these connections, and so on.
For example, the following configuration items indicate a connection that turns off TLS security authentication (the default is open), opens a TCP connection (the default is to turn off the TCP connection), sets the port that TCP listens on, the TCP connection does not use authentication authorization, and sets the directory where the UNIX domain socket is stored.
The code is as follows |
Copy Code |
LISTEN_TLS = 0
LISTEN_TCP = 1
Tcp_port = "16666″
Unix_sock_dir = "/var/run/libvirt"
Auth_tcp = "None" |
Note: For TCP, TLS, and other connections to take effect, you need to add the –listen parameter (-L) when starting LIBVIRTD. The default service LIBVIRTD Start command does not take the –listen parameter when starting the LIBVIRTD services, so you can use the libvirtd–listen-d command to start LIBVIRTD if you want to use a connection such as TCP.
The above configuration option allows the UNIX socket to be placed in the/var/run/libvirt directory, starts the LIBVIRTD and verifies that the configuration is in effect, and the command line operates as follows:
The
code is as follows |
copy code |
[root@rhel6u3-ga ~]# libvirtd–listen-d 2012-12-01 07:54:02.715+0000: 6788:info:libvirt version:0.9.10, Package:21.el6 (Red Hat, Inc [Root@rhel6u3-ga ~]# virsh-c Qemu+tcp://localhost:16666/system Welcome to Virsh, the virtualization Interactive terminal. type: ' help with commands ' quit ' to quit Virsh # qu It [root@rhel6u3-ga ~]# ls/var/run/libvirt/libvirt-sock* /var/run/libvirt/ libvirt-sock /var/run/libvirt/libvirt-sock-ro |
(3)/etc/libvirt/qemu.conf
Qemu.conf is a libvirt configuration file for Qemu, including VNC, spice, etc., and the authorization method used to connect to them, as well as memory paging, SELinux, cgroups, and other related configurations.
(4)/etc/libvirt/qemu/catalogue
The QEMU directory is a profile that holds the domain used by QEMU, looking at the QEMU directory as follows:
The code is as follows |
Copy Code |
[Root@rhel6u3-ga ~]# ls/etc/libvirt/qemu/
Networks Rhel6u3-1.xml Rhel6u3-2.xml |
This includes two domains of XML configuration files (Rhel6u3-1.xml and Rhel6u3-2.xml), which I created with the Virt-manager tool, and the default will be to save their configuration files to the/etc/libvirt/qemu/directory. The networks directory is the network configuration that is used by default when you create a domain.
2. Use of LIBVIRTD
LIBVIRTD is a server-side daemon as a libvirt virtualization management system, and if you want a node to be managed with libvirt (whether local or remote), you need to run the LIBVIRTD daemon on this node, So that other top-level management tools can connect to the node, LIBVIRTD is responsible for performing other management tools to send its virtualization management operations instructions. The Libvirt client tools (including Virsh, Virt-manager, etc.) can be connected to a local or remote LIBVIRTD process to manage clients on the node (startup, shutdown, reboot, migration, and so on), the configuration and resource usage status of the host and client on the collection node.
In Rhel 6.3 LIBVIRTD is configured in the system as a service (service), so it can be manipulated through service commands (which are actually implemented through the/ETC/INIT.D/LIBVIRTD Services script). Commonly used modes of operation are: "Service libvirtd start" command means start LIBVIRTD, "service LIBVIRTD restart" means restart LIBVIRTD, "service LIBVIRTD Reload" Indicates that the service is not restarted but the configuration file (that is, the/etc/libvirt/libvirtd.conf configuration file) is reloaded. The command line for manipulating the LIBVIRTD service example is as follows:
The code is as follows |
Copy Code |
[Root@rhel6u3-ga ~]# Service LIBVIRTD Usage:/etc/init.d/libvirtd {Start|stop|status|restart|condrestart|reload|force-reload|try-restart}
[Root@rhel6u3-ga ~]# Service LIBVIRTD start Starting LIBVIRTD daemon:2012-12-01 08:14:33.048+0000:31202:info:libvirt version:0.9.10, Package:21.el6 (Red Hat, I nc. [OK]
[Root@rhel6u3-ga ~]# Service LIBVIRTD Status LIBVIRTD (PID 31327) is running ...
[Root@rhel6u3-ga ~]# Service LIBVIRTD restart Stopping LIBVIRTD daemon: [OK] Starting LIBVIRTD daemon:2012-12-01 08:14:43.522+0000:31325:info:libvirt version:0.9.10, Package:21.el6 (Red Hat, I nc. [OK] |
By default, LIBVIRTD listens on a local UNIX domain socket without listening to a network-based TCP/IP socket, and requires the command line arguments "-L or –listen" to open the libvirtd.conf Configuration for TCP/IP sockets in the configuration file. In addition, the start or stop of the LIBVIRTD daemon does not directly affect the clients that are running. LIBVIRTD when the client's XML configuration file is present when the startup or restart is complete, LIBVIRTD automatically loads the client's configuration to obtain their information; Of course, if the client does not run based on the Libvirt format XML file, LIBVIRTD cannot find it.
LIBVIRTD is an executable program that can be invoked not only by using the service command, but also by running the LIBVIRTD command individually. The LIBVIRTD command line has the following main parameters:
-D, or –daemon
Indicates that LIBVIRTD is run in the background as a daemon (daemon).
-F, or –config FILE
Specifies that the LIBVIRTD profile is file instead of the default value (usually/etc/libvirt/libvirtd.conf).
-L, or –listen
Open the TCP/IP connection configured in the configuration file.
-P, or –pid-file file
Writes the PID of the LIBVIRTD process to the file, rather than using the default (usually/var/run/libvirtd.pid).
-T, or –timeout SECONDS
Sets the timeout for LIBVIRTD connections to seconds seconds.
-V, or –verbose
Let the command output detailed output information. In particular, the detailed output information makes it easier for the user to find the cause when the operation is wrong.
–version
Displays the version information for the LIBVIRTD program.
For the use of the LIBVIRTD command, several simple command-line operations examples are as follows:
Stop the existing service before #使用libvirtd command
The
code is as follows |
copy code |
[root@rhel6u3-ga ~]# service LIBVIRTD stop stopping LIBVIRTD daemon: [ ok ] [Root@rhel6u3-ga ~]# libvirtd–version Libvirtd (libvirt) 0.9.10 [root@rhel6u3-ga ~]# LIBVIRTD 2012-12-01 08:57:38.475+0000:2196:info:libvirt version:0.9.10, Package:21.el6 (Red Hat, Inc. |
^c #没有以daemon的形式启动, the standard output is LIBVIRTD occupied; this ends the LIBVIRTD process with ctrl-c to continue with the subsequent operation.
The code is as follows |
Copy Code |
[Root@rhel6u3-ga ~]# libvirtd-l-d-p/root/libvirtd.pid
2012-12-01 08:56:14.665+0000:7683:info:libvirt version:0.9.10, Package:21.el6 (Red Hat, Inc. [Root@rhel6u3-ga ~]# Cat/root/libvirtd.pid
7685 |