OpenVZ is a virtualization technology that allows many virtual private servers (VPS) to run on one hardware node. This post shows how to create a slim down LAMP VPS using OpenVZ on a RHEL4 hardware node.
Outline:
- Install OpenVZ
- Install an OpenVZ template
- Create a temporary VPS container and initialize
- Set up NAT on your hardware node
- Install vzyum and related packages
- Update the temporary VPS OS with latest packages
- Replace OpenVZ template with the temporary VPS
Start with the fairly straight-forward quick installation guide available on OpenVZ’s wiki. Next, download a pre-created OS Template and place the tarball in /vz/templates/cache . At this point, you should be able to create a temporary container using the OS template you chose by doing the following:
vzctl create 1001 –ostemplate centos-5-i386-minimal
Where 1001 is the CTID (you’ll use this number to manipulate your VPS), and centos-5-i386-minimal is the name of the pre-created OS template you downloaded. Note: I tried a user-contributed centos 5 template, which required the installation of an additional metadata RPM in order for OpenVZ to know the location of certain files (like the networking scripts, nameserver file, etc…)
Let’s set the IP and nameserver of the VPS:
vctl set 1001 –ipadd 192.168.0.1 –nameserver “123.123.123.123 123.123.123.124″ –save
Next, set up NAT on the hardware node so that our VPS can make outbound network connections:
iptables -t nat -A POSTROUTING -s src_nat -o eth0 -j SNAT –to ip_address
I specified a src_nat of 192.168.0.0/24 to give me 255 NAT’d IPs to play around with. ip_address is your hardware node’s IP.
Time to fire up the VPS:
vctl start 1001
Test that networking works:
vctl enter 1001
ping yahoo.com
exit
At this point, we have a working VPS, but it’s running woefully out-of-date software. OpenVZ provides a wrapper around yum and rpm called ‘vzyum’ and ‘vzrpm’. Since I am running a centos 5 VPS, I’ll use vzyum. First I need to install the required packages on the hardware node (remember the HN is RHEL4):
rpm -Uvh python-elementtree-1.2.6-7.el4.rf.i386.rpm python-sqlite-1.0.1-1.2.el4.rf.i386.rpm python-urlgrabber-2.9.6-1.2.el4.rf.noarch.rpm vzrpm43-python-4.3.3-7_nonptl.6.i386.rpm vzrpm44-4.4.1-22.5.i386.rpm vzpkg-2.7.0-18.noarch.rpm vzrpm44-python-4.4.1-22.5.i386.rpm vzyum-2.4.0-11.noarch.rpm
Many of the packages not provided by RHEL4 were found at DAG .
Finally, let’s update our centos 5 VPS with the latest packages:
vzyum 1001 -y update
vzyum 1001 clean all
vzctl 1001 stop
Now we have all the updated packages and cleaned up any headers leftover from yum.
Now to replace the pre-created OS template with our up-to-date centos 5 version:
mv /vz/templates/cache/centos-5-i386-minimal.tar.gz /vz/templates/cache/centos-5-i386-minimal.tar.gz-old
cd /vz/private/1001
tar cvf /vz/templates/cache/centos-5-i386-minimal.tar.gz .
That’s it! Now you can vzctl create a slew of VPSs based on this template. Next time I’ll discuss how to create a web node template with LAMP built-in.
no comment untill now