更新源
yum install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
yum makecache
安装依赖包
yum -y install wget gcc make automake rpm-build redhat-rpm-config openssl-devel kernel-devel libtool iproute tunctl
yum install -y https://repos.fedorapeople.org/repos/openstack/openstack-icehouse/rdo-release-icehouse-4.noarch.rpm
yum update --enablerepo=openstack-icehouse -y iproute
reboot
源码安装最新的autoconf
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar zxvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure
make -j 4
make install
下载最新的Open vSwitch
wget http://openvswitch.org/releases/openvswitch-2.3.1.tar.gz
mkdir -p ~/rpmbuild/SOURCES
cp openvswitch-2.3.1.tar.gz ~/rpmbuild/SOURCES/
解压
tar zxvf openvswitch-2.3.1.tar.gz
cd openvswitch-2.3.1
cp rhel/openvswitch-kmod.files ~/rpmbuild/SOURCES/
生成rpm
rpmbuild -bb rhel/openvswitch.spec
rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec
安装
cd ~/rpmbuild/RPMS/x86_64/
yum -y install openvswitch-2.3.1-1.x86_64.rpm kmod-openvswitch-2.3.1-1.el6.x86_64.rpm
启动
service openvswitch start
创建网桥
ovs-vsctl add-br br0
ifconfig br0 up
显示所有网桥
ovs-vsctl show
删除网桥
ovs-vsctl del-br br0
增加端口
ovs-vsctl add-port br0 eth0
设置网卡为none
dhclient br0
用 Namespace 模拟两台虚拟机网络
ip netns add network1
ip netns add network2
创建两个虚拟网卡并加入网桥
ovs-vsctl add-port br0 vport1 -- set interface vport1 type=internal
ovs-vsctl add-port br0 vport2 -- set interface vport2 type=internal
tunctl -p -t vport1
tunctl -p -t vport2
两个虚拟网卡接入namespace
ip link set vport1 netns network1
ip link set vport2 netns network2
设置虚拟网卡的IP
ip netns exec network1 ifconfig vport1 192.168.0.1/24 up
ip netns exec network2 ifconfig vport2 192.168.0.2/24 up
显示vlan信息
ovs-appctl fdb/show br0
显示openflow信息
ovs-ofctl show br0
显示流表信息
ovs-ofctl dump-flows br0
显示网桥详细信息
ovs-vsctl list Bridge
显示端口详细信息
ovs-vsctl list Port
显示接口详细信息
ovs-vsctl list Interface
问题
Object "netns" is unknown, try "ip help".
iproute 不支持netns, 需要安装支持netns的版本
yum install -y https://repos.fedorapeople.org/repos/openstack/openstack-icehouse/rdo-release-icehouse-4.noarch.rpm
yum update --enablerepo=openstack-icehouse -y iproute