openVswitch 在centos下安装

来源:互联网 发布:360 卫士 for mac 编辑:程序博客网 时间:2024/06/16 23:45

OpenvSwitch概念:用作虚拟交换机,传递虚拟机VM之间的流量,以及实现VM和外界网络的通信。

OpenvSwitch数据路径需要桥接支持(CONFIG_BRIDGE)作为内核模块构建。(这在Linux发行版提供的内核中是常见的)桥接模块不能加载或使用。如果桥模块正在运行(使用“lsmod | grep bridge”进行检查),则在启动数据路径之前必须先删除它(“rmmod bridge”)。

安装openvswitch-2.5.0

安装依赖包:

yum -y install make gcc openssl-devel autoconf automake rpm-build redhat-rpm-config

yum -y install python-devel openssl-devel kernel-devel kernel-debug-devel libtool wget

预处理

mkdir -p ~/rpmbuild/SOURCES

wget http://openvswitch.org/releases/openvswitch-2.5.0.tar.gz

cp openvswitch-2.5.0.tar.gz ~/rpmbuild/SOURCES/

tar xfz openvswitch-2.5.0.tar.gz

sed ‘s/openvswitch-kmod,
//g’ openvswitch-2.5.0/rhel/openvswitch.spec > openvswitch-2.5.0/rhel/openvswitch_no_kmod.spec

构建RPM包

rpmbuild -bb –nocheck~/openvswitch-2.5.0/rhel/openvswitch_no_kmod.spec

安装:

yum localinstall ~/ rpmbuild/RPMS/x86_64/openvswitch-2.5.0-1.x86_64.rpm

5.启动相关服务:
操作前先cd

cd ~

systemctl start openvswitch.service

如果需要使用openvswitch进行网络配置请看以下步骤:

配置openvswitch

注意:在禁用内核的bridge时候,要先禁止防火墙的开机启动。
centos7以后的版本为:

systemctl stop firewalldsystemctl disable firewalld

[root@localhost ~]# lsmod |grep bridge

bridge                119562  1 ebtable_broutestp                    12976  1 bridgellc                    14552  2 stp,bridge

此时可以发现已经有bridge启动了,执行rmmod bridge会报错

rmmod: ERROR: Module bridge is in use by: ebtable_broute

解决方法:
service etbales status

Redirecting to /bin/systemctl status  ebtables.service● ebtables.service - Ethernet Bridge Filtering tables   Loaded: loaded (/usr/lib/systemd/system/ebtables.service; disabled; vendor preset: disabled)   Active: inactive (dead)

发现ebtables.service 的路径

vim /usr/lib/systemd/system/ebtables.service

[Unit]Description=Ethernet Bridge Filtering tables[Service]Type=oneshotRemainAfterExit=yesExecStart=/usr/libexec/ebtables startExecStop=/usr/libexec/ebtables stop[Install]WantedBy=multi-user.target

执行 /usr/libexec/ebtables stop
然后再rmmod bridge 即可删除内核的桥模块
但是这样重启之后系统会再自动开启,所以要加入黑名单,防止系统重启后bridge加载

vim /etc/modprobe.d/blacklist.conf

blacklist bridge

将Open vSwitch在内核中加载

[root@localhost ~]# find / -name * openvswitch.ko */usr/lib/modules/3.10.0-327.el7.x86_64/kernel/net/openvswitch/openvswitch.ko

将openvswith 在内核中加载

insmod /usr/lib/modules/3.10.0-327.el7.x86_64/kernel/net/openvswitch/openvswitch.ko

使Open vSwitch自动启动

# cd /usr/lib/modules/3.10.0-327.el7.x86_64/kernel/net/openvswitch/# chmod a+x openvswitch.ko# depmod -a

vim /etc/sysconfig/modules/openvswitch.modules

增加以下内容:

#!/bin/shif [ $(grep -c openvswitch /proc/modules) -eq 0 ]; thenmodprobe -b openvswitch > /dev/null 2>&1fiif [ $(grep -c brcompat /proc/modules) -eq 0 ]; thenmodprobe -b brcompat > /dev/null 2>&1fi

修改文件权限

chmod 755 /etc/sysconfig/modules/openvswitch.modules

初始化OVS数据库与服务器

使用ovsdb工具初始化配置数据库。# mkdir -p /etc/openvswitch# ovsdb-tool create  /etc/openvswitch/conf.db $HOME/rpmbuild/BUILD/openvswitch-2.5.0/vswitchd/vswitch.ovsschema在启动OVS之前,我们需要先启动ovsdb-server配置数据库。注意后面的命令大部分是由两个短“-”组成的。# ovsdb-server -v --remote=punix:/var/run/openvswitch/db.sock --remote=db:Open_vSwitch,Open_vSwitch,manager_options --private-key=db:Open_vSwitch,SSL,private_key --certificate=db:Open_vSwitch,SSL,certificate --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert --pidfile --detach首次用ovsdb-tool创建数据库时需用ovs-vsctl命令初始化下数据库。# ovs-vsctl --no-wait init 启动OVS主进程# ovs-vswitchd --pidfile  --detach我们可以通过如下命令查看所安装OVS的版本号。[root@localhost ~]# ovs-vsctl --versionovs-vsctl (Open vSwitch) 2.5.0Compiled May 24 2017 08:34:21DB Schema 7.12.1如果到这步你都没有问题,那么恭喜,你已经成功安装并启动了OVS 2.5.0。

利用openvswitch配置网络桥接

vim /etc/sysconfig/network-scripts/ifcfg-enps10

BOOTPROTO=noneNAME=enp1s0DEVICE=enp1s0ONBOOT=yesOVS_BRIDGE=br0DEVICETYPE=ovsTYPE=OVSPortHWADDR=dc:4a:3e:42:7f:e4DNS1=8.8.8.8DNS2=8.8.4.4IPADDR=192.168.77.102NETMASK=255.255.255.0

vim /etc/sysconfig/network-scripts/ifcfg-br0

DEVICE=br0NAME=br0ONBOOT=yesDEVICETYPE=ovsTYPE=OVSBridgeBOOTPROTO=staticIPADDR=192.168.77.102GATEWAY=192.168.77.254NETMASK=255.255.255.0HOTPLUG=noDNS1=8.8.8.8DNS2=8.8.4.4
原创粉丝点击