Saturday, April 24, 2010

How To Create a Container/VPS Machine With OpenVZ Server

After We have installed a OpenVZ VPS Master Server, We can create a container or VPS Machine on it.
Please see this URL if you still don't have OpenVZ VPS Master Server running/installed on your server.
http://wowtutorial.org/en/tutorial/97.html

Create a VPS Machine in OpenVZ VPS Master Server

First we need to make sure we have a vps config in /etc/vz/conf
All vps config that we have created will store in this directory
VPS config is use to define a harddrive space, memory, and other config stuff

Example there are 3 config file there
[code]$ls -al /etc/vz/conf
ve-light.conf-sample
ve-vps.basic.conf-sample
ve-vps.heavy.conf-sample[/code]

Next, We will need to make sure we have precreated template in /vz/template/cache directory
[code]$ls -al /vz/template/cache

centos-4-i386-default.tar.gz fedora-core-5-i386-minimal.tar.gz-old
centos-4-i386-default.tar.gz-old fedora-core-6-i686-default.tar.gz
centos-4-i386-minimal.tar.gz fedora-core-7-i386-default.tar.gz
centos-4-i386-minimal.tar.gz-old fedora-core-7-i386-minimal.tar.gz
centos-5-i386-minimal.tar.gz mandriva-2006-i386-minimal.tar.gz
debian-3.1-i386-minimal.tar.gz opensuse-10-i386-default.tar.gz
fedora-8-i386-minimal.tar.gz slackware-12.0-i386-minimal.tar.gz
fedora-8-i386-minimal.tar.gz.1 ubuntu-6.06-i386-minimal.tar.gz
fedora-core-5-i386-default.tar.gz ubuntu-7.10-i386-minimal.tar.gz
fedora-core-5-i386-minimal.tar.gz[/code]

If we have a config and precreated template we can start create a VPS Machine on OpenVZ VPS Master Server
We will use vzctl command to create,start,stop,destroy,etc.. the VPS Machine

Example command to create a VPS Machine:
[code]$vzctl create NODE --config yourconfigfile --ostemplate yourostemplate --ipadd yourvpsipadd[/code]

Here is the real examples command
[code]$vzctl create 1 --config vps.basic --ostemplate centos-4-i386-default --ipadd 10.10.1.2[/code]

Example config is : ve-vps.basic.conf-sample we can just use vps.basic in --config line command
NODE here is just numbering your VPS. we can name it 1, 100, 1000 ,etc

Next, We need to set a nameserver & Hostname for brandnew VPS Machine
[code]$vzctl set 1 --nameserver 10.10.1.50 --hostname server.testing.com --save[/code]

Note: Example Nameserver ip address is 10.10.1.50

After that, we can start the VPS Machine with this command
[code]$vzctl start 1[/code]

We also can directly enter into VPS Machine from VPS Master Server
[code]$vzctl enter 1[/code]

This command will automatically let us enter NODE 1 which is our brandnew vps
Then we can just use passwd to change the root password

If we want to exit from container/vps machine 1, it's simple type exit
[code]$exit[/code]

it will automatically logout and stay in OpenVZ Master VPS Machine again

To take a look a running VPS Machine type
[code]$vzlist

VEID NPROC STATUS IP_ADDR HOSTNAME
1 46 running 10.10.1.2 server.testing.com[/code]

Next Step is trying to connect the ip from outside network using putty.
If you are able to connect into 10.10.1.2 port 22 it's mean you are successfully configure a container/VPS Machine

If you want to stop the VPS Machine type
[code]$vzctl stop 1[/code]

It will automatically stop container/vps machine 1 (server.testing.com)

If you want to delete/destroy your VPS Machine, type
[code]$vzctl destroy 1[/code]

Note : you need to stop vps machine 1 first, before destroy the vps machine

No comments:

Post a Comment