【www.shanpow.com--简历下载】
openVZ一:OpenVZ首页、文档和下载

6月14日上海 OSC 源创会开始报名,送机械键盘和开源无码内裤
OpenVZ是基于Linux内核和作业系统的操作系统级虚拟化技术。OpenVZ允许物理服务器运行多个操作系统,被称虚拟专用服务器(VPS,Virtual Private Server)或虚拟环境(VE, Virtual Environment)。
与VMware这种虚拟机和Xen这种半虚拟化技术相比,OpenVZ的host OS和guest OS都必需是Linux(虽然在不同的虚拟环境里可以用不同的Linux发行版)。但是,OpenVZ声称这样做有性能上的优势。根据OpenVZ网站的说法,使用OpenVZ与使用独立的服务器相比,性能只会有1-3%的损失。
OpenVZ是SWsoft, Inc.公司开发的专有软件Virtuozzo的基础。OpenVZ的授权为GPLv2。
OpenVZ由两部分组成,一个经修改过的操作系统核心与及用户工具。
openVZ二:在CentOS 6.4上安装并使用OpenVZ

官方网站:https://openvz.org/Quick_installation
【51CTO精选译文】在本篇指导文章中,我将向大家介绍如何为OpenVZ创建一套CentOS 6.4服务器。在OpenVZ的帮助下,大家可以在同一套硬件上获得多套虚拟私有服务器(简称VPS),这跟Xen以及Linux Vserver项目颇为相似。OpenVZ是Virtuozzo的开源分支,作为家族长辈,Virtuozzo以商业虚拟化方案的姿态出现在很多提供虚拟服务器业务的供应商处。OpenVZ内核补丁以GPL许可为基础,而用户层工具则基于QPL许可。
由于采取实用性指南的定位,这篇文章不会包含任何理论背景知识。网络上背景知识方面的资源已经非常丰富,这里我们就不再赘述。这份文档不向大家提供任何效果保证,仅仅作为参考性材料存在。以下流程是否实际生效需视具体情况而定。
安装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-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-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内核(欲了解不同内核的具体情况,请访问http://wiki.openvz.org/Kernel_flavors进行查看)。以下命令:
yum search vzkernel
将在屏幕上列出所有可用内核:
[root@server1 yum.repos.d]# yum search vzkernel
[...]
vzkernel.i686 : The Linux kernel
vzkernel.x86_64 : The Linux 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-firmware.noarch : Firmware files used by the Linux 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内核了。务必确保default值为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/mapper/vg_server1-lv_root
# initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title OpenVZ (2.6.32-042stab057.1)
root (hd0,0)
kernel /vmlinuz-2.6.32-042stab057.1 ro root=/dev/mapper/vg_server1-lv_root rd_LVM_LV=vg_server1/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=autoKEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=vg_server1/lv_swap rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-042stab057.1.img
title CentOS (2.6.32-279.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-279.el6.x86_64 ro root=/dev/mapper/vg_server1-lv_root rd_LVM_LV=vg_server1/lv_root rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=autoKEYBOARDTYPE=pc KEYTABLE=de rd_LVM_LV=vg_server1/lv_swap rd_NO_DM rhgb quiet
initrd /initramfs-2.6.32-279.el6.x86_64.img
现在我们需要安装几款OpenVZ用户工具:
yum install vzctl vzquota ploop
打开/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 设置为 all:
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 - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
最后,重新启动系统:
reboot
如果大家的系统顺利完成了重启,那么恭喜--安装工作成功结束!
运行:
uname -r
这时我们的新OpenVZ内核应该显示以下内容:
[root@server1 ~]# uname -r
2.6.32-042stab057.1
[root@server1 ~]#
在利用OpenVZ创建虚拟机之前,我们需要在/vz/template/cache目录下为所要用到的发行版添加一套模板,这套模板将负责虚拟机的生成工作。大家可以在以下地址中找到预创建模板清单:http://wiki.openvz.org/Download/template/precreated)。
我打算在自己的虚拟机中使用CentOS 6,所以我需要下载CentOS 6模板:
cd /vz/template/cache
wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz
现在我要向大家展示使用OpenVZ所涉及的基本命令。
要通过CentOS 6模板建立一套VPS,需要运行:
vzctl create 101 --ostemplate centos-6-x86_64 --config basic
这里的101必须是单独ID--每套虚拟机都需要拥有专属的独立ID。大家可以利用虚拟机IP地址的最后三位数字来为其命名。举例来说,如果虚拟机IP地址为192.168.0.101,那么其ID为101即可。
如果大家希望在系统启动时自动运行虚拟机,则执行以下命令:
vzctl set 101 --onboot yes --save
要为虚拟机设定主机名称与IP地址,则运行以下命令:
vzctl set 101 --hostname test.example.com --save
vzctl set 101 --ipadd 192.168.0.101 --save
接下来我们将套接口数量设置为120,并为虚拟机指派数个域名服务器:
vzctl set 101 --numothersock 120 --save
vzctl set 101 --nameserver 8.8.8.8 --nameserver 8.8.4.4 --nameserver 145.253.2.75 --save
(请注意,这里我们也可以使用vzctl set命令或者直接对/etc/vz/conf目录下的虚拟机配置文件进行编辑。如果虚拟机ID为 101, 那么配置文件的路径应为/etc/vz/conf/101.conf。)
运行以下命令来启动虚拟机:
vzctl start 101
执行以下命令为虚拟机设定root密码:
vzctl exec 101 passwd
大家现在已经可以通过SSH(例如PuTTY)或者手动输入以下命令的方式与虚拟机连通:
vzctl enter 101
是退出虚拟机控制台,可直接输入:
exit
停止虚拟机运行,运行:
vzctl stop 101
重启虚拟机则运行:
vzctl restart 101
如果需要从磁盘中删除虚拟机(前提是我们已经停止了该虚拟机的运行),执行以下命令:
vzctl destroy 101
要列出当前虚拟机清单及其运行状态,需运行:
vzlist -a
[root@server1 cache]# vzlist -a
CTIDNPROC STATUSIP_ADDR HOSTNAME
101 14 running 192.168.0.101 test.example.com
[root@server1 cache]#
要查看被指派给对应虚拟机的资源,需运行:
vzctl exec 101 cat /proc/user_beancounters
[root@server1 cache]# vzctl exec 101 cat /proc/user_beancounters
Version: 2.5
uidresource heldmaxheldbarrierlimitfailcnt
101:kmemsize15082021661695 11055923 113770490
lockedpages 002562560
privvmpages5430 710265536696320
shmpages38138121504215040
dummy 00000
numproc19 212402400
physpages2489 27750 21474836470
vmguarpages 0033792 21474836470
oomguarpages 2489 277526112 21474836470
numtcpsock553603600
numflock341882060
numpty01 16 160
numsiginfo022562560
tcpsndbuf 447200172032027033600
tcprcvbuf 819200172032027033600
othersockbuf1314414356112608020971520
dgramrcvbuf 0 8380 262144 2621440
numothersock 11 131201200
dcachesize00340992036249600
numfile 503531 9312 93120
dummy 00000
dummy 00000
dummy 00000
numiptent10 101281280
[root@server1 cache]#
failcnt这一列的信息非常重要,正常来说所有数值都应该为0;如果出现非0数字,则代表当前虚拟机所拥有的资源不足、我们需要为其分配更多资源。打开/etc/vz/conf目录下的虚拟机配置文件,提高对应资源数量,最后重新启动虚拟机。
如果大家还需要进行其它操作,可以运行下列命令以查看vzctl的所有操作指令:
man vzctl
openVZ三:OpenVZ 统一管理平台配置

管理OpenVZ可以通过命令,或者是第三方开发的管理网站。现在主流的有以下三款:
Webvz 2.0 http://webvz.sourceforge.net/
Vtonf http://www.vtonf.com/
HyperVM 2.0 http://lxlabs.com/software/hypervm/
这些第三方开发的管理网站都十分出色,其中WebVZ 2.0 最节省VE资源以及功能基本符合要求,使用简洁。
如果需要功能强大的集群技术可以使用HyperVM 2.0但这东东有限制,需要购买哦~~!
一、安装Webvz 2.0
A. 安装数据库 sqlite
#yum install python-sqlite sqlite-devel sqlite
B. 安装ruby
#yum install ruby ruby-irb ruby-libs ruby-devel ruby-rdoc
C. 安装rubygems
yum –y install rubygems
D.安装rails
#gem install -v=2.1.0 rails -y
这里要注意哦!第一次安装的时候会出现错误,但你在安装多一次就可以成功了。@_@ 晕~~ 我也不知道为何?
E.安裝sqlite3-ruby
#gem install sqlite3-ruby
F.安装webvz 2.0
http://sourceforge.net/project/showfiles.php?group_id=218223
把它解压把
#mkdir /var/srv/www
#tar -zxf webvz.2.0.tar.gz –C/var /srv/www
启动Webvz 2.0
#ruby /var /srv/www/webvz.2.0/script/server -d
#echo "ruby /var /srv/www/webvz.2.0/script/server -d" >> /etc/rc.d/rc.local
登入Webvz 2.0
http://your-server-ip:3000
用户名: admin
密码 : admin123
Webvz的登录界面
Webvz的management 界面

