在CentOS 5.5 服务器上安装使用OpenVZ

在这里主要讲述怎么安装和准备在CentOS 5.5 服务器,OpenVZ可以建立多个虚拟私人服务器在同一个硬件,类似与Linux Vserver Xen项目。OpenVZ是开源的分支,在商业Virtuozzo虚拟化技术解决方案提供商,提供所使用的许多虚拟服务器,内核补丁的OpenVZ GPL授权许可,和用户级工具是在QPL执照。

是意味着作为实用指南;它不覆盖所有的理论环境。

这份文档是没有任何类型的保证,!. 我想说的是这并不是唯一编译内核的方法体系。有许多方法可以达到这个目标,但这是我选择的方法。我不敢保证这个方法对你也试用。

1 安装OpenVZ:

为了安装OpenVZ ,我们需要找到yum 库文件下

cd /etc/yum.repos.d
wget
rpm --import

库中包含了一些不同的OpenVZ 内核 (你可以找到更多详情,他们在这里:://wiki.openvz.org/Kernel_flavors)。该命令:

yum search ovzkernel

显示系统可用的内核:

[root@server1 yum.repos.d]# yum search ovzkernel
...
ovzkernel.i686 : Virtuozzo Linux kernel (the core of the Linux operating system)
ovzkernel.x86_64 : Virtuozzo Linux kernel (the core of the Linux operating system)
ovzkernel-PAE.i686 : The Linux kernel compiled for PAE capable machines.
ovzkernel-PAE-debug.i686 : The Linux PAE kernel compiled with debug config
ovzkernel-PAE-devel.i686 : Development package for building kernel modules to match the PAE kernel.
ovzkernel-debug.i686 : The Linux kernel compiled with debug config
ovzkernel-debug.x86_64 : The Linux kernel compiled with debug config
ovzkernel-devel.i686 : Development package for building kernel modules to match the kernel.
ovzkernel-devel.x86_64 : Development package for building kernel modules to match the kernel.
ovzkernel-ent.i686 : The Linux kernel compiled for huge mem capable machines.
ovzkernel-ent-debug.i686 : The Linux ent kernel compiled with debug config
ovzkernel-ent-devel.i686 : Development package for building kernel modules to match the ent kernel.
ovzkernel-xen.i686 : The Linux kernel compiled for Xen VM operations
ovzkernel-xen.x86_64 : The Linux kernel compiled for Xen VM operations
ovzkernel-xen-devel.i686 : Development package for building kernel modules to match the kernel.
ovzkernel-xen-devel.x86_64 : Development package for building kernel modules to match the kernel.
[root@server1 yum.repos.d]#

挑选其中一个安装

yum install ovzkernel

这里应该自动的更新启动引导,无论如何我们应该打开/boot/grub/menu.lst,第一个内核文件应该控制新的OpenVZ,内核文件写的是"CentOS". 我想这是个好方法,可以让你知道这是“OpenVZ”内核,我们也要确认这是系统默认的OpenVZ内核,而不是默认的Centos 内核。

vi /boot/grub/menu.lst

# 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 OpenVZ (2.6.18-238.5.1.el5.028stab085.5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.5.1.el5.028stab085.5 ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.18-238.5.1.el5.028stab085.5.img
title CentOS (2.6.18-238.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.18-238.el5.img

现在我们安装一些OpenVZ 默认用户工具:

yum install vzctl vzquota

打开/etc/sysctl.conf 确认你有下列设置在其间:

vi /etc/sysctl.conf

[...]
net.ipv4.ip_forward = 1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.all.rp_filter = 1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
[...]
接下来你需要修改/etc/sysctl.conf,运行


sysctl -p

然后

接下来很重要的是,你的虚拟机ip地址必须不同与主机地址,属于同一网络段,如果不是这样,网络就不会在你虚拟机工作。

打开/etc/vz/vz.conf 和set NEIGHBOUR_DEVS 设置为所有:

vi /etc/vz/vz.conf

[...]
NEIGHBOUR_DEVS=all
[...]

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wywxyx.html