OpenVZをインストールする(2)

前回はホストの構築してみました。
今回はゲストを作成してみます。



ちなみに、OpenVZのマニュアルではホストのことを「Hardware Node」、
ゲストのことを「VE(Virtual Environment)」と呼んでいますので、
これからの説明ではこの用語を使おうと思います。


VEを作成する前に、VEの設定ファイルを編集しておきます。

$ cd /etc/sysconfig/vz-scripts
$ cp ve-light.conf-sample ve-light.conf-sample.org


「ve-light.conf-sample」ファイルの

DISKSPACE="204800:204800"

の部分を

DISKSPACE="409600:409600"

に変更します。


ファイルを編集後、以下のコマンドでVEを作成します。

$ vzctl create 101 --ostemplate centos-4-i386-minimal --config light
Creating VE private area: /vz/private/101
Performing postcreate actions
VE private area was created

上記の例では、VEIDに101を割り当て、OSテンプレートにcentos-4-i386-minimalを使用しています。また、設定ファイルの雛形に
/etc/sysconfig/vz-scripts/ve-light.conf-sampleを使用しています。


特に指定がない場合は、/etc/vz/vz.confに指定してある

CONFIGFILE="vps.basic"
DEF_OSTEMPLATE="fedora-core-4"

が設定ファイルの雛形、OSテンプレートに使用されます。


VEIDとはVE毎に付与される一意の番号のことです。
0から100まではシステムによって予約されていますので、101から使用可能です。
0はハードウェアノードに割り当てられています。


OSテンプレートで指定しているものは、/vz/template/cacheに設置したtar ballから
「tar.gz」を除いたものになります。
tar ballはhttp://openvz.org/download/template/cache/から取得できます。

たとえば、

$ pwd
/vz/template/cache
$ ls
centos-4-i386-default.tar.gz
debian-3.1-i386-minimal.tar.gz
centos-4-i386-minimal.tar.gz
opensuse-10-i386-default.tar.gz

というファイルを設置しているときには、以下のコマンドでそれぞれのVEを作成することができます。

$ vzctl create 101 --ostemplate centos-4-i386-minimal
$ vzctl create 102 --ostemplate debian-3.1-i386-minimal
$ vzctl create 103 --ostemplate centos-4-i386-default
$ vzctl create 104 --ostemplate opensuse-10-i386-default


VEの作成が成功するとデータは/vz/private/101配下に展開されます。

$ cd /vz/private/101/
$ ls
bin boot dev etc home initrd lib media mnt opt proc root sbin selinux srv sys tmp usr var

VEの設定ファイルは、/etc/sysconfig/vz-scriptsに「(VEID).conf」というファイル名で作成されます。

$ cd /etc/sysconfig/vz-scripts/
$ ls
0.conf 101.conf ve-light.conf-sample ve-vps.basic.conf-sample


101.confファイルの中身は以下のようになっています。

# Copyright (C) 2000-2006 SWsoft. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#

VERSION="2"

ONBOOT="no"

# UBC parameters (in form of barrier:limit)
# Primary parameters
AVNUMPROC="15:15"
NUMPROC="40:40"
NUMTCPSOCK="40:40"
NUMOTHERSOCK="40:40"
VMGUARPAGES="1725:9223372036854775807"
# Secondary parameters
KMEMSIZE="1131520:1200742"
TCPSNDBUF="159744:262144"
TCPRCVBUF="159744:262144"
OTHERSOCKBUF="61440:163840"
DGRAMRCVBUF="32768:32768"
OOMGUARPAGES="1725:9223372036854775807"
# Auxiliary parameters
LOCKEDPAGES="4:4"
SHMPAGES="1152:1152"
PRIVVMPAGES="7680:8448"
NUMFILE="512:512"
NUMFLOCK="50:60"
NUMPTY="4:4"
NUMSIGINFO="256:256"
DCACHESIZE="196608:202752"

PHYSPAGES="0:9223372036854775807"
NUMIPTENT="16:16"

# Disk quota parameters (in form of softlimit:hardlimit)
DISKSPACE="409600:409600"
DISKINODES="80000:88000"
QUOTATIME="0"

# CPU fair sheduler parameter
CPUUNITS="250"


パラメータはとりあえずそのままにしておいて、VEを起動させてみます。

$ vzctl start 101
Starting VE ...
VE is mounted
Setting CPU units: 250
VE start in progress...


起動しているかを確認してみます。

$ vzctl status 101
VEID 101 exist mounted running
$ vzlist
VEID NPROC STATUS IP_ADDR HOSTNAME
101 3 running -

起動に成功しているようです。


次回はVEの中の様子を探っていこうと思います。