在Fedora 14上安装和使用OpenVZ

在Fedora 14上安装和使用OpenVZ

在本教程中,我将介绍如何为OpenVZ准备Fedora 14服务器。 使用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.repo ...

vi openvz.repo

...并禁用[openvz-kernel-rhel5]存储库( enabled = 0 ),并启用[openvz-kernel-rhel6]存储库( enabled = 1 ):

[...]
[openvz-kernel-rhel5]
name=OpenVZ RHEL5-based kernel
#baseurl=http://download.openvz.org/kernel/branches/rhel5-2.6.18/current/
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel5-2.6.18
enabled=0
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ
[...]
[openvz-kernel-rhel6]
name=OpenVZ RHEL6-based kernel
#baseurl=http://download.openvz.org/kernel/branches/rhel6-2.6.32/current/
mirrorlist=http://download.openvz.org/kernel/mirrors-rhel6-2.6.32
enabled=1
gpgcheck=1
gpgkey=http://download.openvz.org/RPM-GPG-Key-OpenVZ
[...]

存储库包含几个不同的OpenVZ内核(您可以在这里找到有关它们的更多详细信息: http : //wiki.openvz.org/Kernel_flavors )。 命令

yum search vzkernel

显示可用的内核:

[root@server1 yum.repos.d]# yum search vzkernel
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
===================================================================== Matched: vzkernel 
======================================================================
vzkernel-debug-debuginfo.i686 : Debug information for package vzkernel-debug
vzkernel-debug-debuginfo.x86_64 : Debug information for package vzkernel-debug
vzkernel-debuginfo.i686 : Debug information for package vzkernel
vzkernel-debuginfo.x86_64 : Debug information for package vzkernel
vzkernel-debuginfo-common-i686.i686 : Kernel source files used by vzkernel-debuginfo packages
vzkernel-debuginfo-common-x86_64.x86_64 : Kernel source files used by vzkernel-debuginfo packages
vzkernel.i686 : The Linux kernel
vzkernel.x86_64 : The Linux kernel
vzkernel-debug.i686 : The Linux kernel compiled with extra debugging enabled
vzkernel-debug.x86_64 : The Linux kernel compiled with extra debugging enabled
vzkernel-debug-devel.i686 : Development package for building kernel modules to match the debug kernel
vzkernel-debug-devel.x86_64 : Development package for building kernel modules to match the debug kernel
vzkernel-devel.i686 : Development package for building kernel modules to match the kernel
vzkernel-devel.x86_64 : Development package for building kernel modules to match the kernel
vzkernel-headers.i686 : Header files for the Linux kernel for use by glibc
vzkernel-headers.x86_64 : Header files for the Linux kernel for use by glibc
[root@server1 yum.repos.d]#

选择其中一个并安装如下:

yum install vzkernel

这也应该自动更新GRUB引导加载程序。 无论如何,我们应该打开/boot/grub/menu.lst ; 第一个内核节应该包含新的OpenVZ内核。 该内核的标题只是读“Fedora”。 我认为改变标题是一个好主意,并用“OpenVZ”添加一些东西,以便您知道它是OpenVZ内核。 还要确保默认的值为0 ,以便自动引导第一个内核(OpenVZ内核),而不是默认的Fedora内核。

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/mapper/VolGroup-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=0
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora OpenVZ (2.6.32-042test003.1.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-042test003.1.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_LVM_LV=VolGroup/lv_root rd_LVM_LV=VolGroup/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de rhgb quiet crashkernel=auto
        initrd /initramfs-2.6.32-042test003.1.x86_64.img
title Fedora (2.6.35.6-45.fc14.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.35.6-45.fc14.x86_64 ro root=/dev/mapper/VolGroup-lv_root rd_LVM_LV=VolGroup/lv_root rd_LVM_LV=VolGroup/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=de rhgb quiet
        initrd /initramfs-2.6.35.6-45.fc14.x86_64.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.32-042test003.1.x86_64
[root@server1 ~]#
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

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

支付宝扫一扫打赏

微信扫一扫打赏