This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
технология_lcx_в_ubuntu [2010/09/01 09:19] val |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Технология LXC в Ubuntu ====== | ||
- | |||
- | ===== Создаем ветку гостевой системы ===== | ||
- | <code> | ||
- | root@hostX:~# apt-get install debootstrap | ||
- | |||
- | root@hostX:~# export D=/opt/lxc/serverX | ||
- | |||
- | root@hostX:~# mkdir -p $D | ||
- | root@hostX:~# cd $D | ||
- | |||
- | root@hostX:/opt/lxc/...# debootstrap --variant=minbase --arch i386 lucid rootfs.ubuntu | ||
- | </code> | ||
- | |||
- | ===== Настраиваем гостевую систему для запуска в контейнере ===== | ||
- | <code> | ||
- | root@hostX:~# chroot ${D}/rootfs.ubuntu /bin/bash | ||
- | |||
- | root@hostX:/# apt-get update | ||
- | root@hostX:/# apt-get install --force-yes -y gpgv | ||
- | root@hostX:/# apt-get update | ||
- | |||
- | root@hostX:/# apt-get -y install language-pack-en | ||
- | root@hostX:/# locale-gen en_US.UTF-8 | ||
- | root@hostX:/# /usr/sbin/update-locale LANG="en_US.UTF-8" LANGUAGE="en_US.UTF-8" LC_ALL="en_US.UTF-8" LC_CTYPE="C" | ||
- | |||
- | root@hostX:/# apt-get install -y vim telnet inetutils-ping ssh rsyslog | ||
- | |||
- | root@hostX:/# cd /etc/init | ||
- | |||
- | root@hostX:/etc/init# rm -f console* control* hwclock* module* mount* network-interface* plymouth* procps* tty{1,2,3,4,5,6}.conf udev* upstart* | ||
- | |||
- | root@hostX:/etc/init# cat rc-sysinit.conf | ||
- | start on startup | ||
- | |||
- | pre-start script | ||
- | rm -f $(find /var/run -name '*pid') | ||
- | route add default gw 172.16.1.254 | ||
- | # /etc/init.d/postfix start | ||
- | end script | ||
- | |||
- | root@hostX:/etc/init# cat ssh.conf | ||
- | ... | ||
- | start on startup | ||
- | ... | ||
- | |||
- | root@hostX:/etc/init# cat rsyslog.conf | ||
- | ... | ||
- | start on startup | ||
- | ... | ||
- | |||
- | root@hostX:/# cat /etc/hostname | ||
- | serverX.class.un | ||
- | |||
- | root@hostX:/# cat /etc/hosts | ||
- | ... | ||
- | 172.16.1.100+X serverX.class.un | ||
- | |||
- | root@hostX:/# passwd | ||
- | |||
- | root@hostX:/# exit | ||
- | </code> | ||
- | |||
- | ===== Подготовка сети для гостевых систем ===== | ||
- | <code> | ||
- | root@hostX:~# apt-get install bridge-utils | ||
- | |||
- | root@hostX:~# ifdown eth0 | ||
- | |||
- | root@hostX:~# cat /etc/network/interfaces | ||
- | </code><code> | ||
- | auto lo | ||
- | iface lo inet loopback | ||
- | |||
- | #auto eth0 | ||
- | #iface eth0 inet static | ||
- | # address 172.16.1.X | ||
- | # netmask 255.255.255.0 | ||
- | # gateway 172.16.1.254 | ||
- | |||
- | auto br0 | ||
- | iface br0 inet static | ||
- | address 172.16.1.X | ||
- | netmask 255.255.255.0 | ||
- | bridge_ports eth0 | ||
- | bridge_stp off | ||
- | bridge_maxwait 5 | ||
- | post-up /usr/sbin/brctl setfd br0 0 | ||
- | gateway 172.16.1.254 | ||
- | </code><code> | ||
- | root@hostX:~# ifup br0 | ||
- | </code> | ||
- | |||
- | ===== Установка lxc и настройка хост системы ===== | ||
- | <code> | ||
- | root@hostX:~# apt-get install lxc | ||
- | |||
- | root@hostX:~# mkdir /cgroup | ||
- | |||
- | root@hostX:~# cat /etc/fstab | ||
- | ... | ||
- | none /cgroup cgroup defaults 0 0 | ||
- | |||
- | root@hostX:~# mount /cgroup | ||
- | |||
- | root@hostX:~# mkdir /opt/lxc/lib | ||
- | root@hostX:~# rmdir /var/lib/lxc | ||
- | root@hostX:~# ln -s /opt/lxc/lib/ /var/lib/lxc | ||
- | </code> | ||
- | |||
- | ===== Настройка lxc для запуска гостевой системы в контейнере ===== | ||
- | <code> | ||
- | root@hostX:~# cat /opt/lxc/config.serverX | ||
- | lxc.utsname = serverX | ||
- | lxc.tty = 4 | ||
- | lxc.network.type = veth | ||
- | lxc.network.flags = up | ||
- | lxc.network.link = br0 | ||
- | lxc.network.name = eth0 | ||
- | lxc.network.mtu = 1500 | ||
- | lxc.network.ipv4 = 172.16.1.100+X/24 | ||
- | lxc.rootfs = /opt/lxc/serverX/rootfs.ubuntu | ||
- | lxc.mount = /opt/lxc/fstab.serverX | ||
- | |||
- | root@hostX:~# cat /opt/lxc/fstab.serverX | ||
- | none /opt/lxc/serverX/rootfs.ubuntu/dev/pts devpts defaults 0 0 | ||
- | none /opt/lxc/serverX/rootfs.ubuntu/proc proc defaults 0 0 | ||
- | none /opt/lxc/serverX/rootfs.ubuntu/sys sysfs defaults 0 0 | ||
- | none /opt/lxc/serverX/rootfs.ubuntu/var/lock tmpfs defaults 0 0 | ||
- | none /opt/lxc/serverX/rootfs.ubuntu/var/run tmpfs defaults 0 0 | ||
- | |||
- | root@hostX:~# lxc-create -f /opt/lxc/config.serverX -n serverX | ||
- | |||
- | root@hostX:~# lxc-ls | ||
- | serverX | ||
- | |||
- | root@hostX:~# ls /var/lib/lxc | ||
- | serverX | ||
- | </code> | ||
- | |||
- | ===== Запуск/мониторинг/остановка контейнера ===== | ||
- | <code> | ||
- | root@hostX:~# lxc-start -n serverX /bin/bash | ||
- | |||
- | root@hostX:~# lxc-start -n serverX -d | ||
- | |||
- | root@hostX:~# lxc-info -n serverX | ||
- | 'serverX' is RUNNING | ||
- | |||
- | root@hostX:~# lxc-ps --name serverX | ||
- | |||
- | root@hostX:~# ssh 172.16.1.100+X | ||
- | |||
- | root@hostX:~# lxc-stop -n serverX | ||
- | </code> | ||