OpenVZ Quick Start Guide for open-source Linux containers

Source: Internet
Author: User
Tags nameserver

OpenVZ Quick Start Guide for open-source Linux containers

  • Introduction to Linux containers and OpenVZ
  • OpenVZ Installation
    • Install the kernel Image
    • Configure sysctl and install related tools
    • Restart OpenVZ Kernel
  • Easy to use
    • Download a pre-prepared template, also known as an image
    • Create and configure container Information
    • Start running and use

Introduction to Linux containers and OpenVZ

Linux Container (LXC) is a lightweight virtual operating environment
Type is different. Traditional virtual machines need to abstract hardware and provide a complete operating system.
In other words, multiple containers share a kernel mechanism with the system, while only the files required by the runtime environment are provided in the container.
System, virtual network, etc.

Specific architecture:

As shown in, OpenVZ is a container implementation method. There are other containers, such as LXC tool (this tool can be used to create the LXC runtime environment, Docker can be said to be based on LXC tool). This blog will conduct in-depth analysis in the future.

OpenVZ has earlier container technology practices. Many of the mechanisms used in the kernel to implement LXC come from them. Currently, many features of OpenVZ are modified based on the RHEL6 kernel (kernel version 2.6.32, some of the new features are not added to the mainstream kernel, so we recommend that you use the OpenVZ kernel to achieve better container features, such as isolation and snapshot.

OpenVZ Installation

By default, Debian7 (wheezy) does not support OpenVZ (I do not know if it is due to kernel version issues or other problems)
But the OpenVZ team added support for Debian7. We can install the Linux kernel mirrors they provide.
For details about how to complete the installation, refer to [1] [3].

1. Install the kernel Image

As in the previous section, you need to install the kernel image provided by OpenVZ On Debian 7 to fully support OpenVZ. The method is as follows:

1.1 add and update the source (the root permission is required for the following operations)

`# cat << EOF > /etc/apt/sources.list.d/openvz.list deb http://download.openvz.org/debian wheezy main deb http://download.openvz.org/debian wheezy-test main EOF # apt-get update`

1.2 install the kernel Image

'# Apt-get install linux-image-openvz-amd64 # apt-get install linux-image-openvz-686 (if you still use 32-bit Systems )'
2. Configure sysctl and install related tools

After the OpenVZ kernel image is installed, the following configurations are required before restart.

2.1 some kernel parameters need to be configured to ensure the normal operation of OpenVZ. The configuration file is "/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

2.2 install some user space tools

# apt-get install vzctl vzquota ploop vzstats

3. Restart to the OpenVZ kernel.

After the configuration and related software are installed, restart the kernel to the OpenVZ kernel.

Easy to use

For such a Linux container that can provide a complete system running environment, you have to take a look. For more information, see [2] [4].

1. Download the pre-prepared template (also known as an image)

1.1 download the template you need from the official website [5] [6]

1.2 move the downloaded template to the desired path

# mv ubuntu-14.04-x86.tar.gz /var/lib/vz/template/cache/

2. Create and configure container Information

# vzctl create CTID --ostemplate osname
# vzctl set CTID --hostname test --save
# vzctl set CTID --ipadd a.b.c.d --save
# vzctl set CTID --nameserver a.b.c.d --save

For example:

# vzctl create 111 --ostemplate ubuntu-14.04-x86
# vzctl set 111 --hostname ubuntu --save
# vzctl set 111 --ipadd 192.168.2.233 --save
# vzctl set 111 --nameserver 192.168.2.1 --save

3. Start running and use

# vzctl start CTID
# vzctl exec CTID ps ax # Now the container is running!
# vzctl enter CTID
entered into container CTID
[container]# ...
[container]# exit
exited from container VEID
# vzctl stop CTID
# vzctl destroy CTID

For example:

# vzctl start 111
# vzctl enter 111
[container]# do something (default is root)
[container]# exit
# vzctl stop 111

[1] https://wiki.openvz.org/Installation_on_Debian
Http://openvz.livejournal.com/45345.html
[2] https://wiki.openvz.org/Basic_operations_in_OpenVZ_environment
[3] http://download.openvz.org/doc/openvz-intro.pdf
[4] http://download.openvz.org/doc/OpenVZ-Users-Guide.pdf
[5] http://download.openvz.org/template/precreated/
[6] http://openvz.org/Download/template/precreated

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.