Monthly Archives: September 2008

OpenVZ – how-to create a VPS

As a few days ago i was writing about installing OpenVZ and the operation commands i was thinking that this would go nice under it as a follow-up .

Installing a template is pretty easy :

[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

The output for the last command will be similar to:

Now that we installed the templates for Centos 5 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(also 0-100 for the VPS ID is not possible to use)

Running the create command will send you this output so you know it is created:
Creating VE private area (centos-5-i386-default)
Performing postcreate actions
VE private area was created

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
Saved parameters for VE 101

[root@test ~]#vzctl set 101 --ipadd --save
Saved parameters for VE 101

[root@test ~]#vzctl set 101 --hostname --save
Saved parameters for VE 101

[root@test ~]#vzctl set 101 --nameserver --save
Saved parameters for VE 101

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

Now we are ready to start the VPS:

[root@test ~]#vzctl start 101
Starting VE ...
VE is mounted
Adding IP address(es):
Setting CPU units: 1000
Set hostname:
File resolv.conf was modified
VE start in progress...

Let’s start the ssh on the VPS from the node server using exec

[root@test ~]#vzctl exec 101 service sshd start
Starting sshd: [ OK ]

Check the VPS if it is running:

[root@test ~]#vzlist
101  16    running

A last thing to do so that the VPS will be ready for direct use/access is to install yum on the VPS:

[root@test ~]#vzyum 101 install yum

If all this run with no problems you have the first VPS up running Centos 5.


Virtualization with OpenVZ – OpenVZ Kernel Install

OpenVZ is known as being the free version of Virtuozzo(created by the guys at Parallels, former SwSoft) and i have to say that it is working really nice if you know your way around shell commands as this one comes without any Control Panel to manage the Containers and resources.

There are some nice Panels out there that can be used with OpenVZ and one of the is HyperVM created by the guys from LxLabs.

Anyway, will talk right now about installing the OpenVZ kernel/package on the server using command shell.

For this to be completed you need a fresh installed server(recommend CentOS 5) and root access to the server.

First we have to install the kernel for OpenVZ:

[root@test ~]#cd /etc/yum.repos.d

[root@test yum.repos.d]#wget

[root@test yum.repos.d]#cd /

[root@test /]#yum -y install ovzkernel

After the kernel was installed we have to enable IP forwarding :

[root@test /]#vi /etc/sysctl.conf

Change the following lines to look like this:

net.ipv4.ip_forward = 1
kernel.sysrq = 1

And add this at the bottom of that file:

net.ipv4.conf.default.proxy_arp = 0
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0

At last edit the grub.conf(menu.lst) file to let the server know to boot our new kernel by setting the default boot kernel:

[root@test /]#vi /boot/grub/grub.conf

Change the default value: default=0

Reboot the server:

[root@test /]#reboot or [root@test /]#shutdown -r now

If you are doing everything remotely and want to test the kernel and make sure that the server will boot up even if the kernel fails you can try the following:

[root@test /]# grub

grub> savedefault --default=0 --once

grub> quit

Run the reboot command now.

After the server is back up check to see what kernel is using:

[root@test /]#uname -r

And if everything is fine you should see the new kernel.

The next thing to do is to install the operation commands:

[root@test /]#yum -y install vzctrl vzquota vzpkg

When the Yum will finish installing the commands the only thing left to do is to try and start OpenVZ and if is working:

[root@test /]#/etc/rc.d/init.d/vz start
Starting OpenVZ: [ OK ]
Bringing up interface venet0: [ OK ]
Configuring interface venet0: [ OK ]

FreeBSd: Add IP aliases and Stop/Start/Restart networking and routing

Working on a Freebsd server can be difficult if you have no idea that it is not the same as a Linux server even if the architecture type of Freebsd is unix-like but yeah in the end is BSD.

Things are being done a bit differently on a Freebsd server when it comes to networking and routing.

For the start all the IPs are being setup in a file called /etc/rc.conf and also the IP aliases will be set in this file also.

Checking the rc.conf file you will see the line containing the IP as it is really obvious and will look like:

ifconfig_rl0="inet netmask"

The IP, netmask and also the name of the interface(in our case rl0) can be different.

In order to add some more IPs to the same interface we will have to edit the rc.conf file and add the following under the already existing "ifconfig_rl0=" line:

ifconfig_rl0_alias0="inet netmask"
ifconfig_rl0_alias1="inet netmask"
ifconfig_rl0_alias2="inet netmask"

Important Note:Start with alias0 and not with alias1 or other numbers in the alias line

Doing all this we ended up setting the three aliases(,, to the rl0 interface and the only thing left now to do is to restart the networking and routing if needed.

General commands on starting/stopping/restarting networking and routing in FreeBSD:

To start FreeBSD network service:
# /etc/rc.d/netif start

To stop FreeBSD network service:
# /etc/rc.d/netif stop

To restart FreeBSD network service:
# /etc/rc.d/netif restart

It is also necessary to update the routing table after restating networking service:
# /etc/rc.d/routing restart

If you have done all this modifications using a remote connection(ssh) you may want to use the following command to restart networking and routing at once:
# /etc/rc.d/netif restart && /etc/rc.d/routing restart

This should have covered the general networking part for Freebsd.