centos 6.4下openvswitch安装

时间:2023-01-01 10:25:47

1.安装环境

DELL R710

Centos 6.4 x86_64

2. 安装步骤

2.1 安装依赖包

yum install -y gcc gcc-c++ make libtool patch automake openssl openssl-devel rpm-build redhat-rpm-config python-devel 
yum install -y kernel kernel-devel kernel-debug-devel

2.2 安装autoconf

wget ftp://alpha.gnu.org/pub/gnu/autoconf/autoconf-2.68b.tar.gz
tar -zxvf autoconf-2.68b.tar.gz
cd autoconf-2.68b
./configure
make
make install

2.3 删除Bridge模块

rm -rf /etc/libvirt/qemu/networks/autostart/default.xml 
ifconfig virbr0 down 
rmmod bridge 

2.4 安装openvswitch

wget http://openvswitch.org/releases/openvswitch-1.11.0.tar.gz
mkdir -p /root/rpmbuild/SOURCES
cp openvswitch-1.11.0.tar.gz /root/rpmbuild/SOURCES
cd /root/rpmbuild/SOURCES
tar -zxvf openvswitch-1.11.0.tar.gz


在这里需要对rhel目录下的openvswitch-kmod-rhel6.spec以及openvswitch-kmod-rhel6.spec.in文件进行修改,分别添加%files,如果没有进行添加,后面在进行制作rpm安装包时会报错。

vi rhel/openvswitch-kmod-rhel6.spec
# Generated automatically -- do not modify!    -*- buffer-read-only: t -*-
# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
# Linux 6.

# Copyright (C) 2011, 2012 Nicira, Inc.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without warranty of any kind.

%define oname openvswitch

Name:           %{oname}-kmod
Version:        1.11.0
Release:        1%{?dist}
Summary:        Open vSwitch kernel module

Group:          System/Kernel
License:        GPLv2
URL:            http://openvswitch.org/
Source0:        %{oname}-%{version}.tar.gz
Source1:        %{oname}-kmod.files
BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires:  %kernel_module_package_buildreqs

# Without this we get an empty openvswitch-debuginfo package (whose name
# conflicts with the openvswitch-debuginfo package for OVS userspace).
%undefine _enable_debug_packages

# Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package
# for specified kernel version.
%{?kversion:%define kernel_version %kversion}

# Use -D 'kflavors default debug kdump' to build packages for
# specified kernel variants.
%{!?kflavors:%define kflavors default}

%kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors

%description
Open vSwitch Linux kernel module.

%files
/lib/modules/2.6.32-358.18.1.el6.x86_64/extra/openvswitch/openvswitch.ko
/etc/depmod.d/openvswitch.conf

%prep

%setup -n %{oname}-%{version}
cat > %{oname}.conf << EOF
override %{oname} * extra/%{oname}
override %{oname} * weak-updates/%{oname}
EOF

%build
for flavor in %flavors_to_build; do
	mkdir _$flavor
	(cd _$flavor && ../configure --with-linux="%{kernel_source $flavor}")
	%{__make} -C _$flavor/datapath/linux %{?_smp_mflags}
done

%install
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=extra/%{oname}
for flavor in %flavors_to_build ; do
         make -C %{kernel_source $flavor} modules_install \
                 M="`pwd`"/_$flavor/datapath/linux
done
install -d %{buildroot}%{_sysconfdir}/depmod.d/
install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/

%clean
rm -rf $RPM_BUILD_ROOT


 

vi rhel/openvswitch-kmod-rhel6.spec.in
# Spec file for Open vSwitch kernel modules on Red Hat Enterprise
# Linux 6.

# Copyright (C) 2011, 2012 Nicira, Inc.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.  This file is offered as-is,
# without warranty of any kind.

%define oname openvswitch

Name:           %{oname}-kmod
Version:        @VERSION@
Release:        1%{?dist}
Summary:        Open vSwitch kernel module

Group:          System/Kernel
License:        GPLv2
URL:            http://openvswitch.org/
Source0:        %{oname}-%{version}.tar.gz
Source1:        %{oname}-kmod.files
BuildRoot:      %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires:  %kernel_module_package_buildreqs

# Without this we get an empty openvswitch-debuginfo package (whose name
# conflicts with the openvswitch-debuginfo package for OVS userspace).
%undefine _enable_debug_packages

# Use -D 'kversion 2.6.32-131.6.1.el6.x86_64' to build package
# for specified kernel version.
%{?kversion:%define kernel_version %kversion}

# Use -D 'kflavors default debug kdump' to build packages for
# specified kernel variants.
%{!?kflavors:%define kflavors default}

%kernel_module_package -n %{oname} -f %{SOURCE1} %kflavors

%description
Open vSwitch Linux kernel module.

%prep

%setup -n %{oname}-%{version}
cat > %{oname}.conf << EOF
override %{oname} * extra/%{oname}
override %{oname} * weak-updates/%{oname}
EOF

%files
/lib/modules/2.6.32-358.18.1.el6.x86_64/extra/openvswitch/openvswitch.ko
/etc/depmod.d/openvswitch.conf


%build
for flavor in %flavors_to_build; do
	mkdir _$flavor
	(cd _$flavor && ../configure --with-linux="%{kernel_source $flavor}")
	%{__make} -C _$flavor/datapath/linux %{?_smp_mflags}
done

%install
export INSTALL_MOD_PATH=$RPM_BUILD_ROOT
export INSTALL_MOD_DIR=extra/%{oname}
for flavor in %flavors_to_build ; do
         make -C %{kernel_source $flavor} modules_install \
                 M="`pwd`"/_$flavor/datapath/linux
done
install -d %{buildroot}%{_sysconfdir}/depmod.d/
install -m 644 %{oname}.conf %{buildroot}%{_sysconfdir}/depmod.d/

%clean
rm -rf $RPM_BUILD_ROOT
./boot.sh
./configure.sh
make dist


创建rpm安装包

rpmbuild -bb rhel/openvswitch.spec
rpmbuild -bb rhel/openvswitch-kmod-rhel6.spec

此时可以在/root/rpmbuild/RPMS/x86_64目录下找到4个关于openvswitch的rpm包

安装openvswitch rpm安装包

rpm -ivh openvswitch-1.11.0-1.x86_64.rpm openvswitch-kmod-1.11.0-1.el6.x86_64.rpm
rpm -ivh kmod-openvswitch-1.11.0-1.el6.x86_64.rpm


启动openvswitch

modprobe openvswitch
/etc/init.d/openvswitch start
Starting ovsdb-server                                      [  OK  ]
Configuring Open vSwitch system IDs                        [  OK  ]
Starting ovs-vswitchd                                      [  OK  ]
Enabling remote OVSDB managers                             [  OK  ]


通过以上操作,就完成了在centos 6.4下openvswitch的安装!