CentOS 6安装OpenVZ可以分为两种方式,第一种比较复杂,使用rpm安装,需要手工的去下载安装包;第二种比较简单,就是通过YUM去安装。

配置YUM

下载openvz.repo文件到/etc/yum.repos.d/目录,通过下面的命令来完成,使用root用户:

# cd /etc/yum.repos.d

# wget http://download.openvz.org/openvz.repo

# rpm --import http://download.openvz.org/RPM-GPG-Key-OpenVZ

安装OpenVZ Kernel运行下面的命令

# yum install [o]vzkernel[-flavor]

对于RHEL6或CentOS6以上的版本,使用vzkernel,对于其它的版本使用ovzkernel,需要注意的是[ –flavor]参数是可选的,可以是-smp或-enterprise,了解更多kernel flavors

配置CentOS内核参数及其SELinux属性

配置OS内核参数,进入/etc/sysctl.conf文件,修改下面两个参数即可

#为了让VE访问外部网络,需要对IP进行转发

net.ipv4.ip_forward = 1

#主要是控制对kernel系统信息的debug功能,具体如何debug,没有深究过

kernel.sysrq = 1

SELinux是2.6版本的Linux内核提供的强制访问控制系统,安装OpenVZ需要将其禁用,进入/etc/sysconfig/selinux文件,按照如下设置

SELINUX=disabled

Reboot OS

重启系统是必须的一步,重启之后OpenVZ的kernel才会生效

安装OpenVZ用户管理工具

有两个工具需要安装:

vzctl:是管理OpenVZ的一个工具,主要功能包含create、destroy、start、stop、set parameters 等

vzquota:管理VZ磁盘配额的一个工具,一般都是有vzctl来调用的

# yum install vzctl vzquota

启动OpenVZ

启动之前可以先检查一下OpenVZ服务时候已经启动了

[root@centos6 ~]# service vz status 

OpenVZ is stopped. 

[root@centos6 ~]# service vz start 

Starting OpenVZ: [ OK ] 

Bringing up interface venet0: [ OK ]

安装VE模版

下载需要安装的模板到/vz/template/cache目录(宿主机是Debain,则需要下载到/var/lib/vz/template/cache/目录)

# cd /vz/template/cache

# wget http://download.openvz.org/template/precreated/centos-6-x86.tar.gz

安装VE需要根据自己对VE的不同要求会有所不同,安装最基本的VE follow下面几步就可以

[root@centos6 ~]# vzctl create 101 --ostemplate centos-6-x86

Creating container private area (centos-6-x86)

Performing postcreate actions

CT configuration saved to /etc/vz/conf/101.conf

Container private area was created

[root@centos6 ~]# vzctl set 101 --hostname centos.ve1 --save

CT configuration saved to /etc/vz/conf/101.conf

[root@centos6 ~]# vzctl set 101 --ipadd 192.168.0.10 --save

CT configuration saved to /etc/vz/conf/101.conf

[root@centos6 ~]# vzctl set 101 --nameserver 192.168.0.1 --save

CT configuration saved to /etc/vz/conf/101.conf

启动VE

[root@centos6 ~]# vzctl start 101

Starting container ...

Container is mounted

Adding IP address(es): 192.168.0.10

Setting CPU units: 1000

Container start in progress...

进入VE

[root@centos6 ~]# vzctl enter 101

entered into CT 101

[root@centos /]#

退出VE

[root@centos /]# exit

logout

exited from CT 101

[root@centos6 ~]# 

停止VE

[root@centos6 ~]# vzctl stop 101

Stopping container ...

Container was stopped

Container is unmounted

销毁VE

[root@centos6 ~]# vzctl destroy 101

Destroying container private area: /vz/private/101

Container private area was destroyed

查看正在宿主机上正在运行的VE

[root@centos6 ~]# vzlist

CTID NPROC STATUS IP_ADDR HOSTNAME

101 17 running 192.168.0.10 centos.ve1

更多OpenVZ使用相关的命令可以参见官方文档

一般我们在宿主机上创建VE都是批量的,因此为了方便在一台Server上创建多个VE,这里提供了一个简单的批量创建脚本。

图形化管理VE

现在主流的有以下三款:()

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 界面

CentOS6安装OpenVZ--转载_OpenVZ

webvz的管理界面

CentOS6安装OpenVZ--转载_VPS_02

webvz 的登录界面

 

补充:OpenVZ官网推荐的管理面板工具:ovz web panel(强大)
参看:http://code.google.com/p/ovz-web-panel/

The most simple way to install OpenVZ Web Panel is to run the following command (under root): 
wget -O - http://ovz-web-panel.googlecode.com/svn/installer/ai.sh | sh 
After installation Panel should be available by the following URL: 
http://<your-host>:3000 
Default administrator's credentials are: admin/admin. Don't forget to change default password.