openvswitch在rhel61+kvm环境中的使用
安装
1. 下载相关软件
cd /root
下载openvswitch
wget http://openvswitch.org/releases/openvswitch-1.2.2.tar.gz ;
下载autoconf,因为rhel61自带的autoconf版本过低,我们使用fc15的autoconf包
wget http://mirrors.ustc.edu.cn/fedora/linux/releases/15/Fedora/x86_64/os/ \
Packages/autoconf-2.68-2.fc15.noarch.rpm;
下载m4,因为rhel61自带的m4版本过低,我们使用fc15的m4包
wget \
os/Packages/m4-1.4.16-1.fc15.x86_64.rpm;
2. 安装
卸载旧的m4包
yum remove m4 -y;
安装新的m4包
rpm -ivh m4-1.4.16-1.fc15.x86_64.rpm;
安装新的autoconf包
rpm -ivh autoconf-2.68-2.fc15.noarch.rpm ;
解压openvswitch包
tar -zxvf openvswitch-1.2.2.tar.gz;
cd openvswitch-1.2.2;
生成rhel6的内核模块文件
./boot.sh;
./configure; make dist
cp openvswitch-1.2.2.tar.gz /root/rpmbuild/SOURCES/
rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec
rpm -ivh /root/rpmbuild/RPMS/x86_64/kmod-openvswitch-1.2.2-1.el6.x86_64.rpm
加载模块
modprobe openvswitch_mod
modprobe brcompat_mod
生成openvswitch的相关命令,并将命令可执行文件拷贝到/bin
./configure;
make
make install
cp /usr/local/bin/ovs* /bin/
3. 配置
创建openvswitch数据库
mkdir -p /usr/local/etc/openvswitch;
ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema
启动openvswitch数据库
ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,manager_options \
--private-key=db:SSL,private_key \
--certificate=db:SSL,certificate \
--bootstrap-ca-cert=db:SSL,ca_cert \
--pidfile --detach
启动openvswitch交换机服务
ovs-vswitchd --pidfile –detach
初始openvswitch化交换机
ovs-vsctl --no-wait init
启动openvswitch交换机和Linux网桥兼容服务
ovs-brcompatd --pidfile –detach
创建一个交换机,并将em1接口划分到交换机中
注意:和em1相连的交换机端口需要配置成trunk模式
brctl addbr br0
brctl addif br0 em1
也可以使用如下命令
#/usr/local/bin/ovs-vsctl del-br br0
#/usr/local/bin/ovs-vsctl add-br br0
#/usr/local/bin/ovs-vsctl add-port br0 em1
使用命令ovs-vsctl show可以看到结果
[root@dell4 ~]# ovs-vsctl show
f12e9e5d-6504-41b5-a5c2-7e9972d462ab
Bridge "br0"
Port "em1"
Interface "em1"
Port "br0"
Interface "br0"
type: internal
因为和linux网桥兼容,使用brctl show命令,也可以看到
[root@dell4 ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 /sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
/sys/class/net/br0/bridge: No such file or directory
0000.14feb5dc4204 no em1
vnet0
为了让openvswitch相关服务开机能够启动,编辑一个脚本,放置到/etc/rc.local中,内容如下:
[root@dell4 ~]# cat start_openvswitch.sh
rmmod bridge
modprobe openvswitch_mod
modprobe brcompat_mod
/usr/local/sbin/ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
--remote=db:Open_vSwitch,manager_options \
--private-key=db:SSL,private_key \
--certificate=db:SSL,certificate \
--bootstrap-ca-cert=db:SSL,ca_cert \
--pidfile --detach
#/usr/local/sbin/ovs-brcompatd --appctl=/usr/local/bin/ --detach
/usr/local/sbin/ovs-vswitchd --pidfile --detach
/usr/local/bin/ovs-vsctl --no-wait init
/usr/local/sbin/ovs-brcompatd --pidfile --detach
#/usr/local/bin/ovs-vsctl del-br br0
#/usr/local/bin/ovs-vsctl add-br br0
#/usr/local/bin/ovs-vsctl add-port br0 em1
ifconfig br0 up
ifconfig br0 172.16.1.160 netmask 255.255.255.0
route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.1.1
虚拟机的配置请参考如下连接