在一个全新的ubuntu16.04.1中通过源码编译安装qemu和libvirt环境。需要注意一个安装顺序问题。建议先安装qemu.后安装libvirt.因为,libvirt起来后,会检测其需要使用的hypervisor。另外,他们的安装最好都指定安装路径到/usr目录下,这样可以使安装完后直接可以全局使用libvirt和qemu命令。且libvirt默认是通过调用/usr/bin下的qemu命令获取qemu版本和命令使用的。所以,为保证libvirt中能方便的调用到qemu命令,两个组件的安装都需要指定到/usr目录下。(转)
qemu和libvirt的参考链接:
http://wiki.qemu.org/Manual
http://libvirt.org/index.html
qemu和libvirt的版本获取:
http://wiki.qemu.org/Download
http://libvirt.org/sources/
实验使用的源:
libvirt-1.3.5.tar.gz
qemu-2.5.0.tar.bz2
本次安装环境是Ubuntu 16.04.1 LTS下
1.安装qemu:
以下操作均使用root账户:
1. tar -jxvf qemu-2.5.0.tar.bz2
2. cd qemu-2.5.0/
3. 安装必要的组件:(此步可以在configure步骤中根据需要进行安装)apt-get install zlib1g-dev libglib2.0-dev libtool autoconf
4. ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
--prefix用以指定安装的目的路径。默然qemu会安装到/usr/local/bin中。
5. make
6. make install
安装完毕后可以尝试在任意目录下输入qemu命令。或直接输入which qemu-img查看命令的安装位置
root@admin123-virtual-machine:/home/libvirt# which qemu-img
/usr/bin/qemu-img
或者
root@admin123-virtual-machine:/home/libvirt# qemu-img --help | grep version
qemu-img version 2.5.0 (Debian 1:2.5+dfsg-5ubuntu10.14), Copyright (c) 2004-2008 Fabrice Bellard
conversion. If the number of bytes is 0, the source will not be scanned for
2.安装libvirt:
以下操作均使用root账户:
1. tar -zxvf libvirt-1.3.5.tar.gz
2. cd libvirt-1.3.5
3. 安装必要的组件:(此步可以在configure步骤中根据需要进行安装)
libyajl-dev libxml2-dev libdevmapper1.0.2.1 libdevmapper-dev libpciaccess-dev libnl-dev
4. ./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
--prefix用以指定安装的目的路径。默然libvirt会安装到/usr/local/bin中。
5. make
6. make install
7. 启动libvirtd: libvirtd -d
验证:
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# virsh version
Compiled against library: libvirt 1.3.5
Using library: libvirt 1.3.5
Using API: QEMU 1.3.5
Running hypervisor: QEMU 2.5.0
可能会出现的错误:
1.找不到libxml2
checking libxml2 xml2-config >= 2.6.0 ... configure: error: Could not find libxml2 anywhere (see config.log for details).
解决办法
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# apt-get install libxml2*
2.缺少device-mapper-devel/libdevmapper
configure: error: You must install device-mapper-devel/libdevmapper >= 1.0.0 to compile libvirt
解决办法:
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# apt-get install libdevmapper1.02.1 libdevmapper-dev
3.必须安装pciaccess模块来构建
configure: error: You must install the pciaccess module to build with udev
解决办法
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# apt-get install -y libpciaccess-dev
4.缺少libnl-devel
configure: error: libnl-devel >= 1.1 is required for macvtap support
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# apt-get install libnl-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package libnl-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libnl-dev' has no installation candidate
解决办法:
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# apt-get install libnl-3-dev
找了好多办法都是执行命令#apt-get install libnl-dev,但是怎么都行不通,一直提示E: Package ‘libnl-dev’ has no installation candidate,直到看到https://www.ubuntuupdates.org/package/core/precise/main/base/libnl-3-dev中写道有Package “libnl-3-dev”,执行# apt-get install libnl-3-dev才安装成功(不知道libnl-dev和libnl-3-dev有什么区别,也没真是跑起来,也不知道会不会有影响)
5.安装软件的时候出现了Package has no installation candidate的问题
E: Package 'libnl-dev' has no installation candidate
解决办法:
# apt-get update
# apt-get upgrade
# apt-get install <packagename>
6.缺少libnl-route-3.0
configure: error: Package requirements (libnl-route-3.0) were not met:
No package 'libnl-route-3.0' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables LIBNL_ROUTE3_CFLAGS
and LIBNL_ROUTE3_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
解决办法:
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# apt-get install libnl-route*
组建安装成功:
......
......
......
configure: DTrace: no
configure: numad: no
configure: XML Catalog: /etc/xml/catalog
configure: Init script: systemd
configure: Char device locks: /var/lock
configure: Default Editor: vi
configure: Loader/NVRAM:
configure: virt-login-shell: yes
configure: virt-host-validate: yes
configure:
configure: Developer Tools
configure:
configure: Wireshark dissector: no
configure:
configure: Privileges
configure:
configure: QEMU: root:root
configure:
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5#
完全安装成功:
root@admin123-virtual-machine:/home/libvirt/libvirt-1.3.5/libvirt-1.3.5# virsh version
Compiled against library: libvirt 1.3.5
Using library: libvirt 1.3.5
Using API: QEMU 1.3.5
Running hypervisor: QEMU 2.5.0
转载自:
http://blog.csdn.net/klyhuntermax/article/details/51363822
参考资料:
http://www.cnblogs.com/findumars/p/5679742.html
http://blog.csdn.net/klyhuntermax/article/details/51353212
http://blog.csdn.net/gg296231363/article/details/6891460
http://liuzhijun.iteye.com/blog/1728617
http://blog.csdn.net/scape1989/article/details/11002315
http://www.chenyudong.com/archives/install-qemu-libvirt-in-fedora-Linux.html http://www.360doc.com/content/14/0521/16/16285334_379675056.shtml
http://blog.csdn.NET/heybob/article/details/24481397
redhat下安装可参考:http://www.cnblogs.com/findumars/p/5679742.html