在Linux 下配置OPENVZ 实例
4XnLinux联盟
推荐使用Fedora Core 4/5/3 或者RHEL/CentOS 4。
4XnLinux联盟
1. 下载安装文件
4XnLinux联盟
根据您的内核版本在这里:http://openvz.org/download/kernel/ 下载。
# rpm -ihv vzkernel-name*.rpm
4XnLinux联盟
2.修改grub.conf 文件
title OpenVZ (2.6.8-022stab029.1) root (hd0,0) kernel 4XnLinux联盟
/vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5 initrd /initrd-2.6.8-022stab029.1.img4XnLinux联盟
4XnLinux联盟
3.修改、etc/sysyctl.conf文件:
/etc/sysctl.conf:4XnLinux联盟
# On Hardware Node we generally need4XnLinux联盟
# packet forwarding enabled and proxy arp disabled4XnLinux联盟
net.ipv4.ip_forward = 14XnLinux联盟
net.ipv4.conf.default.proxy_arp = 04XnLinux联盟
# Enables source route verification4XnLinux联盟
net.ipv4.conf.all.rp_filter = 14XnLinux联盟
# Enables the magic-sysrq4XnLinux联盟
key kernel.sysrq = 14XnLinux联盟
#net.ipv4.tcp_ecn = 04XnLinux联盟
# we do not want all our interfaces to send redirects4XnLinux联盟
net.ipv4.conf.default.send_redirects = 14XnLinux联盟
4XnLinux联盟
4. 如果你运行了iptables防火墙和SELinux,先关闭和禁止。
4XnLinux联盟
编辑/etc/sysconfig/selinux:
SELINUX=disabled。
另外还要关闭iptables防火墙。
4XnLinux联盟
5.安装OpenVZ管理软件
4XnLinux联盟
根据您的版本在这里:http://openvz.org/download/utils/ 下载。
# rpm –Uhv vzctl*.rpm vzquota*.rpm vzpkg*.rpm
4XnLinux联盟
6.重新启动VZ
4XnLinux联盟
# /etc/init.d/vz start
4XnLinux联盟
7.安装模板
# rpm –ihv vztmpl-fedora-core-3-1.0-2.noarch.rpm4XnLinux联盟
# vzpkgcache4XnLinux联盟
Creating cache for fedora-core-3 OS template4XnLinux联盟
Setting up install process4XnLinux联盟
Packing cache file fedora-core-3.tar.gz ...4XnLinux联盟
Cache file fedora-core-3.tar.gz [130M] created.4XnLinux联盟
4XnLinux联盟
8.为虚拟服务器创建一个非零ID
# vzctl create 1014XnLinux联盟
Creating VPS private area: /vz/private/1014XnLinux联盟
VPS is mounted4XnLinux联盟
Postcreate action done4XnLinux联盟
VPS is unmounted4XnLinux联盟
VPS private area was created4XnLinux联盟
4XnLinux联盟
9.设置为零参数
# vzctl set 101 --hostname test101.my.org --save4XnLinux联盟
Hostname for VPS set: test101.my.org4XnLinux联盟
Saved parameters for VPS 1014XnLinux联盟
# vzctl set 101 --ipadd 10.0.186.1 --save4XnLinux联盟
Adding IP address(es): 10.0.186.14XnLinux联盟
Saved parameters for VPS 1014XnLinux联盟
# vzctl set 101 --nameserver 192.168.1.165 --save4XnLinux联盟
File resolv.conf was modified4XnLinux联盟
Saved parameters for VPS 1014XnLinux联盟
4XnLinux联盟
10.设置root用户口令
4XnLinux联盟
# vzctl set 101 --userpasswd root:test
4XnLinux联盟
11.启动SSH守护进程
4XnLinux联盟
# vzctl exec 101 service sshd start
4XnLinux联盟
12.启动VPS
# vzctl start 1014XnLinux联盟
Starting VPS ...4XnLinux联盟
VPS is mounted4XnLinux联盟
Adding IP address(es): 10.0.186.101 Hostname for VPS 101 set: test.my.org4XnLinux联盟
VPS start in progress...4XnLinux联盟
4XnLinux联盟
13.加载防火墙
4XnLinux联盟
前面关闭的防火墙,出于安全考虑这里还要加载
# vzctl set 101 --iptables iptable_filter 4XnLinux联盟
--iptables ipt_length --iptables ipt_limit 4XnLinux联盟
--iptables iptable_mangle --iptables ipt_REJECT --save