在CentOS 5.6上安装和使用OpenVZ

在CentOS上安装和使用OpenVZ 5.6

在本教程中,我将介绍如何为OpenVZ准备CentOS 5.6服务器。 使用OpenVZ,您可以在同一硬件上创建多个虚拟专用服务器(VPS),类似于Xen和Linux Vserver项目。 OpenVZ是Virtuozzo的开源分支,Virtuozzo是许多提供虚拟服务器的提供商所使用的商业虚拟化解决方案。 OpenVZ内核补丁是根据GPL许可证授权的,用户级工具是QPL许可证。

这是一个实践指南; 它不包括理论背景。 他们在网络上的许多其他文档中被处理。

本文档不附带任何形式的保证! 我想说,这不是设立这样一个制度的唯一办法。 实现这一目标有很多方法,但这是我所采取的方式。 我不会保证这将为您工作!

1安装OpenVZ

为了安装OpenVZ,我们需要将OpenVZ存储库添加到yum:

cd /etc/yum.repos.d
wget http://download.openvz.org/openvz.repo
rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ

存储库包含几个不同的OpenVZ内核(您可以在这里找到有关它们的更多详细信息: http : //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

这也应该自动更新GRUB引导加载程序。 无论如何,我们应该打开/boot/grub/menu.lst ; 第一个内核节应该包含新的OpenVZ内核。 该内核的标题只是“CentOS”。 我认为改变标题是一个好主意,并用“OpenVZ”添加一些东西,以便您知道它是OpenVZ内核。 还要确保默认值为0 ,以便自动引导第一个内核(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地址与主机系统的IP地址不同,则以下步骤很重要。 如果不这样做,网络将无法在虚拟机中运行!

打开/etc/vz/vz.conf并将NEIGHBOUR_DEVS设置为全部

vi /etc/vz/vz.conf
[...]
NEIGHBOUR_DEVS=all
[...]

如果要使用OpenVZ,则需要禁用SELinux。 打开/ etc / sysconfig / selinux并将SELINUX的值设置为disabled

vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

最后重新启动系统:

reboot

如果您的系统重新启动没有问题,那么一切都很好!

uname -r

并且您的新OpenVZ内核应显示:

[root@server1 ~]# uname -r
2.6.18-238.5.1.el5.028stab085.5
[root@server1 ~]#
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏