Get started with lxc.

来源:互联网 发布:刘道成 mysql 百度云 编辑:程序博客网 时间:2024/05/10 12:52

Finally, I got some free time!!!!!!


Get lxc started in RHEL. Only for newbie to lxc.


Normally, we clone the lxc from github.com


git clone http://github.com/lxc/lxc.git

Then compile it.

[root@atest-guest lxc]# ./autogen.sh [root@atest-guest lxc]# ./configure [root@atest-guest lxc]# make[root@atest-guest lxc]# make install

But unfortunately, there are some problem to start enjoying lxc in rhel.

(1). Default lib is /usr/local/lib/. But it is not in the default libdir in RHEL.

[root@atest-guest lxc]# lxc-lslxc-config: error while loading shared libraries: liblxc.so.1: cannot open shared object file: No such file or directorylxc-config: error while loading shared libraries: liblxc.so.1: cannot open shared object file: No such file or directorylxc-config: error while loading shared libraries: liblxc.so.1: cannot open shared object file: No such file or directory.[root@atest-guest lxc]# locate liblxc.so/data/lxc/src/lxc/liblxc.so/usr/local/lib/liblxc.so/usr/local/lib/liblxc.so.1/usr/local/lib/liblxc.so.1.1.0.alpha2[root@atest-guest lxc]# ln -s /usr/local/lib/liblxc.so.1 /usr/lib64/liblxc.so.1[root@atest-guest lxc]# lxc-ls[root@atest-guest lxc]# echo $?0

(2). Please create a br named as lxcbr0.

[root@atest-guest lxc]# lxc-create -t sshd -n sshdGenerating public/private rsa key pair.Your identification has been saved in /usr/local/var/lib/lxc/ssh1/rootfs/etc/ssh/ssh_host_rsa_key.Your public key has been saved in /usr/local/var/lib/lxc/ssh1/rootfs/etc/ssh/ssh_host_rsa_key.pub.The key fingerprint is:9a:e8:af:2c:d9:2e:4a:d1:0d:b2:a8:23:41:bc:05:72 root@atest-guestThe key's randomart image is:+--[ RSA 2048]----+|..E              ||o..              || + o             ||o * o            ||o+ . .  S        ||...  . o         ||+. o. o          ||o.+o.            ||.. +=o.          |+-----------------+Generating public/private dsa key pair.Your identification has been saved in /usr/local/var/lib/lxc/ssh1/rootfs/etc/ssh/ssh_host_dsa_key.Your public key has been saved in /usr/local/var/lib/lxc/ssh1/rootfs/etc/ssh/ssh_host_dsa_key.pub.The key fingerprint is:de:f9:31:bd:ec:7a:d7:4c:9f:e3:0c:ee:97:aa:6b:6d root@atest-guestThe key's randomart image is:+--[ DSA 1024]----+|                 ||                 ||                 ||                 ||        S        ||       . . . .  .||        . o +..o=||           o.E+*=||          .oBBB+.|+-----------------+[root@atest-guest lxc]# lxc-start -n sshd --foregroundlxc-start: conf.c: instantiate_veth: 2855 failed to attach 'vethPVKSIK' to the bridge 'lxcbr0': Operation not permittedlxc-start: conf.c: lxc_create_network: 3138 failed to create netdevlxc-start: start.c: lxc_spawn: 829 failed to create the networklxc-start: start.c: __lxc_start: 1088 failed to spawn 'sshd'lxc-start: lxc_start.c: main: 345 The container failed to start.lxc-start: lxc_start.c: main: 349 Additional information can be obtained by setting the --logfile and --logpriority options.[root@atest-guest lxc]# brctl showbridge namebridge idSTP enabledinterfaces[root@atest-guest lxc]# brctl addbr lxcbr0[root@atest-guest linux_btrfs]# brctl showbridge namebridge idSTP enabledinterfaceslxcbr08000.000000000000no

(3). Error about capabilities.

[root@atest-guest lxc]# lxc-start -n sshd --foregroundlxc-start: conf.c: setup_caps: 2337 unknown capability sys_modulelxc-start: conf.c: lxc_setup: 4172 failed to drop capabilitieslxc-start: start.c: do_start: 688 failed to setup the containerlxc-start: sync.c: __sync_wait: 51 invalid sequence number 1. expected 2lxc-start: start.c: __lxc_start: 1088 failed to spawn 'sshd'lxc-start: lxc_start.c: main: 345 The container failed to start.lxc-start: lxc_start.c: main: 349 Additional information can be obtained by setting the --logfile and --logpriority options.[root@atest-guest lxc]# yum install libcap-devel.x86_64 -y[root@atest-guest lxc]# ./configure ....................Security features: - Apparmor: no - Linux capabilities: yes - seccomp: no - SELinux: no - cgmanager: no..........................[root@atest-guest lxc]# make -j 4[root@atest-guest lxc]# make install[root@atest-guest lxc]# lxc-start -n sshd [root@atest-guest lxc]# echo $?0

0 0