openVZのホスト側コンテナの場所を変更する
■デフォルトコンテナの位置を変える
サーバの容量の都合で場所変えたくなったりする。
#vim /etc/vz/vz.conf ## Defaults for containers VE_ROOT=/vz/root/$VEID VE_PRIVATE=/vz/private/$VEID ↓以下に変更した ## Defaults for containers VE_ROOT=/home/vz/root/$VEID VE_PRIVATE=/home/vz/private/$VEID
これで次回以降作成するコンテナは/home側に作られる。
■各コンテナの設定ファイルの場所
/etc/vz/conf
※実際はシンボリックだった
# pwd /etc/vz # ll 合計 20 lrwxrwxrwx. 1 root root 23 3月 15 20:01 2012 conf -> ../sysconfig/vz-scripts drwxr-xr-x. 3 root root 4096 3月 15 20:01 2012 dists -rw-r--r--. 1 root root 739 1月 15 04:52 2012 download.conf drwxr-xr-x. 2 root root 4096 1月 15 04:52 2012 names -rw-r--r--. 1 root root 345 1月 15 04:52 2012 osrelease.conf -rw-r--r-- 1 root root 1335 3月 26 13:36 2012 vz.conf
■久しぶりにコンテナ立てたのでその時の作業ログ
□コンテナ作成
[root@localhost ~]# vzctl create 175 --ostemplate centos-6-x86 --config basic
Creating container private area (centos-6-x86)
Performing postcreate actions
CT configuration saved to /etc/vz/conf/175.conf
Container private area was created
□起動設定
[root@localhost ~]# vzctl set 175 --onboot yes --save
CT configuration saved to /etc/vz/conf/175.conf
□host名設定
[root@localhost ~]# vzctl set 175 --hostname openvz.example.com --save
CT configuration saved to /etc/vz/conf/175.conf
□IPアドレス設定
[root@localhost ~]# vzctl set 175 --ipadd 192.168.1.175 --save
CT configuration saved to /etc/vz/conf/175.conf
□ソケット設定
[root@localhost ~]# vzctl set 175 --numothersock 120 --save
CT configuration saved to /etc/vz/conf/175.conf
□ネームサーバ設定
[root@localhost ~]# vzctl set 175 --nameserver 192.168.1.1 --save
CT configuration saved to /etc/vz/conf/175.conf
□コンテナ起動
[root@localhost ~]# vzctl start 175
Starting container ...
Container is mounted
Adding IP address(es): 192.168.1.175
Setting CPU units: 1000
Container start in progress...
□rootパスワード設定
[root@localhost ~]# vzctl exec 175 passwd
New password: ルートパスワード設定
Retype new password: ルートパスワード設定
Changing password for user root.
passwd: all authentication tokens updated successfully.
□言語設定
[root@localhost ~]# vzctl exec 175 'echo LANG="ja_JP.UTF-8" > /etc/sysconfig/i18n'
□時間設定
[root@localhost ~]# vzctl exec 175 'mv /etc/localtime /etc/localtime.org'
[root@localhost ~]# vzctl exec 175 'ln -s /usr/share/zoneinfo/Asia/Tokyo /etc/localtime'
□HDD容量設定
[root@localhost ~]# vzctl set 175 --diskspace 100G:105G --save
□メモリ設定
[root@localhost ~]# vzctl set 175 --vmguarpages $((256 * 2048)) --save
UB limits were set successfully
CT configuration saved to /etc/vz/conf/175.conf
[root@localhost ~]# vzctl set 175 --privvmpages $((256 * 3072)) --save
UB limits were set successfully
CT configuration saved to /etc/vz/conf/175.conf
□容量増やしたのにinode増やしてなくてエラーでので増量
[root@localhost ~]# vzctl set 175 --diskinodes $(( 200000*3 )):$(( 220000*3 )) --save
□コンテナの稼動状況
[root@localhost ~]# vzlist -a
CTID NPROC STATUS IP_ADDR HOSTNAME
・・・
175 38 running 192.168.1.175 openvz.example.com
・・・