Modified: 16
January 2009, 10 April
2008, 19 August
2007, 19 April
2007, 16
December 2006
Created: 28 October 2006
参考になったページ
http://opentechpress.jp/developer/article.pl?sid=07/01/17/0129254&pagenum=1
"/etc/sysctl.conf"の設定 (16 January 2009)
4GB以上のメモリーに対応したサーバーのカーネルが欲しい (16 January 2009)
非標準のOSテンプレート(CentOS5など)を利用する方法 (11 January 2009)
設定ファイルをチェックや修復する方法 (10 April 2008)
ホストのネットワークとVPS間で通信できるように設定する方法 (19 April 2007)
"Error: lksctp-tools conflicts with kernel >= 2.6.10"が出てインストールできない (13 August 2007)
"Can't Allocate Memory"が出て実行できない (19 August 2007)
VPSでPostfixを動かす方法 (15 August 2007)
VPSのディスク容量を変更する方法 (16 December 2006)
VPSにログインする方法 (15 August 2007)
VPSのメモリの利用状態を確認する方法 (15 August 2007)
VPSでNTPを動かす方法 (12 January 2009)
VPSのサービスを制御する方法 (28 October 2006)
VPSのネットワークを設定する方法 (28 October 2006)
VPSを自動起動させる方法 (28 October 2006)
VPSのrootパスワードを設定する方法 (28 October 2006)
存在するVPSの一覧を表示する方法 (28 October 2006)
VPSの起動と停止と再起動の方法 (28 October 2006)
VPSをyumアップデートする方法 (28 October 2006)
VPSにパッケージを(yum/rpm)インストールする方法 (28 October 2006)
VPSを作成する方法 (28 October 2006)
VPSを削除する方法 (16 December 2006)
OSテンプレートのインストール (28 October 2006)
OpenVZのカーネルをデフォルトのカーネルとして起動させる方法 (28 October 2006)
意味はよくわかりませんが(えーーーー!、おいおい)、以下のように設定するそうです。
# Kernel sysctl configuration file for Red Hat Linux
#
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
# Do not accept source routing
net.ipv4.conf.default.accept_source_route = 0
# Enables the magic-sysrq key
kernel.sysrq = 1
# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
# Controls whether core dumps will append the PID to the core filename
# Useful for debugging multi-threaded applications
kernel.core_uses_pid = 1
# Controls the use of TCP syncookies
net.ipv4.tcp_syncookies = 1
# Controls the maximum size of a message, in bytes
kernel.msgmnb = 65536
# Controls the default maxmimum size of a mesage queue
kernel.msgmax = 65536
# Controls the maximum shared segment size, in bytes
kernel.shmmax = 4294967295
# Controls the maximum number of shared memory segments, in pages
kernel.shmall = 268435456
4GBのメモリーを実装したサーバーで、OpenVZのカーネル(ovzkernel)をインストールすると、3.2GBぐらいしか認識されません。
# yum install ovzkernel-PAE PAEの付いたカーネルをインストールすると目いっぱい使えます。
非標準のテンプレートは、コミュニティから提供されているようです。以下のURLにあります。
http://download.openvz.org/contrib/template/precreated/
CentSO5の場合
2009年1月11日時点で、CentOS5のテンプレートが2つありました。
- centos-5-i386-default-5.2-20090103.tar.gz
- centos-5-i386-minimal-5.2-20090103.tar.gz
テンプレートは、"/vz/template/cache/"にコピーします。
# cp /root/centos-5-i386-default-5.2-20090103.tar.gz /vz/template/cache VPSを作ってみます。
# vzctl create 8001 --ostemplate centos-5-i386-default-5.2-20090103
Unable to get full ostemplate name for centos-5-i386-default-5.2-20090103
Creating VE private area (centos-5-i386-default-5.2-20090103)
Performing postcreate actions
VE private area was created
#
Fedora10の場合
Fedora10のVPSを作ってみます。
# vzctl create 8002 --ostemplate fedora-10-i386-default
Unable to get full ostemplate name for fedora-10-i386-default
Creating VE private area (fedora-10-i386-default)
Warning: configuration file for distribution fedora-10-i386-default not found default used
Performing postcreate actions
VE private area was created
#
Ubuntu8の場合
Ubuntu8のVPSを作ってみます。
# vzctl create 8003 --ostemplate ubuntu-8.10-i386-minimal
Unable to get full ostemplate name for ubuntu-8.10-i386-minimal
Creating VE private area (ubuntu-8.10-i386-minimal)
Performing postcreate actions
VE private area was created
#
カレントディレクトリを移動します。
# cd /etc/sysconfig/vz-scripts問題ない場合は、以下のようになります。
# vzcfgvalidate 1001.conf Validation completed: success #問題がある場合、以下のようにエラーが出ます。
# vzcfgvalidate 1018.conf Error: othersockbuf.lim-othersockbuf.bar should be > 2621440 (currently, 304800) #修復は、以下のコマンドでできます。
# vzcfgvalidate -i 1024.conf Error: tcpsndbuf.lim-tcpsndbuf.bar should be > 655360 (currently, 204800) set to 319488:974848 (y/n) [y] <Enter> Error: othersockbuf.lim-othersockbuf.bar should be > 655360 (currently, 4800) set to 332096:987456 (y/n) [y] <Enter> Warning: tcprcvbuf.lim-tcprcvbuf.bar should be > 655360 (currently, 204800) set to 319488:974848 (y/n) [y] <Enter> Validation completed: success #
"Error: lksctp-tools conflicts with kernel >= 2.6.10"が出てインストールできない
"ovzkernel"をインストールしようとすると、エラーが出ることがあります。
: ovzkernel-PAE-2.6.18-8.1. 100% |=========================| 259 kB 00:00 ---> Package ovzkernel-PAE.i686 0:2.6.18-8.1.8.el5.028stab039.1 set to be installed ---> Package ovzkernel.i686 0:2.6.18-8.1.8.el5.028stab039.1 set to be installed --> Running transaction check --> Processing Conflict: lksctp-tools conflicts kernel >= 2.6.10 --> Finished Dependency Resolution Error: lksctp-tools conflicts with kernel >= 2.6.10 #以下を実行して消去するとエラーが出なくなります。
# yum erase lksctp-tools
CentOS4に、CentOS5対応のOpenVZをインストールしたときにもこのエラーが出ます。その場合、エラーを回避できても再起動時に、Kernel PANICで起動しません。CentOS5にしましょう。
"Can't Allocate Memory"が出て実行できない
"/etc/sysconfig/vz-scripts/101.conf" を以下のように変更します。
「KMEMSIZE」を大きくすれば解決できます。
: ## UBC parameters (in form of barrier:limit) # Primary parameters AVNUMPROC="40:40" NUMPROC="65:65" NUMTCPSOCK="80:80" NUMOTHERSOCK="80:80" VMGUARPAGES="6144:2147483647" # Secondary parameters KMEMSIZE="2752512:5936012" TCPSNDBUF="319488:524288" TCPRCVBUF="319488:524288" OTHERSOCKBUF="132096:336896" DGRAMRCVBUF="132096:132096" OOMGUARPAGES="6144:2147483647" # Auxiliary parameters LOCKEDPAGES="32:32" SHMPAGES="8192:8192" PRIVVMPAGES="49152:53575" NUMFILE="2048:2048" NUMFLOCK="100:110" NUMPTY="16:16" NUMSIGINFO="256:256" DCACHESIZE="1048576:1097728" :
以下のコマンドで設定します。
# vzctl set 2028 --setmode restart --capability sys_time:on --save Unable to set capability on running VE Restarting VE Stopping VE ... VE was stopped VE is unmounted Starting VE ... VE is mounted Adding IP address(es): 192.168.83.156 Setting CPU units: 1000 Configure meminfo: 65536 Set hostname: webfree500.com File resolv.conf was modified VE start in progress... Saved parameters for VE 2028 #設定してもすぐに同期しませんので、VPSに入って、自分で設定します。
# date 01121733 #
VPSにPostfixをインストールして起動させると、以下のエラーが出て起動しません。
: Aug 15 06:10:09 ns5 postfix/postfix-script: starting the Postfix mail system Aug 15 06:10:09 ns5 postfix/master[15371]: fatal: pipe: Cannot allocate memory以下のように変更すると起動できるようになります。
"/etc/sysconfig/vz-scripts/101.conf" を以下のように変更します。
以下は変更前のデフォルト設定です。
: ## UBC parameters (in form of barrier:limit) # Primary parameters AVNUMPROC="40:40" NUMPROC="65:65" NUMTCPSOCK="80:80" NUMOTHERSOCK="80:80" VMGUARPAGES="6144:2147483647" # Secondary parameters KMEMSIZE="2752512:2936012" TCPSNDBUF="319488:524288" TCPRCVBUF="319488:524288" OTHERSOCKBUF="132096:336896" DGRAMRCVBUF="132096:132096" OOMGUARPAGES="6144:2147483647" # Auxiliary parameters LOCKEDPAGES="32:32" SHMPAGES="8192:8192" PRIVVMPAGES="49152:53575" NUMFILE="2048:2048" NUMFLOCK="100:110" NUMPTY="16:16" NUMSIGINFO="256:256" DCACHESIZE="1048576:1097728" :以下のように変更します。
: # UBC parameters (in form of barrier:limit) # Primary parameters AVNUMPROC="40:40" NUMPROC="256:256" NUMTCPSOCK="256:256" NUMOTHERSOCK="512:512" VMGUARPAGES="6144:2147483647" # Secondary parameters KMEMSIZE="2752512:2936012" TCPSNDBUF="319488:524288" TCPRCVBUF="319488:524288" OTHERSOCKBUF="336896:336896" DGRAMRCVBUF="132096:132096" OOMGUARPAGES="6144:2147483647" # Auxiliary parameters LOCKEDPAGES="32:32" SHMPAGES="8192:8192" PRIVVMPAGES="49152:53575" NUMFILE="2048:2048" NUMFLOCK="100:110" NUMPTY="16:16" NUMSIGINFO="256:256" DCACHESIZE="1048576:1097728" :
ホストのネットワークとVPS間で通信できるように設定する方法
インストール直後の状態では、VPSのサーバーから、ホストのネットワークにPINGが通りません。
IPパケットがフォワードされるように設定する必要があります。
"/etc/sysctl.conf" の "net.ipv4.ip_forward" を "0" から "1" にします。
# Kernel sysctl configuration file for Red Hat Linux # # For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and # sysctl.conf(5) for more details. # Controls IP packet forwarding net.ipv4.ip_forward = 1 # Controls source route verification net.ipv4.conf.default.rp_filter = 1 # Do not accept source routing net.ipv4.conf.default.accept_source_route = 0 # Controls the System Request debugging functionality of the kernel kernel.sysrq = 0 # Controls whether core dumps will append the PID to the core filename. # Useful for debugging multi-threaded applications. kernel.core_uses_pid = 1
以下のコマンド(sshの例)で、サービスの制御ができます。
# vzctl set 101 --diskspace 2000000 --save #指定容量が足らない場合は、以下のメッセージが出ます。
# vzctl set 101 --diskspace 1000 vzquota : (warning) block_hard_limit [1000] < block_current_usage [312980] WARNING: Settings were not saved and will be resetted to original values on next start (use --save flag) #
以下のコマンドで、指定したVPSにログインできます。
# vzctl enter 101 #
以下のコマンドで、メモリの利用状況が確認できます。
# vzcalc -v 101 Resource Current(%) Promised(%) Max(%) Low Mem 0.46 1.22 1.22 Total RAM 0.46 n/a n/a Mem + Swap 0.23 0.70 n/a Alloc. Mem 0.41 0.70 5.33 Num. Proc 0.05 n/a 0.20 -------------------------------------------- Memory 0.46 1.22 5.33 #
以下のコマンド(sshの例)で、サービスの制御ができます。
# vzctl exec 101 service sshd start Starting sshd:[ OK ] # vzctl exec 101 service sshd status sshd (pid 17562 16299) is running... #
# vzctl set 101 --hostname openvz.tomo.ac --save Saved parameters for VE 101 # vzctl set 101 --ipadd 192.168.0.22 --save Saved parameters for VE 101 # vzctl set 101 --nameserver 192.168.0.11 --save Saved parameters for VE 101 #
# vzctl set 101 --onboot yes --save Saved parameters for VE 101 #
# vzctl set 101 --userpasswd root:jhgyggjkk Starting VE ... VE is mounted VE start in progress... Changing password for user root. passwd: all authentication tokens updated successfully. Stopping VE ... VE was stopped VE is unmounted #
以下のコマンドで一覧が表示できます。
# vzlist -a VEID NPROC STATUS IP_ADDR HOSTNAME 101 16 running 192.168.0.21 openvz.tomo.ac 102 16 running 192.168.0.22 openvz.tomo.ac #
起動する
以下のコマンドで起動できます。
# vzctl start 101 Starting VE ... VE is mounted Adding IP address(es): 192.168.83.21 Setting CPU units: 1000 Set hostname: openvz.tomo.ac File resolv.conf was modified VE start in progress... # vzlist -a VEID NPROC STATUS IP_ADDR HOSTNAME 101 12 running 192.168.83.21 openvz.tomo.ac 102 16 running 192.168.83.22 openvz.tomo.ac #
停止する
以下のコマンドで停止できます。
# vzctl stop 101 Stopping VE ... VE was stopped VE is unmounted # vzlist -a VEID NPROC STATUS IP_ADDR HOSTNAME 101 - stopped 192.168.83.21 openvz.tomo.ac 102 16 running 192.168.83.22 openvz.tomo.ac #
再起動する
以下のコマンドで再起動できます。
# vzctl restart 101 Restarting VE Stopping VE ... VE was stopped VE is unmounted Starting VE ... VE is mounted Adding IP address(es): 192.168.83.21 Setting CPU units: 1000 Set hostname: openvz.tomo.ac File resolv.conf was modified VE start in progress... # vzlist -a VEID NPROC STATUS IP_ADDR HOSTNAME 101 16 running 192.168.83.21 openvz.tomo.ac 102 16 running 192.168.83.22 openvz.tomo.ac #
# vzyum 101 update exec /usr/share/vzyum/bin/yum -c /vz/template/centos/4/i386/config/yum.conf --installroot /vz/root/101 --vps=101 update Setting up Update Process Setting up repositories centos4-vz-addons 100% |=========================| 951 B 00:00 centos4-base 100% |=========================| 1.1 kB 00:00 centos4-updates-released 100% |=========================| 951 B 00:00 Reading repository metadata in from local files No Packages marked for Update/Obsoletion #
yumでインストール
# vzyum 101 install postfix exec /usr/share/vzyum/bin/yum -c /vz/template/centos/4/i386/config/yum.conf --installroot /vz/root/101 --vps=101 install postfix Setting up Install Process Setting up repositories centos4-vz-addons 100% |=========================| 951 B 00:00 centos4-base 100% |=========================| 1.1 kB 00:00 centos4-updates-released 100% |=========================| 951 B 00:00 Reading repository metadata in from local files Parsing package install arguments Resolving Dependencies --> Populating transaction set with selected packages. Please wait. ---> Downloading header for postfix to pack into transaction set. postfix-2.2.10-1.RHEL4.2. 100% |=========================| 40 kB 00:00 ---> Package postfix.i386 2:2.2.10-1.RHEL4.2 set to be updated --> Running transaction check Dependencies Resolved ============================================================================= Package Arch Version Repository Size ============================================================================= Installing: postfix i386 2:2.2.10-1.RHEL4.2 centos4-base 3.0 M Transaction Summary ============================================================================= Install 1 Package(s) Update 0 Package(s) Remove 0 Package(s) Total download size: 3.0 M Is this ok [y/N]: y Downloading Packages: (1/1): postfix-2.2.10-1.R 100% |=========================| 3.0 MB 00:15 Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Installing: postfix ######################### [1/1] Installed: postfix.i386 2:2.2.10-1.RHEL4.2 Complete! #
rpmでインストール
# vzrpm 101 -ivh postfix #
インストール可能なOSテンプレートを確認します。
# yum list vz* Setting up repositories openvz 100% |=========================| 951 B 00:00 update 100% |=========================| 951 B 00:00 base 100% |=========================| 1.1 kB 00:00 addons 100% |=========================| 951 B 00:00 extras 100% |=========================| 1.1 kB 00:00 Reading repository metadata in from local files Installed Packages vzctl.i386 3.0.12-1 installed vzctl-lib.i386 3.0.12-1 installed vzpkg.noarch 2.7.0-18 installed vzquota.i386 3.0.9-1 installed vzyum.noarch 2.4.0-11 installed Available Packages vzrpm43.i386 4.3.3-7_nonptl.6 openvz vzrpm43-python.i386 4.3.3-7_nonptl.6 openvz vzrpm44.i386 4.4.1-22.5 openvz vzrpm44-python.i386 4.4.1-22.5 openvz vztmpl-centos-4.i386 2.0-2 openvz vztmpl-fedora-core-3.i386 2.0-2 openvz vztmpl-fedora-core-4.i386 2.0-2 openvz vztmpl-fedora-core-5.i386 2.0-2 openvz #以下のコマンドで、CentOS4のテンプレートがインストールできます。
# yum install vztmpl-centos-4.i386
以下のコマンドで、VPSを作成します。
# vzctl create 101 --ostemplate centos-4-i386-default --config vps.basic Creating VE private area: /vz/private/1001 Performing postcreate actions VE private area was created #
以下のコマンドで、VPSを削除できます。
# vzctl destroy 101 Destroying VE private area: /vz/private/101 VE private area was destroyed #
OpenVZのカーネルをデフォルトのカーネルとして起動させる方法
"/etc/grub.conf"の変更でデフォルトのカーネルを変更(指定)できます。
1番目がOpenVZのカーネルなので、"default=0"とします。
# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00 # initrd /initrd-version.img #boot=/dev/sda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title CentOS (2.6.9-023stab032.1) root (hd0,0) kernel /vmlinuz-2.6.9-023stab032.1 ro root=/dev/VolGroup00/LogVol00 initrd /initrd-2.6.9-023stab032.1.img title CentOS-4 i386 (2.6.9-22.EL) root (hd0,0) kernel /vmlinuz-2.6.9-22.EL ro root=/dev/VolGroup00/LogVol00 initrd /initrd-2.6.9-22.EL.img