Thursday, May 6, 2010

How to create a VPS with Open VZ

OpenVZ uses a Operating System template system, ie every single VPS created with OpenVZ can have its own Operating System template like Fedora Core, Debian,CentOS.

You can download OpenVZ Operating System templates from OpenVZ template website. Note that each OS templates has its own hardware version . Make sure that you are choosing the right OS template for your server hardware.

Installing a template for CentOS:
[root@test ~]#yum -y vztmpl-centos-5-2.0-2 //install the template for Centos 5
[root@test ~]#vzpkgcache //create the cache, a lot of packages will be installed
[root@test ~]#vzpkgls //check the templates installed

Now we can go ahead and create out first VPS:

[root@test ~]#vzctl create 101 --ostemplate centos-5-i386-default --config vps.basic //This will create a VPS with the ID 101 using the Centos 5 template

Now a few things will have to set for the VPS like to be started at boot server time, set the IP, hostname, password and such.


[root@test ~]#vzctl set 101 --onboot yes --save

[root@test ~]#vzctl set 101 --ipadd 192.168.0.3 --save

[root@test ~]#vzctl set 101 --hostname server.server-hostname.com --save

[root@test ~]#vzctl set 101 --nameserver 192.168.0.2 --save


[root@test ~]#vzctl set 101 --userpasswd root:password //This last command will set the password for user root on the VPS






IMPORTANT VPS COMMANDS

How Do We Stop / Start / Restart VPS Servers?
# vzctl start 101 // 101 means the VPS ID
# vzctl restart 101
# vzctl stop 101
Login Into VPS Server
vzctl enter 101



How Do We Set Disk Quota?
# vzctl set 101 --diskspace SoftLimitG:HardLimitG --save
# vzctl set 101 --diskspace 10G:12G –save

How Do We Run a Command For VPS?

# vzctl exec 101 w
# vzctl exec 101 df

Destroy VPS
# vzctl destroy 101 // destroy the vps having ID 101