Ubuntu12.04下安装Openvswitch

最近因为项目需要开始接触Openvswitch的开发,今天开始在Ubuntu12.04上进行openvswitch源码安装。主要的参考资料为

https://github.com/openvswitch/ovs/blob/master/INSTALL.md

下面将安装过程中一些注意事项记录如下:

Build Requirements

//运行命令apt-get install make gcc g++ libssl-dev

//如果是从源码安装,这3个库必须要,sudo apt-get install autoconf                                                                                                    automake libtool

Building and Installing Open vSwitch for Linux, FreeBSD or NetBSD

Once you have installed all the prerequisites listed above in the Base Prerequisites section, follow the procedure below to build.

  1. If you pulled the sources directly from an Open vSwitch Git tree, run boot.sh in the top source directory:

    % ./boot.sh

  2. Configure the package by running the configure script. You can usually invoke configure without any arguments. For example:

    % ./configure //注意,在ubuntu12.04上安装ovs,不能用这个configure命令,必须得和内核一起编译,用第4个命令,下面有注释

    By default all files are installed under /usr/local. If you want to install into, e.g., /usr and /var instead of /usr/local and /usr/local/var, add options as shown here:

    % ./configure --prefix=/usr --localstatedir=/var

    By default, static libraries are built and linked against. If you want to use shared libraries instead:

    % ./configure --enable-shared

    To use a specific C compiler for compiling Open vSwitch user programs, also specify it on the configure command line, like so:

    % ./configure CC=gcc-4.2

    To use 'clang' compiler:

    % ./configure CC=clang

    To build the Linux kernel module, so that you can run the kernel-based switch, pass the location of the kernel build directory on --with-linux. For example, to build for a running instance of Linux:

    % ./configure --with-linux=/lib/modules/uname -r/build //使用这个configure命令

    If --with-linux requests building for an unsupported version of Linux, then "configure" will fail with an error message. Please refer to the FAQ.md for advice in that case.

    If you wish to build the kernel module for an architecture other than the architecture of the machine used for the build, you may specify the kernel architecture string using the KARCH variable when invoking the configure script. For example, to build for MIPS with Linux:

    % ./configure --with-linux=/path/to/linux KARCH=mips

    If you plan to do much Open vSwitch development, you might want to add --enable-Werror, which adds the -Werror option to the compiler command line, turning warnings into errors. That makes it impossible to miss warnings generated by the build.

    To build with gcov code coverage support, add --enable-coverage, e.g.:

    % ./configure --enable-coverage

    The configure script accepts a number of other options and honors additional environment variables. For a full list, invoke configure with the --help option.

    You can also run configure from a separate build directory. This is helpful if you want to build Open vSwitch in more than one way from a single source directory, e.g. to try out both GCC and Clang builds, or to build kernel modules for more than one Linux version. Here is an example:

    % mkdir _gcc && (cd _gcc && ../configure CC=gcc)
    % mkdir _clang && (cd _clang && ../configure CC=clang)

  3. Run GNU make in the build directory, e.g.:

    % make

    or if GNU make is installed as "gmake":

    % gmake

    If you used a separate build directory, run make or gmake from that directory, e.g.:

    % make -C _gcc
    % make -C _clang

    For improved warnings if you installed "sparse" (see "Prerequisites"), add C=1 to the command line.

  4. Consider running the testsuite. Refer to "Running the Testsuite" below, for instructions.

  5. Become root by running "su" or another program.

  6. Run "make install" to install the executables and manpages into the running system, by default under /usr/local.

  7. If you built kernel modules, you may install and load them, e.g.:

    % make modules_install
    % /sbin/modprobe openvswitch

    To verify that the modules have been loaded, run "/sbin/lsmod" and check that openvswitch is listed.

    If the modprobe operation fails, look at the last few kernel log messages (e.g. with dmesg | tail):

    • The message "openvswitch: exports duplicate symbol br_should_route_hook (owned by bridge)" means that the bridge module is loaded. Run /sbin/rmmod bridge to remove it.

      If /sbin/rmmod bridge fails with "ERROR: Module bridge does not exist in /proc/modules", then the bridge is compiled into the kernel, rather than as a module. Open vSwitch does not support this configuration (see "Build Requirements", above).

    • The message "openvswitch: exports duplicate symbol dp_ioctl_hook (owned by ofdatapath)" means that the ofdatapath module from the OpenFlow reference implementation is loaded. Run /sbin/rmmod ofdatapath to remove it. (You might have to delete any existing datapaths beforehand, using the "dpctl" program included with the OpenFlow reference implementation. "ovs-dpctl" will not work.)

    • Otherwise, the most likely problem is that Open vSwitch was built for a kernel different from the one into which you are trying to load it. Run modinfo on openvswitch.ko and on a module built for the running kernel, e.g.:

         % /sbin/modinfo openvswitch.ko
         % /sbin/modinfo /lib/modules/`uname -r`/kernel/net/bridge/bridge.ko
      

      Compare the "vermagic" lines output by the two commands. If they differ, then Open vSwitch was built for the wrong kernel.

    • If you decide to report a bug or ask a question related to module loading, please include the output from the dmesgand modinfo commands mentioned above.

    There is an optional module parameter to openvswitch.ko called vlan_tso that enables TCP segmentation offload over VLANs on NICs that support it. Many drivers do not expose support for TSO on VLANs in a way that Open vSwitch can use but there is no way to detect whether this is the case. If you know that your particular driver can handle it (for example by testing sending large TCP packets over VLANs) then passing in a value of 1 may improve performance. Modules built for Linux kernels 2.6.37 and later, as well as specially patched versions of earlier kernels, do not need this and do not have this parameter. If you do not understand what this means or do not know if your driver will work, do not set this.

  8. Initialize the configuration database using ovsdb-tool, e.g.:

    % mkdir -p /usr/local/etc/openvswitch
    % ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema

Startup

Before starting ovs-vswitchd itself, you need to start its configuration database, ovsdb-server. Each machine on which Open vSwitch is installed should run its own copy of ovsdb-server. Configure it to use the database you created during installation (as explained above), to listen on a Unix domain socket, to connect to any managers specified in the database itself, and to use the SSL configuration in the database:

  % ovsdb-server --remote=punix:/usr/local/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

(If you built Open vSwitch without SSL support, then omit --private-key, --certificate, and --bootstrap-ca-cert.)

Then initialize the database using ovs-vsctl. This is only necessary the first time after you create the database with ovsdb-tool (but running it at any time is harmless):

  % ovs-vsctl --no-wait init

Then start the main Open vSwitch daemon, telling it to connect to the same Unix domain socket:

  % ovs-vswitchd --pidfile --detach //这里可以加多一个参数 --log-file=[FILENAME],这样如果出了错,会把对应的log信息输				    //出到log文件

Now you may use ovs-vsctl to set up bridges and other Open vSwitch features. For example, to create a bridge named br0 and add ports eth0 and vif1.0 to it:

  % ovs-vsctl add-br br0
  % ovs-vsctl add-port br0 eth0
  % ovs-vsctl add-port br0 vif1.0

Please refer to ovs-vsctl(8) for more details.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值