2013年7月18日 星期四

[轉] KVM and OpenVSwitch on Centos 6.3 Minimal

原文網址:http://nullworks.wordpress.com/2012/09/19/kvm-and-openvswitch-on-centos-6-3-minimal/

These are my notes for installing KVM on Centos 6.3 minimal.



====================================================================

# Install Centos 6.3 minimal x86_64 on a server
## Disable selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/sysconfig/selinux
## Set the hostname
vi /etc/sysconfig/network
HOSTNAME=whatevername
## Install basic tools
yum -y install screen sudo wget mlocate ntpdate git links
## (Optional) Install EPEL
wget http://mirror.chpc.utah.edu/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm
rpm -ivh epel-release-6-7.noarch.rpm
## Update the system
yum -y update
## Disable services not used
chkconfig fcoe off
chkconfig ip6tables off
chkconfig iscsi off
chkconfig iscsid off
chkconfig lldpad off
chkconfig netfs off
chkconfig rpcbind off
chkconfig rpcgssd off
chkconfig rpcidmapd off
chkconfig nfslock off
## Install virtualization groups
yum groupinstall Virtualization "Virtualization Client" "Virtualization Platform" "Virtualization Tools"
## Install additional stuff needed
yum install avahi gcc make libxml2-devel gnutls-devel device-mapper-devel python-devel libnl-devel dejavu-lgc-sans-fonts openssl-devel yajl-devel avahi-devel libssh2-devel libcurl-devel kernel-devel
## Remove ebtables
yum -y remove ebtables
## Get and install libvirt sources (needed for openvswitch support)
wget http://libvirt.org/sources/libvirt-0.10.1.tar.gz
tar zxvf libvirt-0.10.1.tar.gz
cd libvirt-0.10.1
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc
make; make install; ldconfig
### (Optional) Setup unsecured access to libvirtd
sed -i 's/#listen_tls = 0/listen_tls = 0/' /etc/libvirt/libvirtd.conf
sed -i 's/#auth_unix_rw = "none"/auth_unix_rw = "none"/' /etc/libvirt/libvirtd.conf
## Start libvirtd service
service messagebus start
service avahi-daemon start
service libvirtd start
## Set libvirtd to start on boots
chkconfig libvirtd on
## Disabled libvirt network
virsh net-destroy default
virsh net-undefine default
## Get and install openvswitch
wget http://openvswitch.org/releases/openvswitch-1.7.1.tar.gz
tar zxvf openvswitch-1.7.1.tar.gz
cd openvswitch-1.7.1
./configure --prefix=/usr --localstatedir=/var --sysconfdir=/etc --with-linux=/lib/modules/`uname -r`/build
#### There seems to be an issue with skbuff.h, so here's what I do to get around it, not 100% is this is right or what impact it might have, so use at your own risk
sed -i 's/#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)/#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)/' datapath/linux/compat/include/linux/skbuff.h
## Build and install openvswitch
make; make install; ldconfig
## Build and install the kernel modules<code>
make -C /usr/src/kernels/`uname -r` modules_install M=~/openvswitch-1.7.1/datapath/linux
## Copy over sysconfig files
cp rhel/etc_init.d_openvswitch /etc/init.d/openvswitch
cp rhel/etc_logrotate.d_openvswitch /etc/logrotate.d/openvswitch
cp rhel/etc_sysconfig_network-scripts_ifup-ovs /etc/sysconfig/network-scripts/ifup-ovs
cp rhel/etc_sysconfig_network-scripts_ifdown-ovs /etc/sysconfig/network-scripts/ifdown-ovs
cp rhel/usr_share_openvswitch_scripts_sysconfig.template /etc/sysconfig/openvswitch
## Edit sysconfig file for BRCOMPAT
sed -i 's/# BRCOMPAT=yes/BRCOMPAT=yes/' /etc/sysconfig/openvswitch
## Create bridge file
vi /etc/sysconfig/network-scripts/ifcfg-ovsbr1
DEVICE=ovsbr1
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=10.0.0.1
NETMASK=255.255.255.0
HOTPLUG=no
## Remove bridge module
rmmod bridge
## Blacklist the bridge module
echo >> /etc/modprobe.d/blacklist.conf <
# Bridge, using openvswitch instead
blacklist bridge
EOT
## Start openvswitch
service openvswitch start
### This next part is not needed if using OpenStack ###
## (Optional) Add Iptables NAT and Rules
iptables -A POSTROUTING -o eth0 -j MASQUERADE
iptables -A INPUT -i ovsbr1 -j ACCEPT
iptables -A FORWARD -i ovsbr1 -j ACCEPT
## Save iptables rules
service iptables save
## Edit the saved iptables file, remove the FORWARD REJECT
vi /etc/sysconfig/iptables
#-A FORWARD -j REJECT --reject-with icmp-host-prohibited
## Restart iptables
service iptables restart

沒有留言: