竹形誠司 ブログ
OpenSolaris    »トピック一覧
掲示板へのスパムが多いため、「ご質問」のコーナーはユーザー登録制とさせていただきました。お手数ですが、上の「新規ユーザーの登録」メニューより登録をお願いします。
帳票Web
アプリケーション

受注開発始めました
詳しくは こちら
竹形 誠司 著/ラトルズ刊
JSP帳票アプリケーション実践開発入門
JSP帳票アプリケーション
実践開発入門

JSP業務アプリケーション短期開発入門
JSP業務アプリケーション
短期開発入門

Java+MySQL+Tomcatで始めるWebアプリケーション構築入門
Java+MySQL+Tomcatで始めるWebアプリケーション構築入門

Java+MySQL+Tomcatで作る掲示板とブログ
Java+MySQL+Tomcatで作る
掲示板とブログ
Solarisコンテナの作り方
by 竹形 誠司[takegata]
コンテナとかゾーンとか
SunではSolarisの中に仮想OSの環境を作る技術を「Solarisコンテナ」と呼んでいますが、関連の用語がとても分かりにくいので整理しておきます。

「コンテナ」とは、日本語に訳すと「入れ物」です。「入れ物」を作ってその中に「仮想環境を入れる」というのが「Solarisコンテナ」の意味する所です。ではゾーンとは何でしょうか。

Solarisコンテナでは、コンテナの中に作られた仮想環境を「非グローバルゾーン」、コンテナの外側の実環境を「グローバルゾーン」と呼んでいます。「非グローバルゾーン」とはまた回りくどい言い方ですよね。何で「ローカルゾーン」と呼ぶようにしなかったのでしょうかねぇ。

ま、そういうわけで、「コンテナ」の中に作られた仮想環境を「非グローバルゾーン」と呼ぶわけです。ただ、この辺の言葉はわりと曖昧に使われることが多いので、あまり気にしないほうがいいかも知れません。

新たな仮想環境を作る
Solarisコンテナの用語を正しく使って(紛らわしく)書くと「グローバルゾーンの中に新たな非グローバルゾーンを作る」ということになります。仮想環境を作るには、zonecfgコマンドとzoneadmコマンドを使います。zonefcgはゾーンを構成するためのコマンド、zoneadmは構成済みのゾーンを管理するためのコマンドです。手順は次のような感じになります。

zoneadm list -vc で現在のゾーンのリストを確認
zonecfg -z <zonename>で新たなゾーンの構成情報を対話的に入力
zoneadm -z <zonename> install で構成済みのゾーンをインストール
zoneadm -z <zonename> boot でインストール済みのゾーンを起動
zlogin -C <zonename> で起動したゾーンにログイン
rootのパスワードやデフォルトのロケールなどを設定、root以外のユーザを追加
ログアウト
sshで(root以外のユーザで)ログイン

この後は通常のSolarisと同じように使うことができます。ただ、グローバルゾーンと共有するディレクトリは、非グローバルゾーン側から書くことができないので、そこは注意が必要です(/usr/share/lib にterminfoを書き込めないなど、何度かハマりました)。

現在のゾーンのリスト
zoneadm list -vc で現在のゾーンのリストを確認しておきます。listサブコマンドのvオプションはSTATSUやPATHなどの追加情報を表示するためのオプション、cオプションは実行中以外のゾーンも表示するためのオプションです。うちのテスト用サーバはこんな感じです。

# zoneadm list -vc
  ID NAME            STATUS    PATH                            BRAND    IP
  0 global          running    /                                native  shared
  1 node1            running    /export/home/zone/node1      native  shared
  2 node2            running    /export/home/zone/node2      native  shared
  3 node3            running    /export/home/zone/zone3      native  shared
新規ゾーンの作成
新しいゾーンを作成するには、zonecfg コマンドの-zオプションで新しいゾーンの名前を指定します。
# zonecfg -z node4
node4: そのような構成済みゾーンはありません
'create' を使用して、新しいゾーンの構成を開始してください。
対話モードに入り、zonecfgのプロンプトが表示されます。ここで"create"と入力します。
zonecfg:node4> create
問題がなければ何も表示されません。次にsetコマンドでzonepathを指定します。これは、ゾーンを構成するファイルを置くための実環境のパスです。実環境をインストールする際にデフォルトの構成を選んでいる場合は、各ファイルシステムに必要な容量を確保した残りが/export/homeに割り当てられるので、ある程度の容量のディスクを使っている場合は、ここが一番空いていると思います。
zonecfg:node4> set zonepath=/export/home/zone/node4
ネットワークを設定します。仮想環境は実環境の物理インターフェイス(実際のイーサネットポート)を共有しますが、仮想環境ごとに別々のIPアドレスを持ちます。そのための基本的な設定を行います。
zonecfg:node4> add net
zonecfg:node4:net> set physical=bge0
zonecfg:node4:net> set address=192.168.5.9
zonecfg:node4:net> set defrouter=192.168.5.254
zonecfg:node4:net> end
実環境がブートしたときに、仮想環境も自動的にブートするように設定します。
zonecfg:node4> set autoboot=true
以上がzonecfgでの最小限の設定です。infoコマンドで設定内容を確認します。
zonecfg:node4> info
zonename: node4
zonepath: /export/home/zone/node4
brand: native
autoboot: true
bootargs:
pool:
limitpriv:
scheduling-class:
ip-type: shared
inherit-pkg-dir:
        dir: /lib
inherit-pkg-dir:
        dir: /platform
inherit-pkg-dir:
        dir: /sbin
inherit-pkg-dir:
        dir: /usr
net:
        address: 192.168.5.9
        physical: bge0
        defrouter: 192.168.5.254
verifyコマンドを実行します。何か問題があればメッセージが表示されます。問題がなければ何も表示されません。
zonecfg:node4> verify
exitコマンドでzonecfgを終了します。設定内容は自動的に保存されます。
zonecfg:node4> exit
ゾーンの一覧を見てみましょう。設定したゾーンnode4のSTATUSがconfiguredになっています。
# zoneadm list -vc
  ID NAME            STATUS    PATH                          BRAND    IP
  0 global          running    /                              native  shared
  1 node1            running    /export/home/zone/node1        native  shared
  2 node2            running    /export/home/zone/node2        native  shared
  3 node3            running    /export/home/zone/zone3        native  shared
  - node4            configured /export/home/zone/node4        native  shared
ゾーンnode4をインストールします。この処理は少し時間が掛かります(数分)。
# zoneadm -z node4 install
Preparing to install zone <node4>.
Creating list of files to copy from the global zone.
Copying <14309> files to the zone.

Initializing zone product registry.
Determining zone package initialization order.
Preparing to initialize <1359> packages on the zone.
Initializing package <1351> of <1359>: percent complete: 99%
The file </export/home/zone/node4/root/var/sadm/system/logs/install_log> contains a log of the zone installation.
ゾーンの一覧を見てみましょう。ゾーンnode4のSTATUSががconfiguredからinstalledに変わりました。
# zoneadm list -vc
  ID NAME            STATUS    PATH                          BRAND    IP
  0 global          running    /                              native  shared
  1 node1            running    /export/home/zone/node1        native  shared
  2 node2            running    /export/home/zone/node2        native  shared
  3 node3            running    /export/home/zone/zone3        native  shared
  - node4            installed  /export/home/zone/node4        native  shared
ゾーンnode4をブートします。
# zoneadm -z node4 boot
zoneadm: zone 'node4': Unable to set route for interface lo0 to ・      ・
zoneadm: zone 'node4':
zoneadm: zone 'node4':
なにやらエラーメッセージのようなものが表示されましたが、どうでしょう。lo0の設定ができないと言っていますが、lo0はループバック用のアドレスで127.0.0.1が割り当てられるのが普通ですが、これがどうなってしまっているのか、後で調べることにしましょう。ゾーンの一覧を見てみます。
# zoneadm list -vc
  ID NAME            STATUS    PATH                          BRAND    IP
  0 global          running    /                              native  shared
  1 node1            running    /export/home/zone/node1        native  shared
  2 node2            running    /export/home/zone/node2        native  shared
  3 node3            running    /export/home/zone/zone3        native  shared
  4 node4            running    /export/home/zone/node4        native  shared
ゾーンnode4のSTATUSがrunningになっています。とりあえずは起動したようです。ただ、rootのパスワードも設定されていない状態なので、まだsshなどではログインできません。zloginというコマンドを使います。
# zlogin -C node4
[ゾーン 'node4' コンソールに接続しました]
Enterキーを押すと次のようなメッセージが表示されます。
Select a Language

  1. English
  2. Japanese

Please make a choice (1 - 2), or press h or ? for help:2
言語の選択です。2のJapaneseを選びます。
Select a Locale

  1. Japanese EUC (ja)
  2. Japanese EUC (ja_JP.eucJP)
  3. Japanese PC Kanji (ja_JP.PCK)
  4. Japanese UTF-8 (ja_JP.UTF-8)
  5. Go Back to Previous Screen

Please make a choice (1 - 5), or press h or ? for help:4
文字コードの選択です。4のUTF-8を選びます。
どのタイプの端末を使用していますか?
1) ANSI 標準 CRT
2) DEC VT52
3) DEC VT100
4) Heathkit 19
5) Lear Siegler ADM31
6) PC コンソール
7) Sun コマンドツール
8) Sun ワークステーション
9) Televideo 910
10) Televideo 925
11) Wyse Model 50
12) X 端末エミュレータ (xterms)
13) CDE 端末エミュレータ (dtterm)
14) その他
選択する番号を入力して、Return キーを押してください。3
使っている端末を指定します。私はTeraTermをVT100の設定で使っているので、3のVT100を選びます。
- Host Name for bge0:4 --------------------------------------------------------

  Enter the host name which identifies this system on the network.  The name
  must be unique within your domain; creating a duplicate host name will cause
  problems on the network after you install Solaris.

  A host name must have at least one character; it can contain letters,
  digits, and minus signs (-).


    Host name for bge0:4 node4
-------------------------------------------------------------------------------
    F2_Continue    F6_Help
ホスト名を聞いてきます。node4をそのまま使用します。画面の指示では[F2]を押して続けるようになっていますが、TeraTermなどを使っている場合は [Esc-2](エスケープキーを押してから数字の2)で代用します。
- Confirm Information for bge0:4 -----------------------------------------------

  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.


    Host name: node4
--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-4_Change    Esc-6_Help
ホスト名の確認です。[Esc-2]で次へ進みます。
- Configure Security Policy: ---------------------------------------------------

  Specify Yes if the system will use the Kerberos security mechanism.

  Specify No if this system will use standard UNIX security.

      Configure Kerberos Security
      ---------------------------
      [ ] Yes
      [X] No

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
ケルベロスを使うかどうかの選択です。使わないのでそのまま[Esc-2]で次へ進みます。
- Confirm Information ----------------------------------------------------------

  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.


    Configure Kerberos Security: No
--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-4_Change    Esc-6_Help
ケルベロスの設定の確認です。[Esc-2]で次へ進みます。
- Name Service -----------------------------------------------------------------

  On this screen you must provide name service information.  Select the name
  service that will be used by this system, or None if your system will either
  not use a name service at all, or if it will use a name service not listed
  here.

  > To make a selection, use the arrow keys to highlight the option
    and press Return to mark it [X].


      Name service
      ------------
      [ ] NIS+
      [ ] NIS
      [X] DNS
      [ ] LDAP
      [ ] None
--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
ネームサービスの設定です。カーソルをDNSに合わせてスペースキーを押すと、DNSの欄にXが入ります。[Esc-2]で次へ進みます。
- Domain Name ------------------------------------------------------------------

  On this screen you must specify the domain where this system resides.  Make
  sure you enter the name correctly including capitalization and punctuation.


    Domain name: veltec.local

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
ドメイン名を入力します。グローバルIPを振る場合はインターネットのDNSで引けるドメイン名を指定しますが、ここではローカルIPを振るので必ずしもその必要はありません。上の例では"veltec.local"というインターネット上には存在しないドメイン名を指定しています。ローカルのDNSやhostsファイルなどでこのドメイン名を解決できるようにしておかないと、sendmailが「そんなドメインはない」と文句を言ってきますが、とりあえずは捨て置くことにします。
- DNS Server Addresses ---------------------------------------------------------

  On this screen you must enter the IP address of your DNS server(s).  You
  must enter at least one address.  IP addresses must contain four sets of
  numbers separated by periods (for example 129.200.9.1).



    Server's IP address: 192.168.5.254
    Server's IP address:
    Server's IP address:

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
名前解決のために参照するDNSサーバのIPアドレスを指定します。私の家では、ルータがプロバイダのDNSを中継するようにしているので、ルータのIPアドレスを入力します。
- DNS Search List --------------------------------------------------------------

  On this screen you can enter a list of domains that will be searched when a
  DNS query is made.  If you do not enter any domains, DNS will only search
  the DNS domain chosen for this system.  The domains entered, when
  concatenated, may not be longer than 250 characters.



    Search domain:
    Search domain:
    Search domain:
    Search domain:
    Search domain:
    Search domain:
--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
DNSサーチリストの入力画面です。何をどのように入力すればよいのかよく分かりませんが、何も入力しなければ「このシステムのために選ばれたドメインだけを検索する」ということなので、放っておくことにします。おそらくドメイン名を省略してマシン名だけを指定した場合に、自動的にドメイン名を補う機能に関する設定だと思うのですが、(以下略)
- Confirm Information ----------------------------------------------------------

  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.


          Name service: DNS
          Domain name: veltec.local
    Server address(es): 192.168.5.254


--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-4_Change    Esc-6_Help
ネットワーク設定の確認です。間違いが無ければ[Esc-2]で次へ進みます。
- Name Service Error -----------------------------------------------------------

  Unable to find an address entry for node4 with the specified DNS
  configuration.


      Enter new name service information?
      -----------------------------------
      [X] Yes
      [ ] No

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help

node4.veltec.localがDNSで引けないので、「DNSの設定をするか」と聞いてきますが、そもそもDNSが動いていないのでNoにXを入れて[Esc-2]でスルーします。DNSを自分で運用されている方は設定してください。
- NFSv4 Domain Name ------------------------------------------------------------

  NFS version 4 uses a domain name that is automatically derived from the
  system's naming services. The derived domain name is sufficient for most
  configurations. In a few cases, mounts that cross domain boundaries might
  cause files to appear to be owned by "nobody" due to the lack of a common
  domain name.

  The current NFSv4 default domain is: "veltec.local"


      NFSv4 Domain Configuration
      ----------------------------------------------
      [X] Use the NFSv4 domain derived by the system
      [ ] Specify a different NFSv4 domain
--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
NFSでveltec.localというドメインを使うかどうか聞いていますが、そもそもNFSを使う予定がなく、どうでもよいので[Esc-2]で先へ進みます。
- Confirm Information for NFSv4 Domain -----------------------------------------

  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.


    NFSv4 Domain Name:  << Value to be derived dynamically >>

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-4_Change    Esc-6_Help
NFSでveltec.localというドメインを使うがよいか?との確認です。[Esc-2]で次へ。
- Time Zone --------------------------------------------------------------------

  On this screen you must specify your default time zone.  You can specify a
  time zone in three ways:  select one of the continents or oceans from the
  list, select other - offset from GMT, or other - specify time zone file.

  > To make a selection, use the arrow keys to highlight the option and
    press Return to mark it [X].


      Continents and Oceans
      ----------------------------------
  -  [ ] Africa
  x  [ ] Americas
  x  [ ] Antarctica
  x  [ ] Arctic Ocean
  x  [X] Asia
  x  [ ] Atlantic Ocean
  x  [ ] Australia
  x  [ ] Europe
  v  [ ] Indian Ocean

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
タイムゾーンの設定です。AsiaにXを付けて[Esc-2]で次へ。
- Country or Region ------------------------------------------------------------

  > To make a selection, use the arrow keys to highlight the option and
    press Return to mark it [X].


      Countries and Regions
      ------------------------
  ^  [ ] China
  x  [ ] Cyprus
  x  [ ] East Timor
  x  [ ] Georgia
  x  [ ] Hong Kong
  x  [ ] India
  x  [ ] Indonesia
  x  [ ] Iran
  x  [ ] Ira-
  x  [ ] Israel
  x  [X] Japan
  x  [ ] Jordan
  v  [ ] Kazakhstan

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help

アジアの国のリストが表示されます。Japanが出てくるまでカーソルを下に移動してXを入れます。[Esc-2]で次へ。
- Confirm Information ----------------------------------------------------------

  > Confirm the following information.  If it is correct, press F2;
    to change any information, press F4.


    Time zone: Japan

--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-4_Change    Esc-6_Help
タイムゾーンがJapandeよいかの確認です。[Esc-2]で次へ。
- Root Password ----------------------------------------------------------------

  Please enter the root password for this system.

  The root password may contain alphanumeric and special characters.  For
  security, the password will not be displayed on the screen as you type it.

  > If you do not want a root password, leave both entries blank.


    Root password:
    Root password:
--------------------------------------------------------------------------------
    Esc-2_Continue    Esc-6_Help
やっと最後の画面です。rootのパスワードを2回入れて[Esc-2]を押すと、仮想環境のリブートが始まります。
System identification is completed.

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


[NOTICE: Zone rebooting]

SunOS Release 5.11 Version snv_86 64-bit
Copyright 1983-2008 Sun Microsystems, Inc.  All rights reserved.
Use is subject to license terms.
Hostname: node4
Reading ZFS config: done.
May 13 11:04:26 svc.startd[8752]: svc:/system/avahi-bridge-dsd:default: Method "/usr/sbin/avahi-daemon-bridge-dsd -D" failed with exit status 1.
May 13 11:04:26 svc.startd[8752]: svc:/system/avahi-bridge-dsd:default: Method "/usr/sbin/avahi-daemon-bridge-dsd -D" failed with exit status 1.
May 13 11:04:27 svc.startd[8752]: svc:/system/avahi-bridge-dsd:default: Method "/usr/sbin/avahi-daemon-bridge-dsd -D" failed with exit status 1.
May 13 11:04:27 svc.startd[8752]: system/avahi-bridge-dsd:default failed: transitioned to maintenance (see 'svcs -xv' for details)
May 13 11:04:28 node4 sendmail[8984]: My unqualified host name (node4) unknown; sleeping for retry
avahi-daemon-bridge-dsdとかいうのがfailedと言っていますね。後で調べましょう。
node4 console login:
上のようなログインプロンプトがrootでログインします。
node4 console login: root
Password:
May 13 11:05:03 node4 login: ROOT LOGIN /dev/console
Sun Microsystems Inc.  SunOS 5.11      snv_86  January 2008
# May 13 11:05:28 node4 sendmail[8984]: unable to qualify my own domain name (node4) -- using short name
May 13 11:05:28 node4 sendmail[8984]: [ID 702911 mail.alert] unable to qualify my own domain name (node4) -- using short name
May 13 11:05:28 node4 sendmail[9677]: My unqualified host name (node4) unknown; sleeping for retry
May 13 11:05:28 node4 sendmail[9678]: My unqualified host name (node4) unknown; sleeping for retry
May 13 11:06:28 node4 sendmail[9677]: unable to qualify my own domain name (node4) -- using short name
May 13 11:06:28 node4 sendmail[9677]: [ID 702911 mail.alert] unable to qualify my own domain name (node4) -- using short name
May 13 11:06:28 node4 sendmail[9678]: unable to qualify my own domain name (node4) -- using short name
May 13 11:06:28 node4 sendmail[9678]: [ID 702911 mail.alert] unable to qualify my own domain name (node4) -- using short name
sendmailが文句を言っています。はいはい、分かってますって。まずはsshでログインできるように、rootでないユーザを作ります。その前に/exportに/homeが無いので作っておきます。
# mkdir /export/home
ユーザtakegataを作ります。
# useradd -s /usr/bin/bash -m -d /export/home/takegata takegata
64 ブロック
ユーザtakegataのパスワードを設定します。
# passwd takegata
新しいパスワード:
新しいパスワードを再入力してください:
passwd: takegata のパスワードが変更されました
これで一通りの設定は終わりです。exitでログアウトします。
# exit
node4 console login:
~. (チルダ、ドット)と入力するとzloginのコンソールから抜けることができます。新しく作った仮想環境のIPアドレスを指定してTeraTermなどからsshでログインしてみましょう。

あっと、エラーメッセージについて調べるんでしたね。でも、今日はここまで。続きはいずれ。


投稿:竹形 誠司[takegata]/2008年 05月 14日 00時 11分 /更新:2008年 05月 14日 00時 23分