= LXC - Linux Containers = [[PageOutline]] == 2014-01-11 == * <參考> [http://ofirm.wordpress.com/2014/01/05/creating-a-virtualized-fully-distributed-hadoop-cluster-using-linux-containers/ Creating a virtualized fully-distributed Hadoop cluster using Linux Containers] * 測試環境:Debian Wheezy 7.1 netinstall ISO with [http://github.com/jazzwang/preseed preseed] {{{ jazz@debian:~$ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 7.3 (wheezy) Release: 7.3 Codename: wheezy }}} * 安裝 LXC {{{ jazz@debian:~$ sudo apt-get install lxc }}} * 產生虛擬機器 {{{ jazz@debian:~$ sudo lxc-create -t debian -n test1 jazz@debian:~$ sudo lxc-start -d -n test1 }}} * 安裝 LXC Web Panel {{{ root@debian:~# wget http://lxc-webpanel.github.io/tools/install.sh -O - | bash }}} * <狀況> 指令可以建立 LXC VM, 但網頁似乎不太靈光。 == 2014-01-12 == * 測試環境:Ubuntu 12.04 LTS {{{ jazz@jazzbook:~$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.2 LTS Release: 12.04 Codename: precise }}} * 感覺上 LXC 1.0 的功能比較齊全(Ex. 支援根據 DNS 分配 IP 的機制),因此直接採用 precise-backports 套件庫中的 lxc 1.0 版本 {{{ echo "deb http://free.nchc.org.tw/ubuntu precise-backports main universe" > /tmp/precise-backport.list sudo mv /tmp/precise-backport.list /etc/apt/sources.list.d/ sudo apt-get update }}} * 安裝 LXC 1.0 版本 {{{ sudo apt-get install lxc }}} {{{ jazz@jazzbook:~$ lxc-version lxc version: 1.0.0.alpha1 }}} * 根據 /etc/default/lxc-net 的說明,可以設定一個檔案,來根據 hostname 決定 IP 分配 {{{ #!sh # Uncomment the next line if you'd like to use a conf-file for the lxcbr0 # dnsmasq. For instance, you can use 'dhcp-host=mail1,10.0.3.100' to have # container 'mail1' always get ip address 10.0.3.100. #LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf }}} {{{ root@jazzbook:~# echo "LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf" >> /etc/default/lxc-net root@jazzbook:~# cat > /etc/lxc/dnsmasq.conf << EOF dhcp-host=hdp11,10.0.1.111 dhcp-host=hdp12,10.0.1.112 dhcp-host=hdp13,10.0.1.113 dhcp-host=hdp14,10.0.1.114 dhcp-host=hdp15,10.0.1.115 dhcp-host=hdp16,10.0.1.116 dhcp-host=hdp17,10.0.1.117 dhcp-host=hdp18,10.0.1.118 dhcp-host=hdp19,10.0.1.119 dhcp-host=hdp21,10.0.1.121 dhcp-host=hdp22,10.0.1.122 dhcp-host=hdp23,10.0.1.123 dhcp-host=hdp24,10.0.1.124 dhcp-host=hdp25,10.0.1.125 dhcp-host=hdp26,10.0.1.126 dhcp-host=hdp27,10.0.1.127 dhcp-host=hdp28,10.0.1.128 dhcp-host=hdp29,10.0.1.129 EOF }}} * 建立 20 個 VM 的主機名稱對應(hostname) {{{ root@jazzbook:~# cat >> /etc/hosts << EOF # for LXC 10.0.1.111 hdp11 10.0.1.112 hdp12 10.0.1.113 hdp13 10.0.1.114 hdp14 10.0.1.115 hdp15 10.0.1.116 hdp16 10.0.1.117 hdp17 10.0.1.118 hdp18 10.0.1.119 hdp19 10.0.1.121 hdp21 10.0.1.122 hdp22 10.0.1.123 hdp23 10.0.1.124 hdp24 10.0.1.125 hdp25 10.0.1.126 hdp26 10.0.1.127 hdp27 10.0.1.128 hdp28 10.0.1.129 hdp29 EOF }}} * 先建立五個 LXC VM 試試看 {{{ root@jazzbook:~# for ((i=11;i<=15;i++)); do lxc-create -t ubuntu -n hdp$i; done Checking cache download in /var/cache/lxc/precise/rootfs-i386 ... Copy /var/cache/lxc/precise/rootfs-i386 to /usr/lib/i386-linux-gnu/lxc ... Copying rootfs to /usr/lib/i386-linux-gnu/lxc ... /bin/bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8) Generating locales... en_US.UTF-8... done Generation complete. Creating SSH2 RSA key; this may take some time ... Creating SSH2 DSA key; this may take some time ... Creating SSH2 ECDSA key; this may take some time ... ## # The default user is 'ubuntu' with password 'ubuntu'! # Use the 'sudo' command to run tasks as root in the container. ## }}} * 從以上訊息可以得知,預設的帳號密碼都是 ubuntu * 啟動 5 個 LXC VM {{{ root@jazzbook:~# for ((i=11;i<=15;i++)); do lxc-start -d -n hdp$i; done }}} * 安裝 LXC Web Panel {{{ jazz@jazzbook:~$ sudo su - root@jazzbook:~# wget http://lxc-webpanel.github.io/tools/install.sh -O - | bash }}}