Contents...
In OpenVZ containers also known as Virtual Machine or VPS. Containers share the resources of the physical machine. Means a particular amount of Disk space and RAM will not be allocated to any particular VPS (Container). Resources pool equally shared by all Containers on demand.
OpenVZ provides templates for all Linux distributions. You will need to download those templates to create a container or VPS.
Download CentOS Linux VPS
Follow the below command to download the CentOS Linux template.
# cd /vz/template/cache # wget http://download.openvz.org/template/precreated/ centos-6-x86_64.tar.gz.tar
Create Container
Note : 145143 is Container ID
After downloaded virtual machine template. Follow the below commands to create first VPS.
# vzctl create 145143 --ostemplate centos-6-x86_64
You will get some output like below:
Creating container private area (centos-6-x86_64) Performing postcreate actions CT configuration saved to /etc/vz/conf/145143.conf
Set IP Address
Now set the IP address to the container for example : 10.12.145.143.
# vzctl set 145143 --ipadd 10.12.145.143 --save CT configuration saved to /etc/vz/conf/145143.conf
Set DNS Server
# vzctl set 145143 --nameserver 10.0.80.11 --save CT configuration saved to /etc/vz/conf/145143.conf
Start Container Onboot
# vzctl set 145143 --onboot yes --save UB limits were set successfully CT configuration saved to /etc/vz/conf/145141.conf
Set Disk Space
# vzctl set 145143 --diskspace 50G:51G --save CT configuration saved to /etc/vz/conf/145143.conf
Set Memory and Swap
# vzctl set 145143 --ram 2G --swap 512M --save CT configuration saved to /etc/vz/conf/145143.conf
Set Hostname
# vzctl set 145143 --hostname vsrv71.looklinux.com --save CT configuration saved to /etc/vz/conf/145143.conf
That’s it. Your container is ready to work just restart it. You can also set some other options like below if you want.
Set Root Password
# vzctl set 145143 --userpasswd root:redhat@123
Set CPUs
# vzctl set 145143 --cpus 4 --save
Set CPU Units
# vzctl set 145143 --cpuunits 100000 –save
Set CPU Limit
# vzctl set 145143 --cpulimit 4 --save
Start Container
# vzctl start 145143 Starting container... Container is mounted Adding IP address(es): 10.12.145.143 Setting CPU units: 1000 Container start in progress...
OR
Start Container In Verbose mode
# vzctl --verbose --verbose stop 145143
You will get some output like below:
Starting container... Running: /usr/sbin/vzquota show 145143 Running: /usr/sbin/vzquota on 145143 -b 8388708 -B 9437284 -i 131172 -I 144279 -e 0 -n 0 -s 0 Mounting root: /vz/root/145143 /vz/private/145143 Running: /etc/vz/conf/vps.mount Container is mounted Adding IP address(es): 10.12.145.143 Running: /usr/libexec/vzctl/scripts/vps-net_add Running container script: /etc/vz/dists/scripts/redhat-add_ip.sh Setting CPU units: 1000 Running container script: /etc/vz/dists/scripts/set_console.sh Running container script: /etc/vz/dists/scripts/redhat-set_hostname.sh Running container script: /etc/vz/dists/scripts/set_dns.sh Running: /usr/sbin/vzquota stat 145141 -f Running: /usr/sbin/vzquota setlimit 145143-b 8388608 -B 9437184 -i 131072 -I 144179 -e 0 -n 0 Running container script: /etc/vz/dists/scripts/prestart.sh Container start in progress...
Listing Container
# vzlist -a CTID NPROC STATUS IP_ADDR HOSTNAME 145143 19 running 10.12.145.143 vsrv71.looklinux.com
Stop/Restart Container
# vzctl stop 145143 # vzctl restart 145143
Destroy Container
Follow the below command to delete the container
# vzctl destroy 145143 Container is currently running. Stop it first.
Above you can see container is running, firt you will need to stop it to delete.
# vzctl stop 145143 Stopping container ... Container was stopped Container is unmounted
Run again
# vzctl destroy 145143 Destroying container private area: /vz/private/145143 Container private area was destroyed # ls /etc/vz/conf/145143.* /etc/vz/conf/145143.conf.destroyed # vzctl status 145143 CTID 145143 deleted unmounted down
Note:- If you do not need the backup copy of the Container configuration files (with the .destroyed suffix), you may delete them manually.
I hope this article will help you to create container in OpenVz. If you have any queries and problem please comment in comment section.
Thanks:)
If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.
Leave a Comment