本文主要是介绍kvm与libvirt的编译与安装,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
系统环境:ubuntu 12.04 LTS amd64
必须安装64位,才可以安装KVM虚拟机。32位系统的内核默认没有把KVM模块编译进去,而且源中也没有与虚拟化相关的软件包,如Qemu等
一、KVM的编译安装
1、安装基本系统和开发工具
1.1 编译内核
mkdir /root/kvm
cd /root/kvm
wget http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.5.tar.gz
tar -zvxf linux-3.5.tar.gz -C /usr/src
cd /usr/src/linux-2.6.34.4
make menuconfig
vi .config
增加
CONFIG_SYSFS_DEPRECATED_V2=y
CONFIG_STP=m
CONFIG_BRIDGE=m
修改
CONFIG_STP=y
CONFIG_BRIDGE=y
make -j30 all
make modules_install
make install
1.2 安装kvm_mod
wget http://nchc.dl.sourceforge.net/project/kvm/kvm-kmod/3.5/kvm-kmod-3.5.tar.bz2
tar -jvxf kvm-kmod-3.5.tar.bz2
cd kvm-kmod-3.5
./configure
make && make install
reboot
1.3 确认kvm_kmod安装成功
lsmod | grep kvm
kvm_intel 40286 0
kvm 266256 1 kvm_intel
如果你的系统是64位可以直接进行这一步,因为64位的ubuntu是自带kvm模块的
1.4 安装qemu-kvm
apt-get install -y libglib2.0-dev
cd /root/kvm
wget https://launchpad.net/ubuntu/+archive/primary/+files/qemu-kvm_1.0%2Bnoroms.orig.tar.gz
tar -zxf qemu-kvm-0.12.5.tar.gz
cd qemu-kvm-0.12.5
./configure --prefix=/usr/local/kvm --disable-vnc-tls --disable-vnc-sasl --disable-curl --enable-system --static
make && make install
ln -s /usr/local/kvm/bin/qemu-img /usr/bin/qemu-img
ln -s /usr/local/kvm/bin/qemu-io /usr/bin/qemu-io
ln -s /usr/local/kvm/bin/qemu-nbd /usr/bin/qemu-nbd
ln -s /usr/local/kvm/bin/qemu-system-x86_64 /usr/bin/qemu
ln -s /usr/local/kvm/bin/qemu-system-x86_64 /usr/bin/kvm
ln -s /usr/local/kvm/bin/qemu-system-x86_64 /usr/bin/qemu-kvm
二、libvirt的编译安装
apt-get install -y libdevmapper libdevmapper-dev libgnutls-dev libxml2-dev libpciaccess-dev libudev-dev libnl-dev gnutls-bin
cd /root/kvm
wget https://launchpad.net/ubuntu/+archive/primary/+files/libvirt_1.0.2.orig.tar.gz
tar -zxf libvirt_1.0.2.orig.tar.gz
cd libvirt-1.0.2
./configure --prefix=/usr/local/libvirt --enable-debug=no --with-storage-lvm=no
make && make install
ln -s /usr/local/libvirt/bin/virsh /usr/bin/virsh
三、virtinst的编译安装
四、常见错误问题
问题一:configure: error: You must install the GnuTLS library in order to compile and run libvirt
解决方法:
Ubuntu:apt-get install -y libgnutls-dev
问题二:
/usr/local/libvirt/sbin/libvirtd
19:49:56.942: error : virRunWithHook:857 : internal error 'brctl setfd virbr0 0' exited with non-zero status 1 and signal 0: libvir: error : cannot execute binary brctl: No such file or directory
19:49:56.982: warning : qemudStartup:1832 : Unable to create cgroup for driver: No such device or address
解决方法:
Ubuntu:apt-get install -y bridge-utils
问题三:
19:51:11.368: error : virRunWithHook:857 : internal error '/sbin/iptables --table filter --insert FORWARD --destination 192.168.122.0/255.255.255.0 --out-interface virbr0 --match state --state ESTABLISHED,RELATED --jump ACCEPT' exited with non-zero status 1 and signal 0: iptables: Unknown error 18446744073709551615
19:51:11.368: error : networkAddMasqueradingIptablesRules:637 : failed to add iptables rule to allow forwarding to 'virbr0': Invalid argument
19:51:11.420: warning : qemudStartup:1832 : Unable to create cgroup for driver: No such device or address
如果使用桥接网络独立IP可以忽略
问题四:
这篇关于kvm与libvirt的编译与安装的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!