CentOS Linux安装OpenVZ虚拟化软件

时间:2020-01-09 10:43:27  来源:igfitidea点击:

如何在Red Hat Enterprise Linux或者CentOS Linux 5.x服务器下安装OpenVZ虚拟化容器软件?
可以使用yum命令本身安装OpenVZ。
您所要做的就是设置正确的存储库。

步骤1:设置Yum Repo

执行以下命令。
光盘到/etc/yum.repos.d

# cd /etc/yum.repos.d

下载Repo文件:

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

最后,导入GPG密钥:

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

步骤2:更新内核配置

执行以下命令以安装OpenVZ Linux内核以安装64位smp内核(最大支持64 GB的RAM):

# yum install ovzkernel

输出示例:

Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* addons: centose.centos.org
* updates: centosh3.centos.org
* extras: centose.centos.org
* rpmforge: apt.sw.be
* base: centose.centos.org
* openvz-kernel-rhel5: mirrors.nullroute.me
* openvz-utils: mirrors.nullroute.me
396 packages excluded due to repository priority protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package ovzkernel.i686 0:2.6.18-128.1.1.el5.028stab062.3 set to be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package                        Arch                      Version                                              Repository                                Size
==============================================================================================================================================================
Installing:
ovzkernel                      i686                      2.6.18-128.1.1.el5.028stab062.3                      openvz-kernel-rhel5                       19 M

Transaction Summary
==============================================================================================================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 19 M
Is this ok [y/N]: y
Downloading Packages:
ovzkernel-2.6.18-128.1.1.el5.028stab062.3.i686.rpm                                                                                     |  19 MB     00:16     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : ovzkernel                                         [1/1] 

Installed: ovzkernel.i686 0:2.6.18-128.1.1.el5.028stab062.3
Complete!

或者,执行以下命令以安装SMP + PAE支持+ 4/4GB拆分(最大支持64 GB RAM)内核:

# yum install ovzkernel-ent

您可以安装以下内核:

  • ovzkernel:Virtuozzo Linux内核(Linux操作系统的核心)
  • ovzkernel-PAE:为支持PAE的机器编译的Linux内核。
  • ovzkernel-PAE-devel:用于构建内核模块以匹配PAE内核的开发包。
  • ovzkernel-devel:用于构建内核模块以匹配内核的开发包。
  • ovzkernel-ent:Linux内核,用于支持大型内存的计算机。
  • ovzkernel-ent-devel:用于构建内核模块以匹配ent内核的开发包。
  • ovzkernel-xen:为Xen VM操作而编译的Linux内核
  • ovzkernel-xen-devel:用于构建内核模块以匹配内核的开发包。

更新/etc/sysctl.conf

OpenVZ内核已安装并更新了GRUB配置,即在重启后,OpenVZ内核会自动启动。
但是,您需要对内核配置进行一些更改。
编辑/etc/sysctl.conf:

# vi /etc/sysctl.conf

设置参数如下:

# Enable packet forwarding enabled 
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
# Disable proxy arp 
net.ipv4.conf.default.proxy_arp = 0
# Enables source route verification
net.ipv4.conf.all.rp_filter = 1
# Enables the magic-sysrq key
kernel.sysrq = 1
# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

保存并关闭文件。

禁用SELinux

您必须通过编辑/etc/sysconfig/selinux来禁用SELinux:

# vi /etc/sysconfig/selinux

放置以下指令:

SELINUX=disabled

保存并关闭文件。

安装VZ实用程序

执行以下命令:

# yum install vzctl vzquota

输出示例:

Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* addons: centosj-msync-dvd.centos.org
* updates: centosh3.centos.org
* extras: centose.centos.org
* rpmforge: apt.sw.be
* base: centosj3.centos.org
* openvz-kernel-rhel5: openvz.mirrors.skynet.be
* openvz-utils: openvz.mirrors.skynet.be
396 packages excluded due to repository priority protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package vzquota.i386 0:3.0.12-1 set to be updated
---> Package vzctl.i386 0:3.0.23-1 set to be updated
--> Processing Dependency: vzctl-lib = 3.0.23-1 for package: vzctl
--> Processing Dependency: libvzctl-0.0.2.so for package: vzctl
--> Running transaction check
---> Package vzctl-lib.i386 0:3.0.23-1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================================================================================================
Package                               Arch                             Version                                Repository                                Size
==============================================================================================================================================================
Installing:
vzctl                                 i386                             3.0.23-1                               openvz-utils                             143 k
vzquota                               i386                             3.0.12-1                               openvz-utils                              82 k
Installing for dependencies:
vzctl-lib                             i386                             3.0.23-1                               openvz-utils                             175 k

Transaction Summary
==============================================================================================================================================================
Install      3 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 400 k
Is this ok [y/N]: y
Downloading Packages:
(1/3): vzquota-3.0.12-1.i386.rpm                                                                                                       |  82 kB     00:00     
(2/3): vzctl-3.0.23-1.i386.rpm                                                                                                         | 143 kB     00:00     
(3/3): vzctl-lib-3.0.23-1.i386.rpm                                                                                                     | 175 kB     00:00     
-------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                          40 kB/s | 400 kB     00:09     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : vzctl-lib                                         [1/3] 
  Installing     : vzquota                                           [2/3] 
  Installing     : vzctl                                             [3/3] 

Installed: vzctl.i386 0:3.0.23-1 vzquota.i386 0:3.0.12-1
Dependency Installed: vzctl-lib.i386 0:3.0.23-1
Complete!

重新启动服务器

最后,重新启动您的机器并启动到新的OpenVZ内核中:

# reboot