欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

CentOS 安装 OpenVZ

程序员文章站 2022-06-04 19:55:50
...

下载openvz.repo 到 /etc/yum.repos.d/

wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo

导入OpenVZ 的GPG key用于 标记RPM包

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

安装OpenVZ的Kernel
Limited OpenVZ functionality is supported when you run a recent 3.x kernel (check vzctl for upstream kernel, so OpenVZ kernel installation is optional but still recommended.

# yum install vzkernel

============================================================================================================================================================================
 Package                                  Arch                            Version                                        Repository                                    Size
============================================================================================================================================================================
Installing:
 vzkernel                                 x86_64                          2.6.32-042stab113.11                           openvz-kernel-rhel6                           33 M
Updating for dependencies:
 kernel-firmware                          noarch                          2.6.32-573.12.1.el6                            updates                                       18 M

Transaction Summary
============================================================================================================================================================================
Install       1 Package(s)
Upgrade       1 Package(s)


Downloading Packages:
(1/2): kernel-firmware-2.6.32-573.12.1.el6.noarch.rpm                                                                                                |  18 MB     03:58     
(2/2): vzkernel-2.6.32-042stab113.11.x86_64.rpm                                                                                                      |  33 MB     09:55  
Running Transaction
  Updating   : kernel-firmware-2.6.32-573.12.1.el6.noarch                                                                                                               1/3 
  Installing : vzkernel-2.6.32-042stab113.11.x86_64                                                                                                                     2/3 
  Cleanup    : kernel-firmware-2.6.32-573.el6.noarch                                                                                                                    3/3 
  Verifying  : kernel-firmware-2.6.32-573.12.1.el6.noarch                                                                                                               1/3 
  Verifying  : vzkernel-2.6.32-042stab113.11.x86_64                                                                                                                     2/3 
  Verifying  : kernel-firmware-2.6.32-573.el6.noarch                                                                                                                    3/3 

Installed:
  vzkernel.x86_64 0:2.6.32-042stab113.11                                                                                                                                    

Dependency Updated:
  kernel-firmware.noarch 0:2.6.32-573.12.1.el6                                                                                                                              

Complete!

系统配置
配置完成之前不要重启OpenVZ kernel

配置sysctl.conf

There are a number of kernel parameters that should be set for OpenVZ to work correctly. These parameters are stored in /etc/sysctl.conf file. Here are the relevant portions of the file; please edit accordingly.

vi /etc/sysctl.conf

# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
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

设置防火墙为disabled

vi /etc/sysconfig/selinux

SELINUX=disabled

安装Tools
OpenVZ needs some user-level tools installed:

# yum install vzctl vzquota ploop

Downloading Packages:
(1/7): e2fsprogs-resize2fs-static-1.42.11-1.ovz.x86_64.rpm                                                                                           |  77 kB     00:02     
(2/7): ploop-1.14.1-1.x86_64.rpm                                                                                                                     |  59 kB     00:00     
(3/7): ploop-lib-1.14.1-1.x86_64.rpm                                                                                                                 | 160 kB     00:00     
(4/7): vzctl-4.9.4-1.x86_64.rpm                                                                                                                      | 145 kB     00:00     
(5/7): vzctl-core-4.9.4-1.x86_64.rpm                                                                                                                 | 289 kB     00:07     
(6/7): vzquota-3.1-1.x86_64.rpm                                                                                                                      |  93 kB     00:05     
(7/7): vzstats-0.5.3-1.noarch.rpm                                                                                                                    |  23 kB     00:00     
Total                                                                                                                                        37 kB/s | 847 kB     00:23     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : vzstats-0.5.3-1.noarch                                                                                                                                   1/7 
  Installing : vzquota-3.1-1.x86_64                                                                                                                                     2/7 
  Installing : vzctl-core-4.9.4-1.x86_64                                                                                                                                3/7 
Invalid UUID , aborting
  Installing : e2fsprogs-resize2fs-static-1.42.11-1.ovz.x86_64                                                                                                          4/7 
  Installing : ploop-lib-1.14.1-1.x86_64                                                                                                                                5/7 
  Installing : ploop-1.14.1-1.x86_64                                                                                                                                    6/7 
  Installing : vzctl-4.9.4-1.x86_64                                                                                                                                     7/7 
============================================================================
Adding the following option to /etc/modprobe.d/openvz.conf:

    options nf_conntrack ip_conntrack_disable_ve0=0

This change will take effect only after the next reboot.

NOTE: if you need to change this setting, edit /etc/modprobe.d/openvz.conf
now. DO NOT REMOVE the line, or it will be re-added!
============================================================================
vz-postinstall: /etc/yum.conf: add exclude=kernel
  Verifying  : e2fsprogs-resize2fs-static-1.42.11-1.ovz.x86_64                                                                                                          1/7 
  Verifying  : vzctl-4.9.4-1.x86_64                                                                                                                                     2/7 
  Verifying  : vzctl-core-4.9.4-1.x86_64                                                                                                                                3/7 
  Verifying  : vzquota-3.1-1.x86_64                                                                                                                                     4/7 
  Verifying  : ploop-1.14.1-1.x86_64                                                                                                                                    5/7 
  Verifying  : ploop-lib-1.14.1-1.x86_64                                                                                                                                6/7 
  Verifying  : vzstats-0.5.3-1.noarch                                                                                                                                   7/7 

Installed:
  ploop.x86_64 0:1.14.1-1                                  vzctl.x86_64 0:4.9.4-1                                  vzquota.x86_64 0:3.1-1                                 

Dependency Installed:
  e2fsprogs-resize2fs-static.x86_64 0:1.42.11-1.ovz           ploop-lib.x86_64 0:1.14.1-1           vzctl-core.x86_64 0:4.9.4-1           vzstats.noarch 0:0.5.3-1          

Complete!

重启进入OpenVZ kernel

reboot

下载OS templates
An OS template is a Linux distribution installed into a container and then packed into a gzipped tarball. Using such a cache, a new container can be created in a minute.

镜像下载地址: https://download.openvz.org/template/precreated/
所有镜像地址: https://openvz.org/Download_mirrors

Put those tarballs as-is (no unpacking needed) to the /vz/template/cache/ directory.

安装成功

相关标签: openvz