既存のOpenVZテンプレートのファイルをアップデートする


OpenVZで作成されたテンプレートを更新する。

参考: OpenVZ wiki: Updating Debian template

1. OpenVZの仮想ホストを作成

# vzctl create VID番号 --ostemplate テンプレート名

上記のテンプレート名は/var/lib/vz/template/cache/ にあるtar.gzファイルの名前を使用する。

実行例

# vzctl create 555 --ostemplate scientific-6-standard_6.0_i386
Creating container private area (scientific-6-standard_6.0_i386)
Performing postcreate actions
Saved parameters for CT 555
Container private area was created
#

2014/11/27 追記

/etc/vz/vz.confの設定によっては下記の様に、パラメータが足らないというエラーがでます。

# vzctl create 555 --ostemplate centos-6-standard_6.0-20121116_i386
Creating container private area (centos-6-standard_6.0-20121116_i386)
Initializing quota ...
Error: Not enough parameters, diskspace quota not set
Creation of container private area failed
#

/etc/vz/vz.confに下記のようにDISKSPACE設定とDISKINODES設定を追加することで、回避できます。

DISKSPACE="20G:22G"
DISKINODES="4000000:4400000"

(バージョンによってはvzctl createオプションでdiskspaceは指定できても、diskinodesが指定できない

2014/11/27 追記終


2. 仮想ホストにIPアドレスとDNSサーバを指定する

# vzctl set VID番号 --ipadd IPアドレス --nameserver DNSサーバIP --save

実行例

# vzctl set 555 --ipadd 192.168.x.x --nameserver 192.168.x.x --save
Saved parameters for CT 555
#

3. 仮想マシンを稼働させる

# vzctl start 555
Starting container ...
Container is mounted
Adding IP address(es): 192.168.35.240
Setting CPU units: 1000
File resolv.conf was modified
Container start in progress...
#

2014/11/27 追記

バージョンによっては、以下のようなエラーとなる場合がある。

# vzctl start 555
Error: required UB parameter kmemsize not set
Error: required UB parameter lockedpages not set
Error: required UB parameter privvmpages not set
Error: required UB parameter shmpages not set
Error: required UB parameter numproc not set
Error: required UB parameter physpages not set
Error: required UB parameter vmguarpages not set
Error: required UB parameter oomguarpages not set
Error: required UB parameter numtcpsock not set
Error: required UB parameter numflock not set
Error: required UB parameter numpty not set
Error: required UB parameter numsiginfo not set
Error: required UB parameter tcpsndbuf not set
Error: required UB parameter tcprcvbuf not set
Error: required UB parameter othersockbuf not set
Error: required UB parameter dgramrcvbuf not set
Error: required UB parameter numothersock not set
Error: required UB parameter numfile not set
Error: required UB parameter dcachesize not set
Error: required UB parameter numiptent not set
#

この場合は、/etc/vz/conf/に作成されている該当CIDの.confファイルに下記のエントリーを追記しておくといい。

PHYSPAGES="0:1024M"
SWAPPAGES="0:512M"
KMEMSIZE="465M:512M"
DCACHESIZE="232M:256M"
LOCKEDPAGES="512M"
PRIVVMPAGES="unlimited"
SHMPAGES="unlimited"
NUMPROC="unlimited"
VMGUARPAGES="0:unlimited"
OOMGUARPAGES="0:unlimited"
NUMTCPSOCK="unlimited"
NUMFLOCK="unlimited"
NUMPTY="unlimited"
NUMSIGINFO="unlimited"
TCPSNDBUF="unlimited"
TCPRCVBUF="unlimited"
OTHERSOCKBUF="unlimited"
DGRAMRCVBUF="unlimited"
NUMOTHERSOCK="unlimited"
NUMFILE="unlimited"
NUMIPTENT="unlimited"

2014/11/27 追記終


4. 仮想マシンにログインする

# vzctl enter 555
entered into CT 555
[root@ホスト名 /]#

5. yum updateを実施

# yum update
sl                                                       | 3.2 kB     00:00
sl/primary_db                                            | 3.1 MB     00:12
sl-security                                              | 1.9 kB     00:00
sl-security/primary_db                                   | 5.8 MB     00:12
Setting up Update Process
Resolving Dependencies
<略>
Transaction Summary
================================================================================
Install       0 Package(s)
Upgrade      32 Package(s)

Total download size: 46 M
Is this ok [y/N]: y
Downloading Packages:
<略>
  tzdata.noarch 0:2011h-3.el6

Complete!
[root@ns5 /]#

6. 追加したい設定があったらやっとく
・phpをインストール
・/etc/php.iniに「date.timezone = Asia/Tokyo」の設定を追加
・「ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime」
・/etc/sysconfig/i18nに「LANG=”ja_JP.UTF-8″」を追加

7. 掃除

# yum clean all
Cleaning up Everything
# echo > /etc/resolv.conf
#

8. 仮想ホストの停止

# vzctl stop 555
Stopping container ...
Container was stopped
Container is unmounted
#

9. 仮想ホストからIPアドレス設定を削除

# vzctl set 555 --ipdel all --save
Saved parameters for CT 555
#

10. 仮想ホストのファイルが展開されている場所に移動

# cd /var/lib/vz/private/555
#

11. テンプレートとしてtar.gzファイルを作成

#  tar --numeric-owner -czf /var/lib/vz/template/cache/scientific-6-standard_6.0-20111026_i386.tar.gz .
#

なお、ファイル名は重要。

「ディストリビューション名」-「ディストリビューションのバージョン」-「カスタマイズ説明」_「カスタマイズのバージョン」_「アーキテクチャ」.tar.gz

という書式で指定する。
そうしないと、Proxmoxでは、テンプレートとして指定できない。

12. 使用した仮想マシンの削除

# vzctl destroy 555
Destroying container private area: /var/lib/vz/private/555
Container private area was destroyed
#

13. /etc/vz/conf/に残る仮想マシンの設定ファイルを削除

# rm /etc/vz/conf/555.conf.destroyed
#

Proxmox上のOpenVZ仮想マシンのバックアップ


Proxmox VEにはOpenVZ仮想マシンのバックアップを容易に取れるように、専用ツールvzdumpが用意されている。
このvzdumpは、OpenVZのwikiにも掲載されているぐらいの便利ツールのようです。

vzdumpでバックアップを行うと、各仮想マシンごとにtarファイルができあがります。

さて、このバックアップファイルを、Proxmoxサーバ内部に残しておくとバックアップの意味がないので、外部サーバに転送しましょう。
NFSでマウントした先にコピーというのが一番簡単なやりかたですが、安いNASだとNFSに対応していない場合があります。

まぁ、具体的にはLinkStationをバックアップ先にしたいです。
この場合、CIFS、ftp、そして、rsync(LinkStationは「バックアップ」と呼ばれている)で転送することができますが、無難なあたりでftpで転送する、とします。

そんなスクリプトを作りました

仕様
・ftpサーバに指定ユーザ・パスワードでログインする
・バックアップは10世代保存とする。
・起動中の仮想マシンのみバックアップする
・Proxmoxサーバ内にバックアップイメージを作成するが、容量が少なく済むように1個ずつ実施する
・lftpを使ってアップロードするので、「aptitude install lftp」でインストールしておく

#!/bin/bash
# vzdump and ftp upload script
#
DUMPDIR="/work"
UPLOADDIR="/disk1/backup/dump"

FTPHOST="IPアドレス"
FTPUSER="ユーザ名"
FTPPASSWORD="パスワード"

cd $DUMPDIR
vzlist > vzlist.log

# create upload directory
lftp -c "open -u $FTPUSER,$FTPPASSWORD $FTPHOST
mkdir $UPLOADDIR/transfer"


# dump and upload virtual machine
# "vzlist -1" : dump active VM only
# "vzlist -a -1": dump all VM
# "vzlist -S -1": dump standby VM only
for hostid in `vzlist -1`
do
	echo $hostid;
	cd $DUMPDIR
	vzdump --dumpdir $DUMPDIR $hostid
	lftp -c "open -u $FTPUSER,$FTPPASSWORD $FTPHOST
cd $UPLOADDIR/transfer
mput -E *.tar *.log"
done

# lotate
lftp -c "open -u $FTPUSER,$FTPPASSWORD $FTPHOST
cd $UPLOADDIR
rm -r daily.9
mv daily.8 daily.9
mv daily.7 daily.8
mv daily.6 daily.7
mv daily.5 daily.6
mv daily.4 daily.5
mv daily.3 daily.4
mv daily.2 daily.3
mv daily.1 daily.2
mv daily.0 daily.1
mv transfer daily.0"

上記スクリプトは毎日夜間に実行するつもりのものなので、NetAppライクに「daily.数字」という感じでディレクトリを作成しています。

Proxmox Virtual EnvironmentでOpenVZのテンプレートが出てこない


Proxmox Virtual Environment(PVE) 1.7を使用中。

PVEはDebianベースでOpenVZとKVMによる仮想化を実現するアプライアンスを作るディストリビューション。
管理はCLIもしくはWeb。
複数のPVEサーバをある程度統合管理が可能。

最初はCitrix XenServerでやろうかな?と思っていたんだけど、フル仮想化だとメモリを食うので、たくさんたてられるOpenVZを使えるこいつに目をつけてみた。

で、OpenVZ用のテンプレートが使えるかな?と思って、「/var/lib/vz/template/cache」にSabayonからダウンロードしたテンプレートファイル “Sabayon_Linux_SpinBase_5.4_x86_openvz.tar.gz”を配置してみた。
が、ProxmoxのWeb GUIの仮想マシン作成メニューで表示されない。

う~ん・・・とファイルを見比べてみる。

# ls /var/lib/vz/template/cache
Sabayon_Linux_SpinBase_5.4_x86_openvz.tar.gz
centos-4-default_4.8-20100922_i386.tar.gz
centos-5-standard_5.2-1_i386.tar.gz
debian-5.0-wordpress_2.9-1_i386.tar.gz
ubuntu-10.04-lamp_10.04_i386.tar.gz
#

ファイル名の法則が違う?

というわけで、ファイル名を「sabayon-5-SpinBase_5.4-1_i386.tar.gz」に変更してみた。
無事認識。

で、Sabayon 5.4のOpenVZを作成して起動してみたんですが・・・ネットワークインタフェースを認識していない・・・
なんでかなぁ???う~ん・・・・

# vzctl start マシンID
Warning: configuration file for distribution sabayon-5-SpinBase_5.4-1_i386 not found, using defaults from /etc/vz/dists/default
Starting container ...
Container is unmounted
Container is mounted
Adding IP address(es): IPアドレス
/bin/bash: line 394: /etc/network/interfaces: No such file or directory
grep: /etc/network/interfaces: No such file or directory
/bin/bash: line 407: /etc/network/interfaces: No such file or directory
/bin/bash: line 429: /etc/network/interfaces: No such file or directory
cp: cannot stat `/etc/network/interfaces': No such file or directory
/bin/bash: line 458: /etc/network/interfaces.bak: No such file or directory
mv: cannot stat `/etc/network/interfaces.bak': No such file or directory
Setting CPU units: 1000
Setting CPUs: 1
Set hostname: ホスト名
File resolv.conf was modified
Setting quota ugidlimit: 0
Container start in progress...
#

なるほど、起動時に読み込むテンプレートが適切じゃないせいなのね。

OpenVZのフォーラムで参考記事を発見。

/etc/vz/conf/各マシンID.conf 内の「OSTEMPLATE=”sabayon-5-SpinBase_5.4-1_i386″」が関係してると。
テンプレート自体は/etc/vz/distsにあるので、Sabayonに近いものは?と見てみると、ありました「gentoo.conf」(SabayonはGentooベースなのです)
てっとりばやく「ln gentoo.conf sabayon-5-SpinBase_5.4-1_i386.conf」を実行してから、起動!

# ln gentoo.conf sabayon-5-SpinBase_5.4-1_i386.conf
# vzctl start マシンID
Starting container ...
Container is mounted
Adding IP address(es): IPアドレス
Setting CPU units: 1000
Setting CPUs: 1
Set hostname: ホスト名
File resolv.conf was modified
Setting quota ugidlimit: 0
Container start in progress...
# 

これで、無事、ネットワーク接続も完了です。