How to create OpenVZ containter

Before we can create any OpenVZ virtual container we need to have a template for the distribution that we want to use in the virtual machines. We will need to put/download that template in the /vz/template/cache directory. The virtual machines will be created from that template. You can find a list of precreated templates (and download them) here.

In this tutorial I will be using CentOS 6 in my virtual machines, so I will download a CentOS 6 template:

cd /vz/template/cache
wget http://download.openvz.org/template/precreated/centos-6-x86_64.tar.gz

To set up a VPS from the CentOS 6 template, run the following commands:

vzctl create 101 --ostemplate centos-6-x86_64 --config basic

Please note that 101 must be a unique ID since each virtual machine must have it’s own unique ID. You can use any number you want. A good practice is to use the last three digits of the virtual machine IP address, so if the IP address is 192.168.0.101 you can use 101 as a virtual machine ID.

If you want the virtual machine to start at the system boot automatically, run the following command:

vzctl set 101 --onboot yes --save

To set the hostname and the virtual machine main IP address run:

vzctl set 101 --hostname test.example.com --save
vzctl set 101 --ipadd 192.168.0.101 --save

Next we set the number of sockets to 120 and assign a few nameservers to the vm:

vzctl set 101 --numothersock 120 --save
vzctl set 101 --nameserver 8.8.8.8 --nameserver 8.8.4.4 --nameserver 208.67.222.222 --save

And finally, to start the virtual machine use:

vzctl start 101

Once the virtual machine is started you can set the root password with:

vzctl exec 101 passwd

after that you can connect using putty.

You can enter the virtual machine from the host directly using:

vzctl enter 101

And exit with:

exit

Some other command that might be useful to you.

To stop the virtual machine, run:

vzctl stop 101

To restart the virtual machine, run:

vzctl restart 101

To delete the virtual machine from the hard drive (it must be stopped before you can do this), run:

vzctl destroy 101

To find more about please check the vzctl man page with:

man vzctl

Be the first to comment

Leave a Reply