To be a better coder
分类: 云计算
2017-11-09 14:58:42
原文地址:Open vSwitch 安装 作者:liurhyme
Open vSwitch 安装
,下载完后输入以下命令解压1. 从官方网站中下载Open vSwitch源代码包,
[root@localhost ~]# tar –xzvf openvswitch-1.2.0.tar.gz
2. 进入解压后目录,输入以下命令配置Open vSwitch工程,生成Makefile文件。
[root@localhost ~]# ./configure --with-l26=/lib/modules/`uname -r`/build
--with-l26:生成内核模式的Open vSwitch时需指定的内核源码编译目录
指定Open vSwitch的安装位置加参数:--prefix=/…
如有其他问题可参考源码根目录下的帮助文件:INSTALL.Linux
3. 编译、链接、生成和安装Open vSwitch,命令如下,make install目录只安装Open vSwitch除内核模块外的其他所有模块,如ovs-vsctl、ovs-vswitchd、ovs-ofctl等
[root@localhost ~]# make
[root@localhost ~]# make install
4. 卸载原有虚拟网桥模块,命令如下,如果Xend正常启动,将自动加载linux虚拟网桥模块bridge.ko。
[root@localhost ~]# rmmod bridge
如果无法卸载,可用“lsmod”命令查看已加载的依赖于bridge的内核模块,并用“rmmod 模块名”卸载,常见的无法卸载的情况可通过预先执行下面两条命令解决。
[root@localhost ~]# /etc/init.d/iptables stop
[root@localhost ~]# rmmod xt_physdev
[如果已经安装成功,启动该模块也是从第5步开始。]
5. 加载Open vSwitch内核模块openvswitch_mod.ko和linux虚拟网桥兼容模块brcompat_mod.ko
[root@localhost ~]# insmod openvswitch-1.2.0/datapath/linux-2.6/openvswitch_mod.ko
[root@localhost ~]# insmod openvswitch-1.2.0/datapath/linux-2.6/brcompat_mod.ko
6. 根据ovsdb模板vswitch.ovsschema创建ovsdb数据库ovs-vswitchd.conf.db,用于存储虚拟交换机的配置信息,只需第一次运行Open vSwitch时创建
[root@localhost ~]# ovsdb-tool create
/usr/local/etc/ovs-vswitchd.conf.db
openvswitch-1.2.0/vswitchd/vswitch.ovsschema
7. 启动ovsdb数据库服务器,Open vSwitch虚拟网桥模块将通过ovsdb-server获得虚拟交换机配置信息,“—detach”表示以后台方式运行, ovsdb-server其他参数请参考“ovsdb-server –help”
[root@localhost ~]# ovsdb-server
/usr/local/etc/ovs-vswitchd.conf.db
--remote=punix:/usr/local/var/run/openvswitch/db.sock
--remote=db:Open_vSwitch,managers
--private-key=db:SSL,private_key
--certificate=db:SSL,certificate
--bootstrap-ca-cert=db:SSL,ca_cert
--detach
8. 初始化Open vSwitch控制接口,以便用ovs-vsctl管理配置虚拟交换机
[root@localhost ~]# ovs-vsctl --no-wait init
9. 启动Open vSwitch用户态模块,unix:后的文件为socket文件,为ovsdb-server监听的socket文件。
[root@localhost ~]# ovs-vswitchd unix:/usr/local/var/run/openvswitch/db.sock --detach
10. 启动linux原有虚拟网桥兼容模块用户态组件ovs-brcompatd,该模块必须在ovsdb-server和ovs-vswitchd启动后才能启动。
[root@localhost ~]# ovs-brcompatd
--pidfile
--detach
-vANY:console:EMER unix:/usr/local/var/run/openvswitch/db.sock
11. 添加网桥br0
[root@localhost ~]# ovs-vsctl add-br br0
12. 激活网桥br0
[root@localhost ~]# ifconfig br0 up
13. 配置网桥br0的ip地址和子网掩码
[root@localhost ~]# ifconfig br0 192.168.203.100/24
14. 将需要添加到网桥br0上的网络接口添加到br0中
[root@localhost ~]# ovs-vsctl add-port br0 peth0
[root@localhost ~]# ovs-vsctl add-port br0 vif0.0
下附在安装有Xen虚拟化平台的Linux发行版上Open vSwitch启动脚本:
(请确保Open vSwitch安装于默认路径,且该脚本放于与Open vSwitch工程目录同目录下)
#!/bin/bash
#./configure --with-l26=/lib/modules/`uname -r`/build
echo "close applications or modules depending on bridge.ko"
if service iptables status|grep running > /dev/null 2>&1; then
/etc/init.d/iptables stop;
fi
if lsmod|grep xt_physdev > /dev/null 2>&1; then
rmmod xt_physdev;
fi
echo "remove module bridge"
if lsmod|grep bridge > /dev/null 2>&1; then
if rmmod bridge >/dev/null 2>&1; then
echo "bridge.ko removed">/dev/null
else
echo "Failed to remove kernel module bridge"
exit
fi
fi
echo "clean obsolete socket files in /usr/local/var/run/openvswitch/"
for i in `ls /usr/local/var/run/openvswitch/|grep "ctl$"`;
do
rm /usr/local/var/run/openvswitch/$i;
done
echo "insert kernel module openvswitch_mod.ko"
if lsmod|grep bridge > /dev/null 2>&1; then
echo "bridge is already running">/dev/null;
elif insmod openvswitch-1.1.0pre2/datapath/linux-2.6/openvswitch_mod.ko ; then
echo "openvswitch_mod.ko inserted";
else
echo "failed to insert openvswitch_mod.ko";
exit
fi
#ovsdb-tool create /usr/local/etc/ovs-vswitchd.conf.db openvswitch-1.1.0pre2/vswitchd/vswitch.ovsschema
echo "start daemon ovsdb-server"
if ps -ef|grep -E "[[:digit:]][[:space:]]+ovsdb-server" >/dev/null 2>&1; then
echo "ovsdb-server is already running">/dev/null;
else
ovsdb-server /usr/local/etc/ovs-vswitchd.conf.db --remote=punix:/usr/local/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,managers --private-key=db:SSL,private_key --certificate=db:SSL,certificate --bootstrap-ca-cert=db:SSL,ca_cert --detach ;
fi
#vs-vsctl --no-wait init
echo "start daemon ovs-vswitchd"
if ps -ef|grep -E "[[:digit:]][[:space:]]+ovs-vswitchd" >/dev/null 2>&1; then
echo "ovs-vswitchd is already running" >/dev/null;
else
ovs-vswitchd unix:/usr/local/var/run/openvswitch/db.sock --detach ;
fi
echo "start daemon ovs-brcompatd"
if insmod openvswitch-1.1.0pre2/datapath/linux-2.6/brcompat_mod.ko; then
ovs-brcompatd --pidfile --detach -vANY:console:EMER unix:/usr/local/var/run/openvswitch/db.sock ;
fi
echo "add and configure bridge xenbr0"
if ovs-vsctl list-br|grep xenbr0 > /dev/null 2>&1; then
echo "bridge xenbr0 already exists" >/dev/null
else
ovs-vsctl add-br xenbr0
fi
ifconfig xenbr0 up
ifconfig xenbr0 192.168.205.118/24
echo "attach all interfaces to bridge xenbr0"
if /usr/sbin/brctl show |grep peth0 > /dev/null 2>&1; then
echo "peth0 is added" >/dev/null;
else
ovs-vsctl add-port xenbr0 peth0 > /dev/null 2>&1;
for i in `ifconfig|grep vif|awk '{print $1}'`;
do
ovs-vsctl add-port xenbr0 $i > /dev/null 2>&1;
done
fi
echo "Open vSwitch started successfully"
#ovs-vsctl add-port xenbr0 peth0
#/etc/init.d/network restart