OpenIndianaでSolaris Zone

未だにコンテナ系仮想化を使ったことなかった。。。

FreeBSDかSolarisかと呟いたら、
「Solarisで」というお返事があったので、やってみた。

OpenSolarisじゃなくて
OpenIndianaになってるのね。

Solarisなんてほとんど使ったこと無いので、
いろいろと調べながらやりました。

OS・・・OpenIndiana SunOS 5.11 oi_151a7

さて何も考えずにやってみよー

# zonecfg -z test
Use 'create' to begin configuring a new zone.
zonecfg:test> create
zonecfg:test> set zonepath=/var/zones/test
zonecfg:test> verify
zonecfg:test> commit
zonecfg:test> export
create -b
set zonepath=/export/zones/test
set brand=ipkg
set autoboot=false
set ip-type=shared
zonecfg:test> exit

設定→verify→commit→exitという流れ。

とりあえず・・・
インストールしてみる

# zoneadm -z test install
/var/zone/test must not be group readable.
/var/zone/test must not be group executable.
/var/zone/test must not be world readable.
/var/zone/test must not be world executable.
ERROR: the zonepath must be a ZFS dataset.
The parent directory of the zonepath must be a ZFS dataset so that the
zonepath ZFS dataset can be created properly.

書き込み権限は良いとして、
どうやらZFSデータセットに作らないとダメらしい。
(だけど、/export/zonesでもダメだった。。。うーん?)

zfsデータセットを作ろう

# zpool list
NAME    SIZE  ALLOC   FREE  EXPANDSZ    CAP  DEDUP  HEALTH  ALTROOT
rpool  14.9G  2.37G  12.5G         -    15%  1.00x  ONLINE  -
#
# zfs create rpool/zones
# zfs set mountpoint=/export/zones rpool/zones
# df -h
Filesystem            Size  Used Avail Use% Mounted on
rpool/ROOT/openindiana
                       14G  1.8G   12G  13% /
swap                  818M  432K  818M   1% /etc/svc/volatile
/usr/lib/libc/libc_hwcap1.so.1
                       14G  1.8G   12G  13% /lib/libc.so.1
swap                  818M  4.0K  818M   1% /tmp
swap                  818M   40K  818M   1% /var/run
rpool/export           12G   36K   12G   1% /export
rpool/export/home      12G   31K   12G   1% /export/home
rpool                  12G   52K   12G   1% /rpool
rpool/zones            12G   31K   12G   1% /export/zones

rpoolからzonesってやつを作って(切り出して)
それを「/export/zones」にマウントしただけw

さてーもう一回やってみるー

# zoneadm -z test install
/export/zones must not be group readable.
/export/zones must not be group executable.
/export/zones must not be world readable.
/export/zones must not be world executable.
could not verify zonepath /export/zones because of the above errors.
zoneadm: zone test failed to verify

はいはい、権限直しますよー

# chmod 700 /export/zones
#
# zoneadm -z test install
   Publisher: Using openindiana.org (http://pkg.openindiana.org/dev/ ).
   Publisher: Using opensolaris.org (http://pkg.openindiana.org/legacy/).
       Image: Preparing at /export/zones/root.
       Cache: Using /var/pkg/publisher.
Sanity Check: Looking for 'entire' incorporation.
  Installing: Packages (output follows)
           Packages to install: 132
       Create boot environment:  No
Create backup boot environment:  No
            Services to change:   4

DOWNLOAD                                  PKGS       FILES    XFER (MB)
Completed                              132/132 28252/28252  150.7/150.7

PHASE                                        ACTIONS
Install Phase                            40855/40855 

PHASE                                          ITEMS
Package State Update Phase                   132/132 
Image State Update Phase                         2/2 

        Note: Man pages can be obtained by installing pkg:/system/manual
 Postinstall: Copying SMF seed repository ... done.
 Postinstall: Applying workarounds.
        Done: Installation completed in 1134.158 seconds.

  Next Steps: Boot the zone, then log into the zone console (zlogin -C)
              to complete the configuration process.

入ったっぽい?

起動させてみよう。。。

# zoneadm -z test boot

コンソールから抜ける場合は「~ ^D(チルダ, Ctrl+D)」

# zlogin -C test

[Connected to zone 'test' console]
102/102
Hostname: test
Loading smf(5) service descriptions: 1/1

What type of terminal are you using?
 1) ANSI Standard CRT
 2) DEC VT52
 3) DEC VT100
 4) Heathkit 19
 5) Lear Siegler ADM31
 6) Sun Command Tool
 7) Sun Workstation
 8) Televideo 910
 9) Wyse Model 50
 10) X Terminal Emulator (xterms)
 11) CDE Terminal Emulator (dtterm)
 12) Other
Type the number of your choice and press Return: 10
		・
		・
		・
System identification is completed.

   rebooting system due to change(s) in /etc/default/init


[NOTICE: Zone rebooting]

再起動が勝手にかかる

どうだー

SunOS Release 5.11 Version oi_151a7 64-bit
Copyright (c) 1983, 2010, Oracle and/or its affiliates. All rights reserved.
Hostname: indiana

indiana console login: root
Password: 
Jan 20 19:55:33 indiana login: ROOT LOGIN /dev/console
OpenIndiana (powered by illumos)    SunOS 5.11    oi_151a7    October 2012
root@indiana:~# 

来ましたー
で一旦落としますw

確認してみると

# zoneadm list -vc
  ID NAME             STATUS     PATH                           BRAND    IP    
   0 global           running    /                              ipkg     shared
   - test             installed  /export/zones                  ipkg     shared

きちんとインストールされてるねー

このままでは、
ネットワークが無いので追加してみましょうー

ホスト側で
使っているNICを確認しておきます。

# ifconfig
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
	inet 127.0.0.1 netmask ff000000 
e1000g0: flags=1004843<UP,BROADCAST,RUNNING,MULTICAST,DHCP,IPv4> mtu 1500 index 3
	inet 192.168.1.2 netmask ffffff00 broadcast 192.168.1.255
	ether 0:c:29:2:26:29 
lo0: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1
	inet6 ::1/128 
e1000g0: flags=20002004841<UP,RUNNING,MULTICAST,DHCP,IPv6> mtu 1500 index 3
	inet6 fe80::20c:29ff:fe02:2629/10 
	ether 0:c:29:2:26:29 

この場合は、「e1000g0

物理NICが余ってる場合には
set ip-type=exclusive
物理NICがない場合は
set ip-type=shared」(デフォルト)
が使えるみたい。
また、exclusiveならDHCPも設定できるっぽいけど、
sharedの場合は、明示的に指定しないと怒られる。

set address=でネットマスクを指定しないと
デフォルトの255.255.255.0使うよ
といわれる。
ついでに自動起動するようにしてみる。

# zonecfg -z test 
zonecfg:test> set autoboot=true
zonecfg:test> add net
zonecfg:test:net> set physical=e1000g0
zonecfg:test:net> set address=192.168.1.3/24
zonecfg:test:net> set defrouter=192.168.1.1
zonecfg:test:net> end
zonecfg:test> verify
zonecfg:test> commit
zonecfg:test> exit
# zoneadm -z test boot

設定を変えて起動させます

ログインしますー

# zlogin -C test
[Connected to zone 'test' console]

indiana console login: root
Password: 
Last login: Sun Jan 20 20:30:37 on console
Jan 20 21:01:01 indiana login: ROOT LOGIN /dev/console
OpenIndiana (powered by illumos)    SunOS 5.11    oi_151a7    October 2012
root@indiana:~# 
root@indiana:~# ifconfig 
lo0:1: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000 
e1000g0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        inet 192.168.1.3 netmask ffffff00 broadcast 192.168.1.255
lo0:1: flags=2002000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv6,VIRTUAL> mtu 8252 index 1
        inet6 ::1/128 

IPアドレスとNICがきちんと認識されています。

このままでは、名前解決出来ないので、以下2ファイルを編集。

root@indiana:~# vi /etc/resolv.conf
nameserver 8.8.8.8
root@indiana:~#

root@indiana:~# vi /etc/nsswitch.conf
hosts: files dns

root@indiana:~# nslookup oracle.com  
Server:         8.8.8.8
Address:        8.8.8.8#53

Non-authoritative answer:
Name:   oracle.com
Address: 137.254.16.101

これでネットワークが使えるようになりました!!

あとは、

zonecfg:test> add capped-memory
zonecfg:test:capped-memory> set physical=200m
zonecfg:test:capped-memory> set swap=300m

なんかでメモリリソース制限してみたり。

参考URL
http://wiki.openindiana.org/oi/Zones
http://docs.oracle.com/cd/E19253-01/819-0385/zones.intro-1/index.html
http://otn.oracle.co.jp/technology/global/jp/sdn/solaris/solaris10/update/update4.html
http://solaris.sunfish.suginami.tokyo.jp/wiki/index.php?title=Zones

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

Enter code * Time limit is exhausted. Please reload CAPTCHA.

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください