经过几天的努力,终于完成安装了!现在记录一下,方便以后重装KVM时使用。

安装版本:

qemu-4.0.0.tar.xz
libvirt-5.4.0.tar.xz

官网下载地址
QEMU

https://download.qemu.org/

Libvirt

https://libvirt.org/sources/

首先更新一下系统

yum update -y

然后重启

reboot

卸载旧内核

yum remove kernel -y

现在开始进行安装:

首先安装qemu kvm

安装依赖包

yum -y install gcc gcc-c++ automake libtool zlib-devel glib2-devel bzip2-devel libuuid-devel spice-protocol spice-server-devel usbredir-devel libaio-devel

在官网地址下载好qemu-4.0.0.tar.xz包解压并进入qemu-4.0.0目录

tar xvJf qemu-4.0.0.tar.xz
cd qemu-4.0.0

首先配置,改变一下编译安装的目录,方便以后使用

./configure --prefix=/usr

配置完成后进行安装

make && make install

安装完成后,做链接

ln -sf /usr/bin/qemu-system-x86_64 /usr/bin/qemu-kvm
ln -sf /usr/bin/qemu-system-x86_64 /usr/libexec/qemu-kvm

然后查看是否成功

qemu-img --version
qemu-kvm --version

现在开始安装libvirt

先安装一下virt-install工具,不然后面安装就会出现某些问题。

yum -y install virt-install

完成后,开始安装相关依赖包

yum -y install libnl-devel libxml2-devel yajl-devel device-mapper-devel libpciaccess-devel gnutls* libxslt

在官网地址下载好libvirt-5.4.0.tar.xz包解压并进入libvirt-5.4.0目录

tar xvJf libvirt-5.4.0.tar.xz
cd libvirt-5.4.0

autogen.sh脚本提供了“--system”参数,可保持对操作系统发型版中安装可执行程序和共享库的目录的一致性:

./autogen.sh --system

然后进行安装

make && make install

完成先安装一下管理工具包和桥接

yum -y install virt-manager virt-viewer bridge-utils

yum -y install libXdmcp libxkbfile xorg-x11-xkb-utils

完成后配置一下br0桥接

cd /etc/sysconfig/network-scripts

cp ifcfg-eth0 ifcfg-br0
sed -i 's/^IPADDR=/#IPADDR=/g' ifcfg-eth0
sed -i 's/^GATEWAY/#GATEWAY/g' ifcfg-eth0
sed -i 's/^IPV6ADDR=/#IPV6ADDR=/g' ifcfg-eth0
sed -i 's/^IPV6_DEFAULTGW=/#IPV6_DEFAULTGW=/g' ifcfg-eth0
echo BRIDGE="br0">>ifcfg-eth0
sed -i 's/TYPE="Ethernet"/TYPE="Bridge"/g' ifcfg-br0
sed -i 's/DEVICE="eth0"/DEVICE="br0"/g' ifcfg-br0
sed -i 's/NAME="eth0"/NAME="br0"/g' ifcfg-br0
sed -i 's/^UUID=/#UUID=/g' ifcfg-br0

重启网络

systemctl restart network

由于编译安装libvirt的版本无法使用systemctl管理,我们就拷贝一下libvirtd.service到/etc/systemd/system/,这样就可以使用systemctl管理了:

cp /usr/lib/systemd/system/libvirtd.service /etc/systemd/system/libvirtd.service

然后启动libvirt,并设置开机启动

systemctl start libvirtd.service #启动libvirt
systemctl enable libvirtd.service #开机启动libvirt

还需要安装一下防火墙

yum install firewalld
systemctl start firewalld
systemctl enable firewalld

最后测试一下

virsh list --all

没显示错误就成功了。

XMing,virt-manager管理工具

标签: centos7, KVM, Qemu, libvirt, 编译

已有 3 条评论

  1. yuanjibin yuanjibin

    ubuntu编译时出错,

    root@yuanjibin:/home/yuanjibin# cd libvirt-1.3.5
    root@yuanjibin:/home/yuanjibin/libvirt-1.3.5# make
    make all-recursive
    make[1]: Entering directory '/home/yuanjibin/libvirt-1.3.5'
    Making all in .
    make[2]: Entering directory '/home/yuanjibin/libvirt-1.3.5'
    make[2]: Leaving directory '/home/yuanjibin/libvirt-1.3.5'
    Making all in gnulib/lib
    make[2]: Entering directory '/home/yuanjibin/libvirt-1.3.5/gnulib/lib'
    make all-am
    make[3]: Entering directory '/home/yuanjibin/libvirt-1.3.5/gnulib/lib'
    CC fseeko.lo
    fseeko.c: In function 'rpl_fseeko':
    fseeko.c:110:4: error: #error "Please port gnulib fseeko.c to your platform! Look at the code in fseeko.c, then report this to bug-gnulib."
    110 | #error "Please port gnulib fseeko.c to your platform! Look at the code in fseeko.c, then report this to bug-gnulib."
    | ^~~~~
    make[3]: *** [Makefile:2259: fseeko.lo] Error 1
    make[3]: Leaving directory '/home/yuanjibin/libvirt-1.3.5/gnulib/lib'
    make[2]: *** [Makefile:2011: all] Error 2
    make[2]: Leaving directory '/home/yuanjibin/libvirt-1.3.5/gnulib/lib'
    make[1]: *** [Makefile:2004: all-recursive] Error 1
    make[1]: Leaving directory '/home/yuanjibin/libvirt-1.3.5'
    make: *** [Makefile:1901: all] Error 2

  2. 111 111

    启动域时出错: 内部错误:qemu unexpectedly closed the monitor: libvirt: 错误 : 无法执行二进制文件 /usr/libexec/qemu-kvm: 权限不够

    Traceback (most recent call last):
    File "/usr/share/virt-manager/virtManager/asyncjob.py", line 89, in cb_wrapper
    callback(asyncjob, *args, **kwargs)
    File "/usr/share/virt-manager/virtManager/asyncjob.py", line 125, in tmpcb
    callback(*args, **kwargs)
    File "/usr/share/virt-manager/virtManager/libvirtobject.py", line 82, in newfn
    ret = fn(self, *args, **kwargs)
    File "/usr/share/virt-manager/virtManager/domain.py", line 1506, in startup
    self._backend.create()
    File "/usr/lib64/python2.7/site-packages/libvirt.py", line 1080, in create
    if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
    libvirtError: 内部错误:qemu unexpectedly closed the monitor: libvirt: 错误 : 无法执行二进制文件 /usr/libexec/qemu-kvm: 权限不够
    更新完成后 出现这个错误能帮忙看下嘛?

    1. 222 222

      权限不够是不是没有关闭selinux,试试把这个关了

添加新评论