CentOS 5.3 OpenVZ安装指南
by Elton on 十.27, 2009, under Linux
1. 安装宿主系统CentOS 5.3,分区的时候,要分一个/vz的ext3分区用来存放OpenVZ的template和Virtual Private Servers。 官方的建议是:
/ 2-4G
/swap 2倍物理内存
/vz 剩余的磁盘空间
2. 关掉FIrewall和SELinux
3. 安装OpenVZ
a) 从http://wiki.openvz.org/Download/kernel下载你操作系统对应的内核版本。 我这里用的是ovzkernel-2.6.18-128.2.1.el5.028stab064.7.i686.rpm
1 | rpm -ihv ovzkernel-2.6.18-128.2.1.el5.028stab064.7.i686.rpm |
b) 编辑GRUB Loader
/boot/grub/grub.conf
确保grub.conf文件的内容为:
1 2 3 4 | title OpenVZ (2.6.18-128.2.1.el5.028stab064.7)
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-128.2.1.el5.028stab064.7 ro root=LABEL=/
initrd /boot/initrd-2.6.18-128.2.1.el5.028stab064.7.img |
c) 设置sysctl参数
/etc/sysctl.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 | # On Hardware Node we generally need # packet forwarding enabled and proxy arp disabled net.ipv4.ip_forward = 1 net.ipv4.conf.default.proxy_arp = 0 # Enables source route verification net.ipv4.conf.all.rp_filter = 1 # Enables the magic-sysrq key kernel.sysrq = 1 # TCP Explict Congestion Notification #net.ipv4.tcp_ecn = 0 # we do not want all our interfaces to send redirects net.ipv4.conf.default.send_redirects = 1 net.ipv4.conf.all.send_redirects = 0 |
使用下面的命令,使设置生效,之后重启系统。
1 | # sysctl -p |
c) 安装客户端工具
- vzctl: 这个工具是用来操作VPS的,如创建,销毁,开始,关闭和设置参数
- vzquota: 用于设定VPS的 quota
- vzpkg:这个工具用来管理 OpenVZ的 templates.
1 2 3 4 | rpm -Uhv vzyum-2.4.0-11.noarch.rpm rpm -Uhv vzquota-3.0.12-1.i386.rpm rpm -Uhv vzctl-3.0.23-1.i386.rpm rpm -Uhv vzpkg-2.7.0-18.noarch.rpm |
然后你就可以启动OpenVZ了
1 | /etc/init.d/vz start |
3.安装OpenVZ template
在这里下载你所需要的模板http://openvz.org/download/template/
先安装模板metadata,再使用vzpkgcache生成cache
或者直接在http://openvz.org/download/template/cache/下载已经cache过的模板,比如centos-5-x86_64.tar.gz ,不用解压,直接把它放到/vz/template/cache中。 然后使用下面的命令来生成虚机
1 | vzctl create 101 --ostemplate centos-5-x86 --config vps.basic |
create后面的数字是这个VPS的ID,每个VPS都要有一个唯一的ID来做标示。 可以使用ip的最后一位来做标示, 这样方便记忆。
VPS创建后,会在/vz/root/vpsid/生成一个目录作为它的私有空间.
为了便于设置,不必每个VPS都指定参数,创建的时候跟上了一个–config参数用于指定VPS的设置参数。 这些配置文件在/etc/sysconfig/vz-script中。 上面使用的就是/etc/sysconfig/vz-scripts/ve-vps.basic.conf-sample这个文件
你可以通过编辑/etc/sysconfig/vz文件的内容,来预先指定模板和配置文件,如:
1 2 | DEF_OSTEMPLATE="centos-5-x86" CONFIGFILE="vps.basic" |
这样就可以通过下面的命令快速建立VPS
1 2 3 4 5 6 | # vzctl create 101 Creating VPS private area: /vz/private/101 VPS is mounted Postcreate action done VPS is unmounted VPS private area was created |
4. 设置VPS
创建虚机后,使用下面命令来设置虚机的参数
1 2 3 4 | vzctl set 101 --hostname test101.my.org --save #设置主机名 vzctl set 101 --nameserver 202.96.209.5 --save #设置DNS vzctl set 101 --ipadd 172.1.1.101 --save #设置IP vzctl set 101 --userpasswd username:password #设置帐号 |
5. 启动和终止
a) 启动
1 | vzctl start 101 |
b)终止
1 | vzctl stop 101 |
c)查看状态
1 | vzctl status 101 |
d)查看所有虚机的资源占用情况
1 | cat /proc/vz/veinfo |
e) 查看所有虚机的状态
1 | vzlist -a |
6. 删除VPS
1 | vzctl destroy 101 |



十月 31st, 2009 on 09:20
很不错的博客,交换下友情链接不?
十一月 1st, 2009 on 17:02
当然可以了,链接已加
五月 6th, 2010 on 13:49
I was pleased to read this article, keep up the good work.
八月 10th, 2010 on 13:00
Thanks for sharing this helpful info!
八月 29th, 2010 on 11:48
I think that is an interesting point, it made me think a bit. Thanks for sparking my thinking cap. Sometimes I get so much in a rut that I just feel like a record.
九月 5th, 2010 on 06:57
Thanks for an idea, you sparked at idea from a concept I hadn’t given thoguht to before . Now lets see if I can do something productive with it.
九月 6th, 2010 on 13:08
I will use your advice from now on. Jaap
十月 14th, 2010 on 19:16
I’m new on here, I hit upon this website I find It pretty helpful and its helped me out a lot. I will be able to contribute & aid other users like it has helped me.