在CentOS 4.4上安装配置OpenVZ

In this HowTo I will describe how to prepare a CentOS 4.4 server for OpenVZ virtual machines. With OpenVZ you can create multiple Virtual Private Servers (VPS) on the same hardware, similar to Xen and the Linux Vserver project. OpenVZ is the open-source branch of Virtuozzo, a commercial virtualization solution used by many providers that offer virtual servers.
0. Minimum Requirements
    - Hardware
    - Software
    - Other
1. Installing and Configuring Host Operating System on Hardware Node
Step #1 �C Install the Base System
Step #2 �C Disk Partitioning
Step #3 �C Configuring Grub, Network and Security
Step #4 �C Other Settings
Step #5 �C Package Selection and Finalizing the system
Step #6 - Post Installation
2. Installing and Configuring OpenVZ Kernel
Step #7 - Downloading and Installing OpenVZ Kernel
Step #8 - Configuring the bootloader
Step #9 - Configuring sysctl
Step #10 - Configuring SELinux
Step #11 - Conntracks
Step #12 - Rebooting into OpenVZ kernel
Step #13 - Installing the utilities
Step #14 - Starting OpenVZ
3. OS template cache preparation
Step #15 - Installing template utilities
Step #16 - Installing OS template metadata
Step #17 - Installing repository cache (optional)
4. VE Creation and other oprations with VEs
Step #19 �C Creating VE
Step #20 �C Adding IP(s) to VE
Step #21 �C Starting VE
Step #22 �C Running ps command from Hardware Node
Step #23 - Entering VE
Step #24 - Exiting from VE
Step #25 - Stopping VE
Step #26 - Destroying VE

0. Minimum Requirements

- Hardware
    Pentium based cpu, 256 MB RAM, 6
- Software
    Any Linux distribution ( Preferred CentOS )
- Other
    NIC and Internet Connection

1. Installing and Configuring Host Operating System on Hardware Node

This section explains how to install Fedora Core 4 on the Hardware Node and how to configure it for OpenVZ. If you are using another distribution, please consult the corresponding installation guides about the installation specifics.

Info: Download the 4 CentOS 4.4 CD iso images from a mirror near you (the list of mirrors can be found here: http://www.centos.org/modules/tinycontent/index.php?id=13).

Step #1 �C Install the Base System

Boot from your CentOS 4.4 CD (CD 1). / DVD
在CentOS 4.4上安装配置OpenVZ_第1张图片
It can take a long time to test the installation media so we skip this test here:
The welcome screen of the CentOS installer appears. Click on Next:
Choose your language next:
Select your keyboard layout:
We want to install a server so we choose Server here:

Step #2 �C Disk Partitioning

On the Disk Partitioning Setup screen, select Manual partition with Disk Druid. Do not choose automatic partitioning since this type of partitioning will create a disk layout intended for systems running multiple services. In case of OpenVZ, all your services shall run inside Virtual Private Servers.
I'm installing CentOS 4.3 on a fresh system, so I answer Yes to the question Would you like to initialize this drive, erasing ALL DATA?
Select Remove all partitions on this system.
We want to remove all Linux partitions, so we answer Yes to the following question:
Create the following partitions on the Hardware Node:
For example: 
Partition FS Type  Typical size Description
/ ext3 2-4 Gb Root partition for Hardware Node OS files
swap swap 2 times RAM Paging partition for the Linux OS
/vz ext3 Rest of available Space  Partition to host OpenVZ templates and VPSs

Step #3 �C Configuring Grub, Network and Security

Now the boot loader GRUB will be installed. You can leave the default settings unchanged and click on Next:
On to the network settings. The default setting here is to configure the network interfaces with DHCP, but we are installing a server, so static IP addresses are not a bad idea... Click on the Edit button at the top right. In the window that pops up uncheck Configure using DHCP and give your network card a static IP address (in this tutorial I'm using the IP address 192.168.0.100 for demonstration purposes):
Set the hostname manually, e.g. server1.example.com, and enter a gateway (e.g. 192.168.0.1) and up to three DNS servers (e.g. 145.253.2.75, 193.174.32.18, and 194.25.0.60):
SELinux is a security extension of CentOS that should provide extended security. In my opinion you don't need it to configure a secure system, and it usually causes more problems than advantages
Click on Proceed:

Step #4 �C Other Settings

Select the default language for the system and add further languages, if necessary:
Choose your time zone:
Give root a password:

Step #5 �C Package Selection and Finalizing the system

Now we are to select the package groups. Uncheck packages on the server group. Install a bare OS without any applications
The installer tells you which CDs it will need to install the selected packages:
The installation begins. This will take a few minutes:
Finally, the installation is complete, and you can remove your CD from the computer and reboot it:

Step #6 - Post Installation

yum update -y
shutdown now -r

2. Installing OpenVZ Kernel

Step #7 - Downloading and Installing OpenVZ Kernel

# cd /etc/yum.repos.d
# wget http://download.openvz.org/openvz.repo
# yum install ovzkernel

Step #8 - Configuring the bootloader

In case GRUB is used as the boot loader, it will be configured automatically: lines similar to these will be added to the /boot/grub/grub.conf file:
title Cent OS (2.6.8-022stab029.1)
       root (hd0,0)
       kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5 quiet rhgb vga=0x31B
       initrd /initrd-2.6.8-022stab029.1.img
Change Cent OS to OpenVZ (just for clarity reasons, so the OpenVZ kernels will not be mixed up with non OpenVZ ones). Remove extra arguments from the kernel line, leaving only the root=... parameter. The modifed portion of /etc/grub.conf should look like this:
title OpenVZ (2.6.8-022stab029.1)
        root (hd0,0)
        kernel /vmlinuz-2.6.8-022stab029.1 ro root=/dev/sda5
        initrd /initrd-2.6.8-022stab029.1.img

Step #9 - Configuring sysctl

There is a number of kernel parameters that should be set for OpenVZ to work correctly. These parameters are stored in /etc/sysctl.conf file. Here is the relevant part of the file; please edit it accordingly.
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 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
# TCP Explict Congestion Notification
#net.ipv4.tcp_ecn = 0
# we do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

Step #10 - Configuring SELinux

SELinux should be disabled. To that effect, put the following line to /etc/sysconfig/selinux:
SELINUX=disabled

Step #11 - Conntracks

In the stable OpenVZ kernels (those that are 2.6.8-based) netfilter connection tracking for VE0 is disabled by default. If you have a stateful firewall enabled on the host node (it is there by default) you should either disable it, or enable connection tracking for VE0.

To enable conntracks for VE0, add the following line to /etc/modprobe.conf file:
options ip_conntrack ip_conntrack_enable_ve0=1
Note: in kernels later than 2.6.8, connection tracking is enabled by default

Step #12 - Rebooting into OpenVZ kernel

Now reboot the machine and choose "OpenVZ" on the boot loader menu. If the OpenVZ kernel has been booted successfully, proceed to installing the user-level tools for OpenVZ.

Step #13 - Installing the utilities

OpenVZ needs some user-level tools installed. Those are:
vzctl - A utility to control OpenVZ VPSs (create, destroy, start, stop, set parameters etc.)
vzquota - A utility to manage quotas for VPSs. Mostly used indirectly (by vzctl).
# yum install vzctl vzquota

Step #14 - Starting OpenVZ

# /sbin/service vz start
Note: OpenVZ is now set up on your machine. To load OpenVZ kernel by default, edit the default line in the /boot/grub/grub.conf file to point to the OpenVZ kernel. For example, if the OpenVZ kernel is the first kernel mentioned in the file, put it as default 0. See man grub.conf for more details.

3. OS template cache preparation

Step #15 - Installing template utilities

# yum install vzpkg vzyum vzrpm43-python vzrpm44-python

Step #16 - Installing OS template metadata

# yum search vztmpl
# yum install vztmpl-XXX [...]
Eg:
yum install vztmpl-centos-4.i386

Step #17 - Installing repository cache (optional)

vzpkgcache

Step #18 - Alternative: use precreated template cache

cd /vz/template/cache
Download Precreated Templates from: http://download.openvz.org/template/precreated/

4. VE Creation and other oprations with VEs

Step #19 �C Creating VE

[host-node]# vzctl create 112 --ostemplate centos-4-i386-default

Step #20 �C Adding IP(s) to VE

[host-node]# vzctl set 112 --ipadd 192.168.6.112 --save

Step #21 �C Starting VE

[host-node]# vzctl start 112

Step #22 �C Running ps command from Hardware Node

Your freshly-created VE should be up and running now; you can see its processes:
[host-node]# vzctl exec VEID ps ax

Step #23 - To enter VE give the following command:

[host-node]# vzctl enter VEID
entered into VPS VEID
[ve]#

Step #24 - To exit from VE, just type exit and press enter:

[ve]# exit
exited from VPS VEID

[host-node]#

Step #25 - To stop VE:

[host-node]# vzctl stop VEID
Stopping VPS ...
VPS was stopped
VPS is unmounted

Step #26 - To destroy VE:

[host-node]# vzctl destroy VEID

Destroying VPS private area: /vz/private/VEID
VPS private area was destroyed

你可能感兴趣的:(centos,职场,openvz,休闲)