安装和使用OpenVZ在Debian Wheezy(AMD64)

安装和使用OpenVZ在Debian Wheezy(AMD64)

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

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

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

1初步说明

我在这里使用x86_64(amd64)系统。 如果您使用的是i386系统,则几个命令将略有不同。

2安装OpenVZ

对于Debian Wheezy,官方存储库中没有OpenVZ内核。 所以我们有三个选择:

  1. 从OpenVZ项目的官方RPM软件包安装 (请参阅在Debian 6.0上从RPM安装内核 ) - 使用ploop支持! (推荐的)
  2. 从OpenVZ项目中安装Debian Wheezy内核,并从Debian的正式版存储库中安装Debian Wheezy内核(请参阅Debian上的安装 ) - 具有ploop支持的内核,但Debian的vzctl软件包不支持。
  3. 从Proxmox软件包安装 (请参阅Debian Wheezy上的安装Proxmox VE ) - 内核中没有ploop支持。

2.1从OpenVZ项目的官方RPM软件包安装

http://wiki.openvz.org/Download/kernel/rhel6http://wiki.openvz.org/Download/utils下载最新的vzkernel,vzctl,ploop和vzquota RPM软件包,例如:

cd /tmp
wget http://download.openvz.org/kernel/branches/rhel6-2.6.32/042stab076.8/vzkernel-2.6.32-042stab076.8.x86_64.rpm
wget http://download.openvz.org/kernel/branches/rhel6-2.6.32/042stab076.8/vzkernel-devel-2.6.32-042stab076.8.x86_64.rpm
wget http://download.openvz.org/utils/vzctl/4.3.1/vzctl-4.3.1-1.x86_64.rpm
wget http://download.openvz.org/utils/vzctl/4.3.1/vzctl-core-4.3.1-1.x86_64.rpm
wget http://download.openvz.org/utils/ploop/1.7/ploop-1.7-1.x86_64.rpm
wget http://download.openvz.org/utils/ploop/1.7/ploop-lib-1.7-1.x86_64.rpm
wget http://download.openvz.org/utils/vzquota/3.1/vzquota-3.1-1.x86_64.rpm

安装以下软件包...

apt-get install fakeroot alien libcgroup1

...并将RPM包转换为DEB包:

fakeroot alien --to-deb --scripts --keep-version vz*.rpm ploop*.rpm

安装DEB包,如下所示:

dpkg -i vz*.deb ploop*.deb

接下来,我们必须确保在重新启动系统时启动正确的内核(OpenVZ内核)。 在最后一个命令的输出中,您应该看到如下:

Setting up vzkernel (2.6.32-042stab076.8) ...
update-initramfs: Generating /boot/initrd.img-2.6.32-042stab076.8
WARNING: could not open /lib/modules/2.6.32-042stab076.8/modules.builtin: No such file or directory
WARNING: could not open /var/tmp/mkinitramfs_baPCFp/lib/modules/2.6.32-042stab076.8/modules.builtin: No such file or directory
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.0-4-amd64
Found initrd image: /boot/initrd.img-3.2.0-4-amd64
Found linux image: /boot/vmlinuz-2.6.32-042stab076.8
Found initrd image: /boot/initrd.img-2.6.32-042stab076.8
done

这意味着系统上还有另一个内核( 3.2.0 ),而openVZ内核( 2.6.32 )不是列表中的第一个。 因此,为了使OpenVZ内核成为默认内核,我们有两个选项 - 调整GRUB中的默认内核(推荐)或删除非VZ内核。

要调整GRUB中的默认内核,请打开/ etc / default / grub ...

vi /etc/default/grub

...并修改GRUB_DEFAULT行(从0开始计数;因为每个内核也都有一个恢复模式,我们的OpenVZ内核是第三个内核,所以我们需要在这里放入2 ):

[...]
GRUB_DEFAULT=2
[...]

更新GRUB之后:

update-grub

要删除默认内核,请运行...

apt-get remove linux-image-amd64 linux-image-3.2.0-4-amd64

...并更新GRUB:

update-grub

现在我们已经确保正确的内核启动,我们可以继续。

接下来,我们必须检查我们是否在/ etc / fstab中使用UUID而不是设备名称,否则系统可能无法使用openVZ内核引导。 跑...

blkid

...找出您的设备/分区的UUID:

root@server1:/tmp# blkid
/dev/mapper/server1-swap_1: UUID="c465cb44-1bf9-4fbe-bb31-17139fd43004" TYPE="swap"
/dev/sda5: UUID="WRK6Xm-fg52-T836-sp4k-6uxm-trHH-FiRdBx" TYPE="LVM2_member"
/dev/sda1: UUID="46d1bd79-d761-4b23-80b8-ad20cb18e049" TYPE="ext2"
/dev/mapper/server1-root: UUID="d5ac6d76-0b69-46da-b0c1-a4376f2f0e4e" TYPE="ext4"
root@server1:/tmp#

打开/ etc / fstab

vi /etc/fstab

我的原始/ etc / fstab看起来如下(您看到, / boot分区的UUID已经被使用,但是对于/和swap,设备名称正在使用中):

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/mapper/server1-root /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=46d1bd79-d761-4b23-80b8-ad20cb18e049 /boot           ext2    defaults        0       2
/dev/mapper/server1-swap_1 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0

修改它,以便UUID用于所有分区:

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
#/dev/mapper/server1-root /               ext4    errors=remount-ro 0       1
UUID=d5ac6d76-0b69-46da-b0c1-a4376f2f0e4e /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda1 during installation
UUID=46d1bd79-d761-4b23-80b8-ad20cb18e049 /boot           ext2    defaults        0       2
#/dev/mapper/server1-swap_1 none            swap    sw              0       0
UUID=c465cb44-1bf9-4fbe-bb31-17139fd43004 none            swap    sw              0       0
/dev/sr0        /media/cdrom0   udf,iso9660 user,noauto     0       0

确保OpenVZ在启动时自动启动:

update-rc.d vz defaults
update-rc.d vzeventd defaults

接下来我们需要链接几个库:

ln -s /usr/lib64/libvzctl-4.3.1.so /usr/lib
ln -s /usr/lib64/libploop.so /usr/lib

如果要使用ploop容器,请执行以下操作:

apt-get install parted

另外,打开/etc/init.d/vz ...

vi /etc/init.d/vz

...并添加行mkdir $ VARLOCK / ploop ,以确保重新启动后重新创建目录/ var / lock / ploop

#!/bin/sh
#  Copyright (C) 2000-2009, Parallels, Inc. All rights reserved.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# OpenVZ startup script, used for redhat and debian related distributions.

###
# chkconfig: 2345 96 20
# description: OpenVZ startup script.
###

### BEGIN INIT INFO
# Provides: vz
# Required-start: $network $remote_fs $syslog
# Required-stop:  $network $remote_fs $syslog
# Should-Start:  sshd vzeventd
# Should-Stop:  sshd vzeventd
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: OpenVZ startup script
# Description: OpenVZ startup script.
### END INIT INFO


# This line is needed to cheat /etc/init.d/rc who expects action word

. /usr/libexec/vzctl/scripts/initd-functions
mkdir $VARLOCK/ploop
[...]

/ vz创建一个符号链接到/ var / lib / vz以提供向后兼容性:

ln -s /vz /var/lib/vz

打开/etc/sysctl.conf并确保您具有以下设置:

vi /etc/sysctl.conf
[...]
net.ipv4.conf.all.rp_filter=1
net.ipv4.icmp_echo_ignore_broadcasts=1
net.ipv4.conf.default.forwarding=1
net.ipv4.conf.default.proxy_arp = 0
net.ipv4.ip_forward=1
kernel.sysrq = 1
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.eth0.proxy_arp=1
[...]

如果需要修改/etc/sysctl.conf ,请运行

sysctl -p

之后。

如果虚拟机的IP地址与主机系统的IP地址不同,则以下步骤很重要。 如果不这样做,网络将无法在虚拟机中运行!

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

vi /etc/vz/vz.conf
[...]
# Controls which interfaces to send ARP requests and modify APR tables on.
NEIGHBOUR_DEVS=all
[...]

安装vzdump

apt-get install vzdump

最后重新启动系统:

reboot

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

uname -r

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

root@server1:~# uname -r
2.6.32-042stab076.8
root@server1:~#
赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

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

支付宝扫一扫打赏

微信扫一扫打赏