具有Open vSwitch的LXC [英] LXC with Open vSwitch

查看:171
本文介绍了具有Open vSwitch的LXC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的LXC容器中尝试使用OVS(软件Linux交换机) http://openvswitch.org/ Ubuntu作为主机和访客.所以我已经安装了它:

I want to try OVS (software Linux switch) http://openvswitch.org/ with my LXC container with Ubuntu as host and guest. So I have installed it:

# apt-get install openvswitch-switch

根据此文档配置 https://infologs.wordpress.com/2015/06/19/how-to-attach-lxc-container-to-ovs-openvswitch/

  1. 创建的测试容器:

  1. Created test container:

# lxc-create -t ubuntu -n veth03-ovs -- -r trusty

  • 创建了ovs桥并为其分配了IP:

  • Created ovs bridge and assigned IP to it:

    # ovs-vsctl add-br switch0
    # ip add add 192.168.100.1/24 dev switch0
    

  • 让它是新网络192.168.100.0/24,而switch0(根据我的理解)将是那里的第一个地址(网关).

    Let it be new network 192.168.100.0/24 and switch0 (according to my understanding) will be first address (gateway) there.

    看起来不错:

    # ip a
    ...
    4: ovs-system: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default 
        link/ether 52:9d:e1:60:1d:56 brd ff:ff:ff:ff:ff:ff
    5: switch0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default 
        link/ether 16:63:eb:47:13:41 brd ff:ff:ff:ff:ff:ff
        inet 192.168.100.1/24 scope global switch0
           valid_lft forever preferred_lft forever
    

    桥接口状态:

    # ovs-vsctl show
    1b236728-4637-42a5-8b81-53d4c93a6803
        Bridge "switch0"
            Port "switch0"
                Interface "switch0"
                    type: internal
        ovs_version: "2.3.2"
    

    1. 为veth03-ovs容器编辑的LXC配置,以使用此网桥:

    1. Edited LXC config for veth03-ovs container for using this bridge:

    # vim /var/lib/lxc/veth03-ovs/config
    ...
    lxc.network.type = veth
    lxc.network.flags = up
    
    lxc.network.script.up = /etc/lxc/ifup
    lxc.network.script.down = /etc/lxc/ifdown
    # lxc.network.veth.pair = lxc0
    lxc.network.hwaddr = 00:16:3e:15:b3:62
    lxc.network.ipv4 = 192.168.100.10
    

    所以我想将192.168.100.10指向容器的内部接口.

    So I want to point 192.168.100.10 for internal interface of container.

    /etc/lxc/ifup /etc/lxc/ifdown 为此桥添加/删除端口.

    /etc/lxc/ifup and /etc/lxc/ifdown add/remove ports for this bridge after start/stop of container.

    # cat /etc/lxc/ifup
    #!/bin/bash
    
    BRIDGE="switch0″
    ovs-vsctl –may-exist add-br $BRIDGE
    ovs-vsctl –if-exists del-port $BRIDGE $5
    ovs-vsctl –may-exist add-port $BRIDGE $5
    
    # cat /etc/lxc/ifdown 
    #!/bin/bash
    ovsBr=’switch0′
    ovs-vsctl –if-exists del-port ${ovsBr} $5
    

    所以现在我想启动容器,但得到:

    So now I want to start container but getting:

    # lxc-start -n veth03-ovs --logfile /tmp/log
    lxc-start: lxc_start.c: main: 344 The container failed to start.
    lxc-start: lxc_start.c: main: 346 To get more details, run the container in foreground mode.
    lxc-start: lxc_start.c: main: 348 Additional information can be obtained by setting the --logfile and --logpriority options.
    
    # cat /tmp/log
      lxc-start 1448974395.199 ERROR    lxc_conf - conf.c:run_buffer:342 - Script exited with status 1
      lxc-start 1448974395.225 ERROR    lxc_conf - conf.c:lxc_create_network:3079 - failed to create netdev
      lxc-start 1448974395.225 ERROR    lxc_start - start.c:lxc_spawn:950 - failed to create the network
      lxc-start 1448974395.225 ERROR    lxc_start - start.c:__lxc_start:1213 - failed to spawn 'veth03-ovs'
      lxc-start 1448974400.730 ERROR    lxc_start_ui - lxc_start.c:main:344 - The container failed to start.
      lxc-start 1448974400.730 ERROR    lxc_start_ui - lxc_start.c:main:346 - To get more details, run the container in foreground mode.
      lxc-start 1448974400.730 ERROR    lxc_start_ui - lxc_start.c:main:348 - Additional information can be obtained by setting the --logfile and --logpriority options.
    

    我认为 lxc.network.script.up / lxc.network.script.down 脚本中的错误及其未获取$5参数,该参数应该是LXC传递给OVS的中间接口.但是我不确定.

    I suppose that error in lxc.network.script.up / lxc.network.script.down scripts and its are not getting $5 parameter, which should be intermediate interface passed by LXC to OVS. But I am not sure.

    LXC是否支持Open vSwitch? https://github.com/lxc/lxc/issues/256

    Is LXC supports Open vSwitch? https://github.com/lxc/lxc/issues/256

    推荐答案

    这很糟糕.我刚刚从Wordpress博客复制了ifup/ifdown脚本.但是有错别字:

    It was my bad. I've just copied ifup/ifdown scripts from Wordpress blog. But there were typos:

    ovs-vsctl –may-exist add-br $BRIDGE
    

    但应为:

    ovs-vsctl --may-exist add-br $BRIDGE
    

    --,而不仅仅是may之前的-. ifup/ifdown脚本中的所有地方都相同.因此,它们应如下所示:

    --, not just - before may. The same everywhere in ifup/ifdown scripts. So they should look as these:

    # cat /etc/lxc/ifup
    #!/bin/bash
    
    BRIDGE=switch0
    ovs-vsctl --may-exist add-br $BRIDGE
    ovs-vsctl --if-exists del-port $BRIDGE $5
    ovs-vsctl --may-exist add-port $BRIDGE $5
    
    # cat /etc/lxc/ifdown
    #!/bin/bash
    ovsBr=switch0
    ovs-vsctl --if-exists del-port ${ovsBr} $5
    

    这篇关于具有Open vSwitch的LXC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆