Published on: October 22, 2014 by Vipin R.N
Scenario:
Scenario
Our requirement is to create VPS from a Node (or Physical server). The Virtualization technology adopted in the Node is OpenVZ (Open Virtuozzo).
OpenVZ
OpenVZ is an Operating System level, container-based Virtualization for Linux. OpenVZ creates multiple secure, isolated Linux containers (otherwise known as VEs or VPSs) on a single physical server enabling better server utilization and ensuring that applications do not conflict. Each container performs and executes exactly like a stand-alone server; a container can be rebooted independently and have root access, users, IP addresses, memory, processes, files, applications, system libraries and configuration files.
Creating a Container
Before we start creating a Container or create VPS, the following prerequisites are to be met :
To create a new Container, we have to:
[root@node /vz/template/cache/]# ls centos-5.0-x86.tar.gz centos-6-x86_64.tar.gz centos-6-x86.tar.gz debian-6.0-x86_64.tar.gz
Now, let’s create the container. The command used to create a container is :-
# vzctl create CTID --ostemplate --config basic
Example :
vzctl create 100 –ostemplate centos-6-x86 –config basic
OR
vzctl create 262 –ostemplate debian-6.0-x86_64 –config basic
Note : When specifying the OS template, make sure to remove the file extension (tar.gz). If you don’t specify the OS Template name, it will try to fetch the parameter in /etc/vz/vz.conf. See the section ## Defaults for containers in that file for more information. It would look like :
## Defaults for containers
VE_ROOT=/vz/root/$VEID
VE_PRIVATE=/vz/private/$VEID
CONFIGFILE=”basic”
DEF_OSTEMPLATE=”centos-5″
With vzctl create command, the container private area is being created. The private area is the directory containing the actual files of the given Container; it is usually residing in /vz/private/CTID/. The private area is mounted to the /vz/root/CTID directory on the Hardware Node and provides Container users with a complete Linux file system tree.
[root@node ~]# ls /vz/root/100/
.autofsck boot/ etc/ lib/ mnt/ proc/ sbin/ srv/ tmp/ var/ bin/ dev/ home/ media/ opt/ root/ selinux/ sys/ usr/[root@node conf]# ls /vz/private/100
bin boot dev etc home lib media mnt opt proc root sbin selinux srv sys tmp usr var
The switch –config basic is specified to choose the basic template configuration which would be usually located at /etc/vz/conf/ve-basic.conf-sample. This file has resource control parameters suitable for most Containers. Obviously these parameters can be changed later.
Creating just the container will not help it function properly. Some inevitable configuration has to be made before we start the container. The Configuration file of a container is located at /etc/vz/conf/CTID.conf where CTID is the container ID. You can either edit the configuration file directly or use vzctl commands to adjust the parameters in any container’s configuration file. Using vzctl commands is more safe because you cannot make any incorrect or invalid parameter in the configuration file. Few essential parameters for a Container are given below.
Add IP Address
Adding an IP address is very much essential. To add an IP address to the Container, use the command
# vzctl set CTID --ipadd <IP Address> --save
Example :
vzctl set 100 –ipadd 8.18.17.48 –save
Note : It is possible to add multiple IP addresses at once or add an entire IP range by using CIDR notation. Make sure that the IP address is free or not used elsewhere.
Assign DNS Server
To set a DNS server to a Container, use the command
# vzctl set CTID --nameserver <NS ADDRESS> --save
Example :
vzctl set 100 –nameserver 8.8.8.8 –save
Disk Space
To set certain amount of Disk space to a Container, use the command
# vzctl set CTID --diskspace <SOFTLIMIT:HARDLIMIT> --save
Example :
vzctl set 100 –diskspace 100G:110G –save
Note : Sufficient Disk space would be allotted to the container by the Basic configuration file. If it is not enough, you can override it.
Hostname
To set the Hostname to a Container, use the command
# vzctl set CTID --hostname <HOSTNAME> --save
Example :
vzctl set 100 –hostname training.supportsages.com –save
Change System Time
Sometimes it may be essential to enable the capability of a container to change its System time. For that use the command
# vzctl set CTID --capability sys_time:on --save
Example :
vzctl set 100 –capability sys_time:on –save
Startup Parameters
It is possible to define the onboot Container startup parameter. Setting this parameter to yes makes the Container automatically boot at the Hardware Node startup.
# vzctl set CTID --onboot yes --save
Example :
vzctl set 100 –onboot yes –save
Starting the Container
Once all the essential parameters are defined, the container can be started. Many options can be set while the container is running. Then it may be necessary to restart the container for the changes to be in effect.
# vzctl start CTID
Example :
vzctl start 100
Checking the Container Status
To see whether our configuration has succeeded, hit vzlist -a. It will display all containers in a node irrespective of the status (Running | Stopped etc)
[root@node ~]# vzlist -a
CTID NPROC STATUS IP_ADDR HOSTNAME
100 26 running 8.18.17.48 training.supportsages.com
101 70 running 8.18.17.1 server.supportsages.com
Stopping the Container
To stop the container, execute
# vzctl stop CTID
Example :
vzctl stop 100
Removing the Container
To remove the container, execute
# vzctl destroy CTID
Example :
vzctl destroy 100
Note : Removing a container will cause complete data loss in it. Ensure that the data is backed up or no longer required. Before removing a container, it has to be stopped as well.
Other Parameters
Various other parameters determining the resource usage can be set in the Container configuration. See this link for complete details.
References / Further Reading
Category : Howtos, Linux, Troubleshooting, VPS
Add new commentSIGN IN