LXC在主机之间迁移

LXC在主机之间迁移

我用 LXC 设置了一个测试系统,并安装了一个网络服务器等,这一切都不是问题。但现在我想切换到另一个主机系统,我还压缩了 /var/lib/lxc/webserver 并将其复制到另一个主机。但我遇到了一些错误:

lxc-start: failed to attach 'vethO5HJ2b' to the bridge 'lxcbr0' : No such device
lxc-start: failed to create netdev
lxc-start: failed to create the network
lxc-start: failed to spawn 'webserver'

在配置中我确实找到了网络设置。有解决网络问题或退出主机之间迁移的更好方法的想法吗?

ifconfig-a

Host1(虚拟机正在这里工作)

eth0      Link encap:Ethernet  Hardware Adresse 00:25:90:d2:c2:d6  
          inet Adresse:85.xxx.xxx.43  Bcast:85.xxx.xxx.43  Maske:255.255.255.255
          inet6-Adresse: fe80::225:90ff:fed2:c2d6/64 Gültigkeitsbereich:Verbindung
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX packets:186831047 errors:0 dropped:0 overruns:0 frame:0
          TX packets:170397357 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX-Bytes:14641876568 (14.6 GB)  TX-Bytes:32363758586 (32.3 GB)
          Speicher:f7100000-f7180000 

eth0:1    Link encap:Ethernet  Hardware Adresse 00:25:90:d2:c2:d6  
          inet Adresse:81.xxx.xxx.247  Bcast:81.xxx.xxx.255  Maske:255.255.255.255
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          Speicher:f7100000-f7180000 

eth1      Link encap:Ethernet  Hardware Adresse 00:25:90:d2:c2:d7  
          BROADCAST MULTICAST  MTU:1500  Metrik:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX-Bytes:0 (0.0 B)  TX-Bytes:0 (0.0 B)
          Interrupt:20 Speicher:f7200000-f7220000 

lo        Link encap:Lokale Schleife  
          inet Adresse:127.0.0.1  Maske:255.0.0.0
          inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine
          UP LOOPBACK RUNNING  MTU:65536  Metrik:1
          RX packets:22574 errors:0 dropped:0 overruns:0 frame:0
          TX packets:22574 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:0 
          RX-Bytes:4393152 (4.3 MB)  TX-Bytes:4393152 (4.3 MB)

lxcbr0    Link encap:Ethernet  Hardware Adresse ee:2c:00:bf:f0:a9  
          inet Adresse:10.0.3.1  Bcast:10.0.3.255  Maske:255.255.255.0
          inet6-Adresse: fe80::ec2c:ff:febf:f0a9/64 Gültigkeitsbereich:Verbindung
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:0 
          RX-Bytes:0 (0.0 B)  TX-Bytes:468 (468.0 B)

bridge name bridge id       STP enabled interfaces
lxcbr0      8000.000000000000   no  

ls: Zugriff auf /var/log/upstart/lxc* nicht möglich: Datei oder Verzeichnis nicht gefunden (in English, not found)  

$ brctl show
bridge name bridge id       STP enabled interfaces
lxcbr0      8000.000000000000   no      
minecraft@h2210663:~$ ls -l /var/log/upstart/lxc*
ls: Zugriff auf /var/log/upstart/lxc* nicht möglich: Datei oder Verzeichnis nicht gefunden
minecraft@h2210663:~$ cat /etc/default/lxc
# MIRROR to be used by ubuntu template at container creation:
# Leaving it undefined is fine
#MIRROR="http://archive.ubuntu.com/ubuntu"
# or 
#MIRROR="http://<host-ip-addr>:3142/archive.ubuntu.com/ubuntu"

# LXC_AUTO - whether or not to start containers symlinked under
# /etc/lxc/auto
LXC_AUTO="true"

# Leave USE_LXC_BRIDGE as "true" if you want to use lxcbr0 for your
# containers.  Set to "false" if you'll use virbr0 or another existing
# bridge, or mavlan to your host's NIC.
USE_LXC_BRIDGE="true"

# If you change the LXC_BRIDGE to something other than lxcbr0, then
# you will also need to update your /etc/lxc/default.conf as well as the
# configuration (/var/lib/lxc/<container>/config) for any containers
# already created using the default config to reflect the new bridge
# name.
# If you have the dnsmasq daemon installed, you'll also have to update
# /etc/dnsmasq.d/lxc and restart the system wide dnsmasq daemon.
LXC_BRIDGE="lxcbr0"
LXC_ADDR="10.0.3.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.0.3.0/24"
LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
LXC_DHCP_MAX="253"

LXC_SHUTDOWN_TIMEOUT=120

$ cat /etc/init/lxc-net.conf
description "lxc network"
author "Serge Hallyn <[email protected]>"

start on starting lxc
stop on stopped lxc

env USE_LXC_BRIDGE="false"
env LXC_BRIDGE="lxcbr0"
env LXC_ADDR="10.0.3.1"
env LXC_NETMASK="255.255.255.0"
env LXC_NETWORK="10.0.3.0/24"
env LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
env LXC_DHCP_MAX="253"
env varrun="/var/run/lxc"

pre-start script
    [ -f /etc/default/lxc ] && . /etc/default/lxc

    [ "x$USE_LXC_BRIDGE" = "xtrue" ] || { stop; exit 0; }

    cleanup() {
        # dnsmasq failed to start, clean up the bridge
        iptables -t nat -D POSTROUTING -s ${LXC_NETWORK} ! -d ${LXC_NETWORK} -j MASQUERADE || true
        ifconfig ${LXC_BRIDGE} down || true
        brctl delbr ${LXC_BRIDGE} || true
    }

    if [ -d /sys/class/net/${LXC_BRIDGE} ]; then
        if [ ! -f ${varrun}/network_up ]; then
            # bridge exists, but we didn't start it
            stop;
        fi
        exit 0;
    fi

    # set up the lxc network
    echo 1 > /proc/sys/net/ipv4/ip_forward
    mkdir -p ${varrun}
    brctl addbr ${LXC_BRIDGE}
    ifconfig ${LXC_BRIDGE} ${LXC_ADDR} netmask ${LXC_NETMASK} up
    iptables -t nat -A POSTROUTING -s ${LXC_NETWORK} ! -d ${LXC_NETWORK} -j MASQUERADE
    dnsmasq -u lxc-dnsmasq --strict-order --bind-interfaces --pid-file=${varrun}/dnsmasq.pid --conf-file= --listen-address ${LXC_ADDR} --dhcp-range ${LXC_DHCP_RANGE} --dhcp-lease-max=${LXC_DHCP_MAX} --dhcp-no-override --except-interface=lo --interface=${LXC_BRIDGE} --dhcp-leasefile=/var/lib/misc/dnsmasq.${LXC_BRIDGE}.leases --dhcp-authoritative || cleanup
    touch ${varrun}/network_up
end script

post-stop script
    [ -f /etc/default/lxc ] && . /etc/default/lxc
    [ -f "${varrun}/network_up" ] || exit 0;
    # if $LXC_BRIDGE has attached interfaces, don't shut it down
    ls /sys/class/net/${LXC_BRIDGE}/brif/* > /dev/null 2>&1 && exit 0;

    if [ -d /sys/class/net/${LXC_BRIDGE} ]; then
        ifconfig ${LXC_BRIDGE} down
        iptables -t nat -D POSTROUTING -s ${LXC_NETWORK} ! -d ${LXC_NETWORK} -j MASQUERADE || true
        pid=`cat ${varrun}/dnsmasq.pid 2>/dev/null` && kill -9 $pid || true
        rm -f ${varrun}/dnsmasq.pid
        brctl delbr ${LXC_BRIDGE}
    fi
    rm -f ${varrun}/network_up
end script

主机2(目的地)

eth0      Link encap:Ethernet  Hardware Adresse 00:25:90:ae:09:6a  
          inet Adresse:2xx.xx4.xxx.217  Bcast:2xx.xx4.xxx.255  Maske:255.255.255.192
          inet6-Adresse: fe80::225:90ff:feae:96a/64 Gültigkeitsbereich:Verbindung
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          RX packets:2876153658 errors:0 dropped:48779 overruns:0 frame:0
          TX packets:2680725017 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX bytes:234344379020 (218.2 GiB)  TX bytes:710758489234 (661.9 GiB)
          Interrupt:16 Speicher:df900000-df920000 

eth0:1    Link encap:Ethernet  Hardware Adresse 00:25:90:ae:09:6a  
          inet Adresse:2xx.xx4.xxx.252  Bcast:2xx.xx4.xxx.255  Maske:255.255.255.192
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metrik:1
          Interrupt:16 Speicher:df900000-df920000 

eth1      Link encap:Ethernet  Hardware Adresse 00:25:90:ae:09:6b  
          BROADCAST MULTICAST  MTU:1500  Metrik:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:20 Speicher:dfa00000-dfa20000 

lo        Link encap:Lokale Schleife  
          inet Adresse:127.0.0.1  Maske:255.0.0.0
          inet6-Adresse: ::1/128 Gültigkeitsbereich:Maschine
          UP LOOPBACK RUNNING  MTU:16436  Metrik:1
          RX packets:738956166 errors:0 dropped:0 overruns:0 frame:0
          TX packets:738956166 errors:0 dropped:0 overruns:0 carrier:0
          Kollisionen:0 Sendewarteschlangenlänge:0 
          RX bytes:65605834297 (61.1 GiB)  TX bytes:65605834297 (61.1 GiB)
$ brctl show
bridge name bridge id       STP enabled interfaces

   $ ls: Zugriff auf /var/log/upstart/lxc* nicht möglich: Datei oder Verzeichnis nicht gefunden (in English, not found) 

$ cat /etc/default/lxc
# /etc/default/lxc

LXC_AUTO="true"
LXC_DIRECTORY="/ssd/lib/lxc"

$ cat /etc/init/lxc-net.conf
cat: /etc/init/lxc-net.conf: Datei oder Verzeichnis nicht gefunden (in English, not found)

答案1

从您收到的错误来看,第二台主机似乎缺少网桥lxcbr0

其他需要考虑的事项:

  1. 另外,您“移动”容器时遵循了哪些步骤?
  2. 您是否复制了容器的文件和 .conf 文件?
  3. 您是否使用这样的命令在第二台主机上重新创建该主机的容器?

    $ lxc-create -t TEMPLATE -f lxc.conf -n CONTAINER
    
  4. 另外,我会比较两个主机之间的以下内容,并确保两个系统之间的所有设置都一致。在两台主机上使用以下命令:

    $ ifconfig -a
    $ brctl show
    $ ls -l /var/log/upstart/lxc*
    $ cat /etc/default/lxc
    $ cat /etc/init/lxc-net.conf
    

相关内容