Add a script to install libvirt and enable KVM/Qemu VM live migration

Change-Id: I775c0873aefd78e0d25fb07357dd7ea587451dcf
This commit is contained in:
Changbin Liu 2013-12-12 00:58:43 -05:00
parent 52c88b4844
commit cf46b6f9fc
1 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,66 @@
#!/bin/bash
## Install libvirt (1.2.0), and enable VM (KVM/Qemu) live
## migration. Default libvirt on Ubuntu 12.04 is 0.9.8, which does not
## work well with Open vSwitch ("<virtualport type='openvswitch'/>"
## cannot be added into VM xml configuration).
# Install KVM, QEMU and libvirt (0.9.8, so that we have /etc/init/libvirt-bin.conf)
sudo apt-get -y install \
kvm \
qemu \
libvirt-bin
# Install dependencies. You can omit the libcurl4-gnutls-dev package
# if you dont want ESX support.
sudo apt-get update
sudo apt-get -y install \
gcc \
make \
pkg-config \
libxml2-dev \
libgnutls-dev \
libdevmapper-dev \
libcurl4-gnutls-dev \
python-dev \
libpciaccess-dev \
libxen-dev \
libyajl-dev \
libnl-dev
sudo mkdir -p /opt/libvirt
sudo chmod 00755 /opt/libvirt
sudo chown root:root /opt/libvirt
sudo chmod a+w /opt/libvirt
cd /opt/libvirt
wget http://libvirt.org/sources/libvirt-1.2.0.tar.gz
tar xzvf libvirt-1.2.0.tar.gz
mv libvirt-1.2.0 libvirt
cd libvirt
./configure \
--prefix=/usr \
--localstatedir=/var \
--sysconfdir=/etc \
--with-esx=yes \
--with-xen=yes # if you need Xen support, youll need to add
# --with-xen=yes to the command
make -j
sudo make install
# enable libvirt for VM live migration
sudo sed -i /etc/libvirt/libvirtd.conf \
-e 's/#listen_tls = 0/listen_tls = 0/g' \
-e 's/#listen_tcp = 1/listen_tcp = 1/g' \
-e 's/#auth_tcp = "sasl"/auth_tcp = "none"/g'
sudo sed -i /etc/init/libvirt-bin.conf \
-e 's/env libvirtd_opts="-d"/env libvirtd_opts="-d -l"/g'
sudo sed -i /etc/default/libvirt-bin \
-e 's/libvirtd_opts="-d"/libvirtd_opts="-d -l"/g'
# restart libvirt
sudo service libvirt-bin restart
# Remove the default network created by libvirt
sudo virsh net-destroy default
sudo virsh net-undefine default