VPSã§é㶠-ãã®ï¼ï¼ ï¼Ubuntué¯12.04ã«LXCãã¤ã³ã¹ã³ãã¦éç£åä»®æ³ç°å¢ãæ§ç¯ãã Part1ï¼åæå°å ¥ç·¨
çæ§ããã«ã¡ã¯ï¼
ä»æ¥ã¯LXCï¼Linux Containers http://lxc.sourceforge.net/ )ï¼lxc version: 0.7.5ï¼ãUbuntuåã«ä»è¾¼ãã§ã¿ãå®é¨ãè¡ãã¾ãã
åºæ¬çã«ã¯ããã®ãã«ãï¼https://help.ubuntu.com/12.04/serverguide/lxc.html ï¼ãå
å®ãã¦ã¦æ®ã©ããã§äºè¶³ãã¾ãããæ¥æ¬èªã®æ
å ±ãå°ãªãã®ã§ä¸å¿ç§ãè¨é²ãã¨ãã¾ãã
ï¼äºã Ubuntu Weekly Recipe第226åãLXCã§è»½éä»®æ³ç°å¢ã®æ´»ç¨ http://gihyo.jp/admin/serial/01/ubuntu-recipe/0226 ãèªãã§ããã¨ããããï¼
Part1ã¯ã¤ã³ã¹ãã¼ã«âã¨ããããç«ã¡ä¸ããæã¾ã§ã
Part2以éã¯éè¦ã¨æ¸ãæ°ãããã°ï¼LXCå
ã§VPNç°å¢æ§ç¯ã»ãã¡ã¤ã«å
±æé¯æ§ç¯çï¼ã
ãããã¯ã¼ã¯å¨ãããããã®ã§ã¤ãããªVPSã«ä»è¾¼ãã§ãã£ããã¼ããåã«ã¾ãã¯å¿ ããã¼ã«ã«ã®VirtualBoxå ã®ã¯ãªã¼ã³ã§ã¶ã£å£ãã¦ããUbuntu12.04ä»®æ³ç°å¢çã§ååã«å®é¨ãã¦ã¿ã¾ããããå°è¨å®æ¼ãã«ãã£ã¦ãã©ãã£ã¦ãç§ã¯ä¸åé¢ç¥ãããã¾ãããå ¨ã¦èªå·±è²¬ä»»ã§ã
(2012/08/28追è¨ï¼
VirtualBoxã¨LXCãåãæ¯è¦ä¸ã§åæã«åããã¨ãVirtualBoxå ã®OSãèµ·åããã¨ãã«æ¯è¦ä¸¸ãã¨ããªã¼ãºããã®ã§ãã©ã¡ããä¸æ¹ã ãåããã¹ããï¼VirtualBoxå ã§åãã¦ããUbuntuå ã«ä»è¾¼ãã LXCã®èµ·åã¯åé¡ç¡ããæ¯è¦ä¸ã«ä¸¦åã§VirtualBoxã¨LXCãèµ·åãããã¨åç¾ï¼
ããªã¼ãºåç¾ç°å¢ï¼
- VirtualBox4.1.16ã4.1.20
- LXC lxc version: 0.7.5
- æ¯è¦Ubuntu 12.04 64bit (corei3,corei5ãã·ã³ã®å®æ©2å°ã§åç¾ãVT-xãBIOSã§æå¹ãã¤VirtualBoxã§ãæå¹ï¼VTç¡å¹ã§ã®åç¾å®é¨ã¯ã¾ã ï¼)
(2012/08/28追è¨ãããï¼
ï¼ãããã®VPS2G(vps)å
LXCç°å¢å
Ubuntu(vpsvm0)ã«xrdpãå
¥ãã¦vpsvm0ï¼ã®GUIç°å¢ï¼âsshãã³ãã«âvpsâsshãã³ãã«âWin7ãã·ã³ã®ãªã¢ã¼ããã¹ã¯ãããã§GUIãããã£ã¦ãå³ï¼
A:ã¤ã³ã¹ãã¼ã«æé
Ubuntu 12.04ã ã¨è¶ ç°¡åã§æåæãæé ï¼ï¼lxcã®ã¤ã³ã¹ãã¼ã«
root@xut:~# apt-get install lxc ããã±ã¼ã¸ãªã¹ããèªã¿è¾¼ãã§ãã¾ã... å®äº ä¾åé¢ä¿ããªã¼ãä½æãã¦ãã¾ã ç¶æ æ å ±ãèªã¿åã£ã¦ãã¾ã... å®äº 以ä¸ã®ç¹å¥ããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ããã¾ã: bridge-utils cgroup-lite cloud-utils debootstrap euca2ools libapparmor1 libyaml-0-2 python-boto python-m2crypto python-paramiko python-yaml ææ¡ããã±ã¼ã¸: btrfs-tools lvm2 qemu-user-static 以ä¸ã®ããã±ã¼ã¸ãæ°ãã«ã¤ã³ã¹ãã¼ã«ããã¾ã: bridge-utils cgroup-lite cloud-utils debootstrap euca2ools libapparmor1 libyaml-0-2 lxc python-boto python-m2crypto python-paramiko python-yaml ã¢ããã°ã¬ã¼ã: 0 åãæ°è¦ã¤ã³ã¹ãã¼ã«: 12 åãåé¤: 0 åãä¿ç: 0 åã 2,069 kB ã®ã¢ã¼ã«ã¤ããåå¾ããå¿ è¦ãããã¾ãã ãã®æä½å¾ã«è¿½å 㧠13.6 MB ã®ãã£ã¹ã¯å®¹éãæ¶è²»ããã¾ãã ç¶è¡ãã¾ãã [Y/n]? ï¼å¾ç¥ï¼
Yæ¼ãã¦ãºãããã£ã¨ã¤ã³ã¹ã³å®äºã
æé ï¼ï¼isc-dhcp-serverã®ã¤ã³ã¹ãã¼ã«
ã½ãã½ãå¢ããéç£åä»®æ³ç°å¢ãä½ãããã«LXCç°å¢ç¨ã®dhcpãµã¼ãã¼ãç«ã¦ã¾ãã
root@xut:~# apt-get install isc-dhcp-server ããã±ã¼ã¸ãªã¹ããèªã¿è¾¼ãã§ãã¾ã... å®äº ä¾åé¢ä¿ããªã¼ãä½æãã¦ãã¾ã ç¶æ æ å ±ãèªã¿åã£ã¦ãã¾ã... å®äº ææ¡ããã±ã¼ã¸: isc-dhcp-server-ldap 以ä¸ã®ããã±ã¼ã¸ãæ°ãã«ã¤ã³ã¹ãã¼ã«ããã¾ã: isc-dhcp-server ã¢ããã°ã¬ã¼ã: 0 åãæ°è¦ã¤ã³ã¹ãã¼ã«: 1 åãåé¤: 0 åãä¿ç: 0 åã 429 kB ã®ã¢ã¼ã«ã¤ããåå¾ããå¿ è¦ãããã¾ãã ãã®æä½å¾ã«è¿½å 㧠1,005 kB ã®ãã£ã¹ã¯å®¹éãæ¶è²»ããã¾ãã åå¾:1 http://ftp.riken.jp/Linux/ubuntu/ precise-updates/main isc-dhcp-server amd64 4.1.ESV-R4-0ubuntu5.2 [429 kB] 429 kB ã 0ç§ ã§åå¾ãã¾ãã (701 kB/s) ããã±ã¼ã¸ãäºåè¨å®ãã¦ãã¾ã ... Selecting previously unselected package isc-dhcp-server. (ãã¼ã¿ãã¼ã¹ãèªã¿è¾¼ãã§ãã¾ã ... ç¾å¨ 238643 åã®ãã¡ã¤ã«ã¨ãã£ã¬ã¯ããªãã¤ã³ã¹ãã¼ã«ããã¦ãã¾ãã) (.../isc-dhcp-server_4.1.ESV-R4-0ubuntu5.2_amd64.deb ãã) isc-dhcp-server ãå±éãã¦ãã¾ã... man-db ã®ããªã¬ãå¦çãã¦ãã¾ã ... ureadahead ã®ããªã¬ãå¦çãã¦ãã¾ã ... isc-dhcp-server (4.1.ESV-R4-0ubuntu5.2) ãè¨å®ãã¦ãã¾ã ... Generating /etc/default/isc-dhcp-server... isc-dhcp-server start/running, process 13449 isc-dhcp-server6 stop/pre-start, process 13498
ã¤ã³ã¹ãã¼ã«ã¯ä»¥ä¸ï¼ãªãã¦ç°¡åãªãã§ãããã
B:è¨å®ãã¡ã¤ã«æ¢è¨ªï¼å ¨ã¦æ¯è¦å´ï¼
lxcã®è¨å®ãã¡ã¤ã«ã¯ãããã¸ãã«ããã¾ãã1:/etc/lxcä»¥ä¸ ï¼ç¢ºèªã®ã¿ï¼
root@xut:/# tree -F /etc/lxc /etc/lxc âââ auto/ã (èªåèµ·åã³ã³ããæå®ç¨ãã£ã¬ã¯ããªï¼ âââ lxc.conf (lxcå ±éè¨å®ãã¡ã¤ã«ï¼ 1 directory, 1 file
root@xut:/# cat /etc/lxc/lxc.conf lxc.network.type=veth lxc.network.link=lxcbr0 lxc.network.flags=up root@xut:/#
ç¹ã«å¼ãå¿ è¦ãªãã
2:/etc/init/以ä¸ï¼ç¢ºèªã®ã¿ï¼
root@xut:/etc/init# ls|grep lxc lxc-net.conf ï¼lxc networkã®èµ·åã¹ã¯ãªããï¼ lxc.conf (lxcã®èµ·åã¹ã¯ãªããï¼ root@xut:/etc/init#
lxc-net.confå ã§ã¯
echo 1 > /proc/sys/net/ipv4/ip_forward
ã ã®
ï¼ä¸ç¥ï¼ # 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 -A POSTROUTING -s ${LXC_NETWORK} -t nat -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} || cleanup touch ${varrun}/network_up ï¼å¾ç¥ï¼
ã ã®iptableså¨ãã®è¨å®ãå ¨é¨ãä»»ãã§ãã£ã¦ããã¦ã¾ããç¹ã«å¼ãå¿ è¦ãªãã
ããLXCã³ã³ããï¼192.168.40.50 portçªå·10222ï¼ã«ç´æ¥ã°ãã¼ãã«IPã¢ãã¬ã¹ããæ¥ç¶ãããæã«ã¯
iptables -A PREROUTING -t nat -p tcp --dport 10222 -i eth0 -j DNAT --to 192.168.40.50:10222
çãä¸è¨ iptables -A POSTROUTING è¡ã®æ¬¡ãããã«ã¨ãããã追è¨ãã¦ï¼ï¼ ufw allow 10222 ãæ¯è¦ã»LXCã³ã³ããåæ¹ã§å®è¡ï¼ãã¾ãã°è¯ãã§ããããï¼192.168.40.50ã®LXCã³ã³ããã®sshã®ãã¼ãã10222çªã«ãã¦ããå ´åçï¼
3:/etc/default/lxc ï¼å¿
è¦ã«å¿ãã¦è¦ç·¨éï¼
LXCã®ãããã¯ã¼ã¯(ããªãã¸æ¥ç¶ï¼å¨ãã®è¨å®ãã¡ã¤ã«ã§ãã
root@xut:/etc/default# cat 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/lxc.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 LXC_BRIDGE="lxcbr0" LXC_ADDR="192.168.40.1" LXC_NETMASK="255.255.255.0" LXC_NETWORK="192.168.40.0/24" LXC_DHCP_RANGE="192.168.40.2,192.168.40.254" LXC_DHCP_MAX="253" LXC_SHUTDOWN_TIMEOUT=120 root@xut:/etc/default#
ç¹ã«å¼ãå¿
è¦ãªããï¼âã®ä¾ã§ã¯LXC_ADDRå¨ããå¼ã£ã¦ã¾ããï¼
ï¼lxcbr0ã§ããªãã¸æ¥ç¶ãããããªãå ´åã¨ããLXC_ADDRãå¤ãããå ´åã«ç·¨éï¼
4:/etc/default/ufw ï¼å¿
è¦ã«å¿ãã¦è¦ç·¨éï¼
ã©ã¤ããªUbuntu使ããªã ufwï¼Ubuntuã®ã½ããã¦ã§ã¢ãã¡ã¤ã¢ã¦ã©ã¼ã«ï¼ã使ã£ã¦iptalbesã®è¨å®ããã¦ããçã§ããufwãæå¹ãªå ´åã¯
DEFAULT_FORWARD_POLICY="ACCEPT"
ã«ããå¿ è¦ãããã¾ããï¼ãã®è¨å®ãå¿ããã¨LXC_NETWORKã®å¤ã«åºããªãï¼
# /etc/default/ufw # ï¼ä¸ç¥ï¼ # Set the default forward policy to ACCEPT, DROP or REJECT. Please note that # if you change this you will most likely want to adjust your rules #DEFAULT_FORWARD_POLICY="DROP" DEFAULT_FORWARD_POLICY="ACCEPT" ï¼å¾ç¥ï¼
ï¼è¨å®ããªããããè¦ service ufw restartï¼
5:/etc/dhcp/dhcpd.confï¼è¦ç·¨éï¼
LXC_NETWORKç¨ã®DHCPé¯ã®è¨å®ã¯ã ããããããªæããï¼ããã§ã¯192.168.40.50ã192.168.40.120 ãå²ãå½ã¦ã¦ããï¼
ddns-update-style none; option domain-name "lxc.local"; option domain-name-servers 192.168.40.1; default-lease-time 600; max-lease-time 7200; authoritative; log-facility local7; subnet 192.168.40.0 netmask 255.255.255.0 { option routers 192.168.40.1; option subnet-mask 255.255.255.0; option broadcast-address 192.168.40.255; option domain-name lxc; option domain-name-servers 192.168.40.1; range dynamic-bootp 192.168.40.50 192.168.40.120; default-lease-time 7200; max-lease-time 43200; }
6: /etc/default/isc-dhcp-serverï¼è¦ç·¨éï¼
root@xut:~# cat /etc/default/isc-dhcp-server # Defaults for dhcp initscript # sourced by /etc/init.d/dhcp # installed at /etc/default/isc-dhcp-server by the maintainer scripts # # This is a POSIX shell fragment # # On what interfaces should the DHCP server (dhcpd) serve DHCP requests? # Separate multiple interfaces with spaces, e.g. "eth0 eth1". #INTERFACES="" INTERFACES="lxcbr0"
INTERFACES="lxcbr0"ã«éå®ãã¦ããã¾ãããã
ï¼è¨å®ããªããããè¦ service isc-dhcp-server restartï¼
7: /etc/dnsmasq.d/lxcï¼ç¢ºèªã®ã¿ï¼
root@xut:~# cat /etc/dnsmasq.d/lxc bind-interfaces except-interface=lxcbr0 root@xut:~#
C:LXCã³ã³ããï¼ä»®æ³ç°å¢ï¼ä½ææé
ã³ãã³ãä¸çºæµãã¦ãã¨ã¯è¦ã¦ãã ããï¼ååã®ã¿OSã«å¿ è¦ãªããã±ã¼ã¸ã®ãã¦ã³ãã¼ãã«åæ°åç¨åº¦æéããããã¾ãã2åç®ä»¥éã¯çéãï¼(ubuntuã®ææ°ç12.04ç°å¢ã vm0ã¨ããååã§ä½æãã¦ããä¾ï¼
root@xut:~# lxc-create -t ubuntu -n vm0 No config file specified, using the default config debootstrap 㯠/usr/sbin/debootstrap ã§ã Checking cache download in /var/cache/lxc/precise/rootfs-amd64 ... installing packages: vim,ssh Downloading ubuntu precise minimal ... I: Retrieving Release I: Retrieving Release.gpg I: Checking Release signature I: Valid Release signature (key id 630239CC130E1A7FD81A27B140976EAF437D05B5) I: Retrieving Packages I: Validating Packages I: Retrieving Packages I: Validating Packages I: Resolving dependencies of required packages... I: Resolving dependencies of base packages... I: Found additional base dependencies: libbsd0 libedit2 libgpm2 libgssapi-krb5-2 libk5crypto3 libkeyutils1 libkrb5-3 libkrb5support0 libpython2.7 libwrap0 openssh-client openssh-serv er vim-runtime I: Checking component main on http://archive.ubuntu.com/ubuntu... I: Retrieving adduser I: Validating adduser ï¼ä¸ç¥ï¼ Processing triggers for resolvconf ... locale: Cannot set LC_CTYPE to default locale: No such file or directory locale: Cannot set LC_MESSAGES to default locale: No such file or directory locale: Cannot set LC_ALL to default locale: No such file or directory invoke-rc.d: policy-rc.d denied execution of start. Processing triggers for initramfs-tools ... Download complete Copy /var/cache/lxc/precise/rootfs-amd64 to /var/lib/lxc/vm0/rootfs ... Copying rootfs to /var/lib/lxc/vm0/rootfs ... ## # The default user is 'ubuntu' with password 'ubuntu'! # Use the 'sudo' command to run tasks as root in the container. ## 'ubuntu' template installed 'vm0' created root@xut:~#
ã¤ã³ã¹ãã¼ã«ãçµäºãã㨠/var/lib/lxc/vm0ï¼vm0ï¼ä»»æã®ä»®æ³ç°å¢åã»ã³ã³ããåï¼ ä»¥ä¸ã«ãããªæãã§ä»®æ³ç°å¢ã®ãã¡ã¤ã«ç¾¤ãä½æããã¾ãã
root@xut:/var/lib/lxc/vm0# ll åè¨ 20 drwxr-xr-x 3 root root 4096 7æ 31 22:52 ./ drwxr-xr-x 3 root root 4096 7æ 31 22:41 ../ -rw-r--r-- 1 root root 1249 7æ 31 22:52 config ï¼vm0ã®è¨å®ãã¡ã¤ã«ï¼ -rw-r--r-- 1 root root 110 7æ 31 22:52 fstab drwxr-xr-x 22 root root 4096 7æ 31 22:51 rootfs/ ï¼vm0ã®ã«ã¼ããã£ã¬ã¯ããªï¼ root@xut:/var/lib/lxc/vm0# find ./ -maxdepth 2 ./ ./fstab ./rootfs ./rootfs/opt ./rootfs/tmp ./rootfs/lib ./rootfs/proc ./rootfs/bin ./rootfs/sys ./rootfs/root ./rootfs/var ./rootfs/srv ./rootfs/home ./rootfs/sbin ./rootfs/lib64 ./rootfs/media ./rootfs/selinux ./rootfs/run ./rootfs/dev ./rootfs/boot ./rootfs/mnt ./rootfs/etc ./rootfs/usr ./config root@xut:/var/lib/lxc/vm0#
/var/lib/lxc/vm0/configã§vm0åºæã®è¨å®ãè¨è¿°ãã¾ããï¼é常ã¯ç¹ã«ç·¨éã®å¿ è¦ãªãï¼
root@xut:/var/lib/lxc/vm0# cat config lxc.network.type=veth lxc.network.link=lxcbr0 lxc.network.flags=up lxc.network.hwaddr = 00:16:3e:e5:9f:2e lxc.utsname = vm0 lxc.devttydir = lxc lxc.tty = 4 lxc.pts = 1024 lxc.rootfs = /var/lib/lxc/vm0/rootfs lxc.mount = /var/lib/lxc/vm0/fstab lxc.arch = amd64 lxc.cap.drop = sys_module mac_admin lxc.pivotdir = lxc_putold # uncomment the next line to run the container unconfined: #lxc.aa_profile = unconfined lxc.cgroup.devices.deny = a # Allow any mknod (but not using the node) lxc.cgroup.devices.allow = c *:* m lxc.cgroup.devices.allow = b *:* m # /dev/null and zero lxc.cgroup.devices.allow = c 1:3 rwm lxc.cgroup.devices.allow = c 1:5 rwm # consoles lxc.cgroup.devices.allow = c 5:1 rwm lxc.cgroup.devices.allow = c 5:0 rwm #lxc.cgroup.devices.allow = c 4:0 rwm #lxc.cgroup.devices.allow = c 4:1 rwm # /dev/{,u}random lxc.cgroup.devices.allow = c 1:9 rwm lxc.cgroup.devices.allow = c 1:8 rwm lxc.cgroup.devices.allow = c 136:* rwm lxc.cgroup.devices.allow = c 5:2 rwm # rtc lxc.cgroup.devices.allow = c 254:0 rwm #fuse lxc.cgroup.devices.allow = c 10:229 rwm #tun lxc.cgroup.devices.allow = c 10:200 rwm #full lxc.cgroup.devices.allow = c 1:7 rwm #hpet lxc.cgroup.devices.allow = c 10:228 rwm #kvm lxc.cgroup.devices.allow = c 10:232 rwm root@xut:/var/lib/lxc/vm0#
D:LXCã³ã³ããèµ·å確èª
ã³ã³ã§ä¸æ¦æ¯è¦ï¼è¦ªæ©ï¼èªä½ããªãã¼ããã¾ããããï¼ãªãã¼ãç´å¾ã«æ¯è¦ã§ifconfig -aãã¦ã¿ãå³ï¼
root@xut:~# ifconfig -a eth0 Link encap:ã¤ã¼ãµããã ãã¼ãã¦ã§ã¢ã¢ãã¬ã¹ 08:00:27:fa:a8:39 inetã¢ãã¬ã¹:192.168.25.40 ããã¼ããã£ã¹ã:192.168.25.255 ãã¹ã¯:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 ã¡ããªãã¯:1 RXãã±ãã:317 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:422 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:1000 RXãã¤ã:27923 (27.9 KB) TXãã¤ã:149231 (149.2 KB) lo Link encap:ãã¼ã«ã«ã«ã¼ããã㯠inetã¢ãã¬ã¹:127.0.0.1 ãã¹ã¯:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 ã¡ããªãã¯:1 RXãã±ãã:2 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:2 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:0 RXãã¤ã:100 (100.0 B) TXãã¤ã:100 (100.0 B) lxcbr0 Link encap:ã¤ã¼ãµããã ãã¼ãã¦ã§ã¢ã¢ãã¬ã¹ 7a:33:e0:87:e5:0e inetã¢ãã¬ã¹:192.168.40.1 ããã¼ããã£ã¹ã:192.168.40.255 ãã¹ã¯:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 ã¡ããªãã¯:1 RXãã±ãã:0 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:2 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:0 RXãã¤ã:0 (0.0 B) TXãã¤ã:108 (108.0 B) root@xut:~#
lxcbr0ãæ°ãã«åºæ¥ã¦ãã¾ããï¼/etc/default/lxcãç·¨éããã®ã§ããã®ä¾ã§ã¯inetã¢ãã¬ã¹:192.168.40.1 ã«ãªã£ã¦ãããæ¯è¦ã®eth0ã¯192.168.25.40ï¼
ã¤ã³ã¹ã³ããvm0ãèµ·åãã¦ã¿ã¾ãã
èµ·åã¯
lxc-start -n vm0
ã¾ãã¯
lxc-start -n vm0 -d
ããå¾ã§
lxc-console -n vm0
ã·ã£ãããã¦ã³ã¯
lxc-shutdown -n vm0
å¼·å¶åæ¢ã¯
lxc-stop -n vm0
ã§ãã
ï¼èµ·åããå³ï¼
ï¼vm0ç°å¢ã§ã®ifconfig -aï¼
root@vm0:~# ifconfig -a eth0 Link encap:Ethernet HWaddr 00:16:3e:e5:9f:2e inet addr:192.168.40.50 Bcast:192.168.40.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:17 errors:0 dropped:0 overruns:0 frame:0 TX packets:11 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1594 (1.5 KB) TX bytes:1338 (1.3 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) root@vm0:~# route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.40.1 0.0.0.0 UG 100 0 0 eth0 192.168.40.0 * 255.255.255.0 U 0 0 0 eth0 root@vm0:~#
dhcpã§ã¡ããã¨192.168.40.50ãå²ãå½ã¦ãããããã§ãã
(vm0ãèµ·åããå¾ã§ã®æ¯è¦å´ã®ifconfig -a)
root@xut:/home/xut# ifconfig -a eth0 Link encap:ã¤ã¼ãµããã ãã¼ãã¦ã§ã¢ã¢ãã¬ã¹ 08:00:27:fa:a8:39 inetã¢ãã¬ã¹:192.168.25.40 ããã¼ããã£ã¹ã:192.168.25.255 ãã¹ã¯:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 ã¡ããªãã¯:1 RXãã±ãã:14750 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:7298 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:1000 RXãã¤ã:16875022 (16.8 MB) TXãã¤ã:2053244 (2.0 MB) lo Link encap:ãã¼ã«ã«ã«ã¼ããã㯠inetã¢ãã¬ã¹:127.0.0.1 ãã¹ã¯:255.0.0.0 UP LOOPBACK RUNNING MTU:16436 ã¡ããªãã¯:1 RXãã±ãã:2 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:2 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:0 RXãã¤ã:100 (100.0 B) TXãã¤ã:100 (100.0 B) lxcbr0 Link encap:ã¤ã¼ãµããã ãã¼ãã¦ã§ã¢ã¢ãã¬ã¹ 3a:9f:33:53:15:e1 inetã¢ãã¬ã¹:192.168.40.1 ããã¼ããã£ã¹ã:192.168.40.255 ãã¹ã¯:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 ã¡ããªãã¯:1 RXãã±ãã:3144 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:11494 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:0 RXãã¤ã:160963 (160.9 KB) TXãã¤ã:16614801 (16.6 MB) vethR9OLBE Link encap:ã¤ã¼ãµããã ãã¼ãã¦ã§ã¢ã¢ãã¬ã¹ 3a:9f:33:53:15:e1 UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 ã¡ããªãã¯:1 RXãã±ãã:3144 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã¬ã¼ã :0 TXãã±ãã:11501 ã¨ã©ã¼:0 æ失:0 ãªã¼ãã©ã³:0 ãã£ãªã¢:0 è¡çª(Collisions):0 TXãã¥ã¼é·:1000 RXãã¤ã:204979 (204.9 KB) TXãã¤ã:16615107 (16.6 MB) root@xut:/home/xut#
(注æç¹ï¼
åæã¦ã¼ã¶ã¼å:ubuntuããã¹ã¯ã¼ããubuntuãªã®ã§
å³å¹sudo adduser hogehogekun ã§å¥ã®ä»»æã®ã¦ã¼ã¶ã¼hogehogekunãä½ã£ã¦
/etc/groupã®
sudo:x:27:ubuntuã
sudo:x:27:hogehogekunã«ãã¤ã¤
sudo deluser ubuntuãã¦ãã¾ãã¾ãããã
ãã¨ã¯apt-get install ufw;ufw enable ããå¾ã§å¥½ãã«å¼ãåãã¹ãã
lxc-*ã³ãã³ãã®ä¸è¦§ã¯
https://help.ubuntu.com/12.04/serverguide/lxc.html#lxc-admin ãããã«æ¸ãã¦ããã¾ãã®ã§ä¸èªãã¦ã¿ãã°ã¨ãã·
ä»æ¥ã¯ããã¾ã§ãPart2ã«ç¶ãããã
ï¼ãã®åã«ããã¯ã¢ããæé é¢é£ã¨ã³ããªã¼ã®å®çµç·¨ãå
ãâ¦ï¼
ã§ã¯ã§ã¯ï¼