1.libvirt介绍
Libvirt是用于管理虚拟化平台的开源的API,后台程序和管理工具。它可以用于管理KVM、Xen、VMware ESX,QEMU和其他虚拟化技术。网上有很多文章做介绍,这里就不详细介绍了。libvirt本身安装过程没有什么难度,主要在于原生的centos会自带一个版本的libvirt,同时,如果自行编译的版本在安装之前,没有把发行版自带的libvirt卸载干净,就会出现各种各样的错误。笔者工作较忙,时间比较仓促,排版可能不太好看,请见谅。
2.卸载系统自带的libvirt
2.1.查看当前安装的libvirt相关包
[root@localhost libvirt-2.0.0]# rpm -qa |grep libvirt
2.2.全部卸载掉
由于目前笔者的环境已经是卸载干净的,因此,此处不做演示了
[root@localhost libvirt-2.0.0]# yum remove `rpm -qa |grep libvirt`
3.开始编译安装
3.1.解压缩
[root@localhost home]# tar xvf libvirt-2.0.0.tar.xz
3.2.生成Makefile文件
注意:如果./configure不带任何参数,各种文件会被安装到诸如/usr/local,/var/local下面,这样和原生安装路径不一致,通常不要
这样安装
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --enable-debug=yes $ make $ sudo make install
3.3.错误处理
错误1:需要安装依赖关系:
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
错误2
没有卸载系统自带的,直接安装的新的,但是版本一样
#查看服务状态
[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.
处理方式,杀死残余进程
[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可以正常工作,但是依然有报错
Apr 21 16:53:45 localhost.localdomain libvirtd[80026]: operation failed: network 'default' already exists with uuid 0c2459eb-2797-4a07-93af-6fb5857a6831
#查看libvirt网络配置
[root@192 libvirt-2.0.0]# virsh net-list --all Name State Autostart Persistent --------------------------------------------------- default active no no
#查看网络的xml
[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>
#删除该net之后重启libvirt进程遇到新问题
Apr 21 19:18:52 localhost.localdomain libvirtd[82476]: Initialization of netcf state driver failed: internal error: failed to initialize netcf
#关闭selinux之后,正常
[root@localhost ~]# setenforce 0
#网络也重新生成了[2]
[root@localhost ~]# virsh net-list Name State Autostart Persistent ---------------------------------------------------------- default active yes yes
错误3
virsh: error while loading shared libraries: libvirt-lxc.so.0: cannot open shared object file: No such file or directory bash-4.2# ldconfig bash-4.2# virsh --version 2.0.0
错误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
这是因为进程没有启动
[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.
长期更新维护…
参考文档
[1]: Linux下编译安装qemu和libvirt
[2]: Networking