table of Contents
1.libvirt Introduction
Libvirt is open source API, daemon and management tools for managing virtualization platforms. It can be used to manage KVM, Xen, VMware ESX, QEMU and other virtualization technologies. There are many online articles to do, but here is not described in detail. libvirt installation process itself is not difficult, mainly centos native will own a version of libvirt, at the same time, if the self-compiled version before installing, did not release comes with libvirt clean uninstall, there will be a variety of error . The author is more busy, time rush, layout may not look good, please forgive me.
2. Uninstall system comes with libvirt
2.1. View related libvirt package is currently installed
[root@localhost libvirt-2.0.0]# rpm -qa |grep libvirt
2.2. All uninstall
Due to the current environment is already the author of a clean uninstall, therefore, not demonstrated here
[root@localhost libvirt-2.0.0]# yum remove `rpm -qa |grep libvirt`
3. Use tar package compiled and installed
3.1. Unzip
[root@localhost home]# tar xvf libvirt-2.0.0.tar.xz
3.2. Generate Makefile
Note: If no parameter ./configure, various files will be installed, such as / usr / local, / var / local below, so inconsistent and native installation path, usually not
so mounted 1
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --enable-debug=yes $ make $ sudo make install
3.3. Error Handling
Error 1: need to install the dependencies:
configure: error: You must install the pciaccess module to build with udev
[root@localhost libvirt-2.0.0]# yum install libpciaccess-devel
configure: error: You must install the libyajl library & headers to compile libvirt
[root@localhost libvirt-2.0.0]# yum install yajl-devel
configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to compile libvirt
[root@localhost libvirt-2.0.0]# yum install device-mapper-devel
configure: error: xml2-config not found. Please check your libxml2 installation.
yum -y install libxml2-devel
configure: error: libnl-devel >= 1.1 is required for macvtap support
configure: error: You must install the pciaccess module to build with udev
[root@localhost libvirt-2.0.0]# yum install libpciaccess-devel
configure: error: You must install the libyajl library & headers to compile libvirt
[root@localhost libvirt-2.0.0]# yum install yajl-devel
configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to compile libvirt
[root@localhost libvirt-2.0.0]# yum install device-mapper-devel
configure: error: xml2-config not found. Please check your libxml2 installation.
yum -y install libxml2-devel
Error 2
No uninstall the system comes directly install the new version but the same
#查看服务状态
[root@192 libvirt-2.0.0]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2019-04-21 16:48:37 CST; 25s ago
Docs: man:libvirtd(8)
http://libvirt.org
Process: 79857 ExecStart=/usr/sbin/libvirtd $LIBVIRTD_ARGS (code=exited, status=0/SUCCESS)
Main PID: 79857 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/libvirtd.service
├─2705 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
└─2706 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
Apr 21 16:48:36 localhost.localdomain systemd[1]: Started Virtualization daemon.
Apr 21 16:48:36 localhost.localdomain libvirtd[79857]: libvirt version: 2.0.0, package: 10.el7 (CentOS BuildSystem <http://bugs.centos.org>, 2016-11-12-02:15:12, c...entos.org)
Apr 21 16:48:36 localhost.localdomain libvirtd[79857]: hostname: localhost.localdomain
Apr 21 16:48:36 localhost.localdomain libvirtd[79857]: operation failed: network 'default' already exists with uuid 0c2459eb-2797-4a07-93af-6fb5857a6831
Apr 21 16:48:37 localhost.localdomain dnsmasq[2705]: read /etc/hosts - 2 addresses
Apr 21 16:48:37 localhost.localdomain dnsmasq[2705]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Apr 21 16:48:37 localhost.localdomain dnsmasq-dhcp[2705]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Apr 21 16:48:37 localhost.localdomain libvirtd[79857]: internal error: failed to initialize netcf
Apr 21 16:48:37 localhost.localdomain libvirtd[79857]: Initialization of netcf state driver failed: internal error: failed to initialize netcf
Apr 21 16:48:37 localhost.localdomain libvirtd[79857]: Driver state initialization failed
Hint: Some lines were ellipsized, use -l to show in full.
Treatment to kill residual process
[root@192 libvirt-2.0.0]# ps -ef|grep libvirt
nobody 2705 1 0 12:20 ? 00:00:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 2706 2705 0 12:20 ? 00:00:00 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshelper
root 79999 3730 0 16:52 pts/0 00:00:00 grep --color=auto libvirt
[root@192 libvirt-2.0.0]# kill -9 2705
[root@192 libvirt-2.0.0]# ps -ef|grep libvirt
root 80016 3730 0 16:53 pts/0 00:00:00 grep --color=auto libvirt
libvirt can work, but there are still error
Apr 21 16:53:45 localhost.localdomain libvirtd[80026]: operation failed: network 'default' already exists with uuid 0c2459eb-2797-4a07-93af-6fb5857a6831
View libvirt network configuration
[root@192 libvirt-2.0.0]# virsh net-list --all
Name State Autostart Persistent
---------------------------------------------------
default active no no
# View xml network
[root@192 libvirt-2.0.0]# virsh net-dumpxml default
<network>
<name>default</name>
<uuid>0c2459eb-2797-4a07-93af-6fb5857a6831</uuid>
<forward mode='nat'>
<nat>
<port start='1024' end='65535'/>
</nat>
</forward>
<bridge name='virbr0' stp='on' delay='0'/>
<mac address='52:54:00:38:f8:e0'/>
<ip address='192.168.122.1' netmask='255.255.255.0'>
<dhcp>
<range start='192.168.122.2' end='192.168.122.254'/>
</dhcp>
</ip>
</network>
# Remove the net after the restart process encounters new problems libvirt
Apr 21 19:18:52 localhost.localdomain libvirtd[82476]: Initialization of netcf state driver failed: internal error: failed to initialize netcf
After # close selinux, normal
[root@localhost ~]# setenforce 0
# Network also rebuilt 2
[root@localhost ~]# virsh net-list
Name State Autostart Persistent
----------------------------------------------------------
default active yes yes
Error 3
virsh: error while loading shared libraries: libvirt-lxc.so.0: cannot open shared object file: No such file or directory
This is because the dynamic database updates, no refresh, refresh needed
bash-4.2# ldconfig
bash-4.2# virsh --version
2.0.0
Error 4
[root@localhost libvirt-2.0.0]# virsh list
error: failed to connect to the hypervisor
error: no valid connection
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
This is because the process did not start
[root@localhost libvirt-2.0.0]# systemctl start libvirtd
[root@localhost libvirt-2.0.0]# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
Loaded: loaded (/usr/lib/systemd/system/libvirtd.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2019-05-15 10:28:31 EDT; 5s ago
Docs: man:libvirtd(8)
http://libvirt.org
Main PID: 81685 (libvirtd)
CGroup: /system.slice/libvirtd.service
├─81685 /usr/sbin/libvirtd
├─81825 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshe...
└─81826 /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp-script=/usr/libexec/libvirt_leaseshe...
May 15 10:28:31 localhost.localdomain systemd[1]: Started Virtualization daemon.
May 15 10:28:33 localhost.localdomain dnsmasq[81825]: started, version 2.76 cachesize 150
May 15 10:28:33 localhost.localdomain dnsmasq[81825]: compile time options: IPv6 GNU-getopt DBus no-i18n IDN DHCP DHCPv6 no-Lua TFTP no...notify
May 15 10:28:33 localhost.localdomain dnsmasq-dhcp[81825]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
May 15 10:28:33 localhost.localdomain dnsmasq-dhcp[81825]: DHCP, sockets bound exclusively to interface virbr0
May 15 10:28:33 localhost.localdomain dnsmasq[81825]: reading /etc/resolv.conf
May 15 10:28:33 localhost.localdomain dnsmasq[81825]: using nameserver 192.168.233.2#53
May 15 10:28:33 localhost.localdomain dnsmasq[81825]: read /etc/hosts - 2 addresses
May 15 10:28:33 localhost.localdomain dnsmasq[81825]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
May 15 10:28:33 localhost.localdomain dnsmasq-dhcp[81825]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Hint: Some lines were ellipsized, use -l to show in full.
4. Installation package src.rpm
As the author of the experimental environment was accidentally destroyed, in order to later problems can be compiled faster recovery environment, choose to use the jail chroot build environment inside a building, convenient backup and restore, but this way, make after the expiry, can not in a hosted environment make install, missing a lot of things, but do not want the environment outside the jail installed too many dependencies, otherwise it defeats the purpose, therefore, we decided to try src.rpm package to compile and install (here are in operation based chroot environment, the environment as ordinary operation mode, except that different paths yum install)
4.1. First, install the rpm package
bash-4.2# rpm -i libvirt-2.0.0-1.fc23.src.rpm
warning: libvirt-2.0.0-1.fc23.src.rpm: Header V4 DSA/SHA1 Signature, key ID de95bc1f: NOKEY
warning: user veillard does not exist - using root
warning: group veillard does not exist - using root
warning: user veillard does not exist - using root
warning: group veillard does not exist - using root
4.2. Rpmbuild directory into the implementation of the spec file
bash-4.2# cd /root/rpmbuild/
bash-4.2# ll
total 8
drwxr-xr-x. 2 root root 4096 Aug 11 06:52 SOURCES
drwxr-xr-x. 2 root root 4096 Aug 11 06:52 SPECS
bash-4.2# rpmbuild -bp S
SOURCES/ SPECS/
bash-4.2# rpmbuild -bp SPECS/libvirt.spec
error: Failed build dependencies:
xhtml1-dtds is needed by libvirt-2.0.0-1.el7.x86_64
libxslt is needed by libvirt-2.0.0-1.el7.x86_64
readline-devel is needed by libvirt-2.0.0-1.el7.x86_64
ncurses-devel is needed by libvirt-2.0.0-1.el7.x86_64
libtasn1-devel is needed by libvirt-2.0.0-1.el7.x86_64
gnutls-devel is needed by libvirt-2.0.0-1.el7.x86_64
libattr-devel is needed by libvirt-2.0.0-1.el7.x86_64
libblkid-devel >= 2.17 is needed by libvirt-2.0.0-1.el7.x86_64
augeas is needed by libvirt-2.0.0-1.el7.x86_64
sanlock-devel >= 2.4 is needed by libvirt-2.0.0-1.el7.x86_64
libpcap-devel is needed by libvirt-2.0.0-1.el7.x86_64
libnl3-devel is needed by libvirt-2.0.0-1.el7.x86_64
avahi-devel is needed by libvirt-2.0.0-1.el7.x86_64
dnsmasq >= 2.41 is needed by libvirt-2.0.0-1.el7.x86_64
radvd is needed by libvirt-2.0.0-1.el7.x86_64
ebtables is needed by libvirt-2.0.0-1.el7.x86_64
cyrus-sasl-devel is needed by libvirt-2.0.0-1.el7.x86_64
polkit-devel >= 0.112 is needed by libvirt-2.0.0-1.el7.x86_64
/usr/bin/qemu-img is needed by libvirt-2.0.0-1.el7.x86_64
iscsi-initiator-utils is needed by libvirt-2.0.0-1.el7.x86_64
parted-devel is needed by libvirt-2.0.0-1.el7.x86_64
librados2-devel is needed by libvirt-2.0.0-1.el7.x86_64
librbd1-devel is needed by libvirt-2.0.0-1.el7.x86_64
glusterfs-api-devel >= 3.4.1 is needed by libvirt-2.0.0-1.el7.x86_64
glusterfs-devel >= 3.4.1 is needed by libvirt-2.0.0-1.el7.x86_64
libcap-ng-devel >= 0.5.0 is needed by libvirt-2.0.0-1.el7.x86_64
fuse-devel >= 2.8.6 is needed by libvirt-2.0.0-1.el7.x86_64
netcf-devel >= 0.2.2 is needed by libvirt-2.0.0-1.el7.x86_64
libcurl-devel is needed by libvirt-2.0.0-1.el7.x86_64
audit-libs-devel is needed by libvirt-2.0.0-1.el7.x86_64
systemtap-sdt-devel is needed by libvirt-2.0.0-1.el7.x86_64
nfs-utils is needed by libvirt-2.0.0-1.el7.x86_64
dbus-devel is needed by libvirt-2.0.0-1.el7.x86_64
scrub is needed by libvirt-2.0.0-1.el7.x86_64
numad is needed by libvirt-2.0.0-1.el7.x86_64
4.3. One by one to repair dependence
yum --installroot=/home/user3/jail install -y xhtml1-dtds
yum --installroot=/home/user3/jail install -y libxslt
yum --installroot=/home/user3/jail install -y readline-devel
yum --installroot=/home/user3/jail install -y libtasn1-devel
yum --installroot=/home/user3/jail install -y gnutls-devel
yum --installroot=/home/user3/jail install -y libattr-devel
yum --installroot=/home/user3/jail install -y libblkid-devel
yum --installroot=/home/user3/jail install -y augeas sanlock-devel sanlock
yum --installroot=/home/user3/jail install -y libpcap-devel
...
Finally try again,
bash-4.2# rpmbuild -bp SPECS/libvirt.spec
error: Failed build dependencies:
/usr/bin/qemu-img is needed by libvirt-2.0.0-1.el7.x86_64
Only this one, install the file can not solve for an unknown reason, and therefore access to information 3 , informed that this is not important, so you can modify the spec file, comment out this.
# From QEMU RPMs
# BuildRequires: /usr/bin/qemu-img
according to
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --enable-debug=yes
--Enable-debug increase in the spec file configure at
compile
bash-4.2# rpmbuild -bb SPECS/libvirt.spec
If successful, it will generate
bash-4.2# ll RPMS/x86_64/
total 21284
-rw-r--r--. 1 root root 2716 Aug 11 07:47 libvirt-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 4380632 Aug 11 07:47 libvirt-client-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 588380 Aug 11 07:47 libvirt-daemon-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 3868 Aug 11 07:47 libvirt-daemon-config-network-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 6356 Aug 11 07:47 libvirt-daemon-config-nwfilter-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 47564 Aug 11 07:47 libvirt-daemon-driver-interface-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 669320 Aug 11 07:47 libvirt-daemon-driver-lxc-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 202876 Aug 11 07:47 libvirt-daemon-driver-network-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 46672 Aug 11 07:47 libvirt-daemon-driver-nodedev-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 71392 Aug 11 07:47 libvirt-daemon-driver-nwfilter-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 478708 Aug 11 07:47 libvirt-daemon-driver-qemu-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 36804 Aug 11 07:47 libvirt-daemon-driver-secret-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 233904 Aug 11 07:47 libvirt-daemon-driver-storage-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 1984 Aug 11 07:47 libvirt-daemon-kvm-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 1956 Aug 11 07:47 libvirt-daemon-lxc-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 10537260 Aug 11 07:47 libvirt-debuginfo-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 152084 Aug 11 07:47 libvirt-devel-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 3781352 Aug 11 07:47 libvirt-docs-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 52048 Aug 11 07:47 libvirt-lock-sanlock-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 334884 Aug 11 07:47 libvirt-login-shell-2.0.0-1.el7.x86_64.rpm
-rw-r--r--. 1 root root 123980 Aug 11 07:47 libvirt-nss-2.0.0-1.el7.x86_64.rpm
Then install all rpm packages
[root@localhost home]# rpm -i /home/user3/jail/root/rpmbuild/RPMS/x86_64/*
You may be prompted missing package, yum install it on the line
[root@localhost home]# yum install -y augeas sanlock-devel sanlock
Start libvirtd process
[root@localhost home]# systemctl start libvirtd
[root@localhost home]# virsh list
Id Name State
----------------------------------------------------
[root@localhost home]# virsh -v
2.0.0
Successful installation, see libvirtd path
[root@localhost home]# ps -ef|grep libvirtd
root 16193 1 0 16:04 ? 00:00:00 /usr/sbin/libvirtd
root 16407 21296 0 16:07 pts/0 00:00:00 grep --color=auto libvirtd
After testing, you can normally start the virtual machine
4.4. Error Handling
1. error can not start a virtual machine
[root@localhost user3]# virsh start vm_vbras_64
error: Failed to start domain vm_vbras_64
error: Failed to connect socket to '/var/run/libvirt/virtlogd-sock': Connection refused
Probably because there are no related processes to kill before reloading, what specifically do this thing has not been studied
[root@localhost user3]# ll /var/run/libvirt/virtlogd-sock
srw-rw-rw-. 1 root root 0 Aug 11 11:57 /var/run/libvirt/virtlogd-sock
[root@localhost user3]# systemctl stop libvirtd
[root@localhost user3]# rm /var/run/libvirt/virtlogd-sock
rm: remove socket ‘/var/run/libvirt/virtlogd-sock’? y
[root@localhost ~]# /usr/sbin/virtlogd --daemon
[root@localhost user3]# systemctl start libvirtd
And then re-run the virtual machine to normal
Updated: 20,190,911, update and maintain long-term ...