Setting up a simple Web/Mail Server in OpenVZ

Here are the steps I continue to use over and over to build utilities/project servers in OpenVZ. Utilities servers host web apps, mailing applications, etc for my company. We usually build them as self-contained little appliance-like servers. My vision and goal is simple == better every day!

First, we create the virtual machine:

cd /vz/template/cache/
wget http://download.openvz.org/template/precreated/centos-5-x86_64.tar.gz
vzctl create 1164 --ostemplate centos-5-i386-default --config vps.basic
vzctl set 1164 --hostname [HOSTNAMEHERE] --save
vzctl set 1164 --ipadd [IP] --save
vzctl set 1164 --nameserver [IP] --save
vzctl start 1164
vzctl exec 1164 passwd
vzctl enter 1164

Now that we are in the virtual machine and away from the HN we add the REMI repo and apply the updates directly on the box.

wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
rpm -Uvh remi-release-5*.rpm epel-release-5*.rpm
 
yum --enablerepo remi -y update
yum --enablerepo remi -y install httpd php php-devel php-pear php-gd php-mbstring php-crypt php-mysql mysql

Add Postfix and switch it on via system-switch-mail

yum --enablerepo remi -y install postfix system-switch-mail
system-switch-mail

Now… customer configurations and setups…

Browser.php updated to v1.5

In the Browser.php project John pointed out (in the comments) a terrible typo in the source. I imagine no one has encountered this before as it only effects v1 or v1.5 of Internet Explorer.

Typo updated and version 1.5 of Browser.php released: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

Removing Images in a WordPress Post (Revisited)

A while back I wrote a semi-popular post on removing images from a WordPress post — today I am revisiting it. The original solution used the_content() and the output buffer to remove the images out of the post. Now that I have used WordPress a bit longer and candidly had to use the solution again and thought “what was I thinking” I thought I would share the cleaner solution:

.
.
.
<?php echo preg_replace('/<img[^>]+./','',get_the_content()); ?>
.
.
.

Browser.php updated to v1.4

I released v1.4 of the Browser.php project today to address a few features suggested by readers. This new release adds support for GoogleBot, Yahoo! Slurp, and the W3C Validator.

Check out version 1.4: http://chrisschuld.com/projects/browser-php-detecting-a-users-browser-from-php/

Browser.php updated to v1.3

Based on a comment on the Browser.php page I added support for the iPod today. I opted to place both the iPhone and iPod as browsers even though they are likely using the same instance of Safari. Additionally I added support for the iPod and iPhone as platforms. Thanks for the comments; enjoy!

Backup an OpenVZ VPS

There are a lot of ways to backup an OpenVPS without powering them down. I have two critical VPS systems both operating phone/PBX apps (asterisk) which I need to backup and I cannot get them to backup correctly while powered up (driving me nuts). So weekly (early on Sunday mornings) I backup them up by quickly powering them off; backing them up and powering them back up.

Side Note: Yes, yes, begin the hate mail: I power down the boxes; which creates all of the 65sec of down time. If anyone is calling my office at 2AM on Sunday morning and can’t leave a message please email me and I’ll adjust our backup schedule!

The script also pushes the backup images to a mount at /nfs/backup (a backup NAS system we have in place)

Here is how I do it:

#!/bin/sh
 
if mount|grep -q ' nfs ' && df -T | grep -w nfs | grep -w "\/nas\/backup" | grep -q -wv "100%";then
 
        # date in YYYYMMDD format
        today=`date +%Y%m%0e`;
 
        echo -e "Stopping VZ 105"
        /usr/sbin/vzctl stop 105
 
        echo -e "Dumping VZ 105"
        /usr/bin/vzdump --suspend 105
 
        echo -e "Starting VZ 105"
        /usr/sbin/vzctl start 105
 
        echo -e "Compressing Output"
        /bin/gzip -9 /vz/dump/vzdump-105.tar
 
        echo -e "Backing up - moving file to NAS"
        /bin/mv /vz/dump/vzdump-105.tar.gz /nas/backup/__hostname__here__/vzdump-105-$today.tar.gz
 
else
        echo Error: the NFS mount for the backup NAS does not appear to be correct
fi

Installing a standard Bind DNS server on an VPS (openvz)

All of our name servers I use are virtual servers and we add them into our network as OpenVZ VPS systems.  Here is the setup I use for setting up a Bind server on an OpenVZ VPS with CentOS 5.

Setup the Open VZ VPS and get into the VPS:

vzctl create 1031 --ostemplate centos-5-i386-default --config vps.basic
vzctl set 1031 --hostname ns4.aztecsoftware.net --save
vzctl set 1031 --ipadd 10.0.0.31 --save
vzctl set 1031 --nameserver 10.0.0.30 --save
vzctl start 1020
vzctl enter 1020

Now that you are in the VPS update the OS and get Bind updated:

yum -y erase bind* caching-nameserver
rm -rf /var/named
yum -y install bind*
yum -y update

Get the DNS key through dns-keygen (copy the key):

/usr/sbin/dns-keygen

Start the DNS Setup:

touch /var/named/chroot/etc/named.external.zones
touch /var/named/chroot/etc/named.internal.zones
cp /usr/share/doc/bind-9.3.4/sample/etc/named.* /var/named/chroot/etc/
cp /usr/share/doc/bind-9.3.4/sample/var/named/named.root /var/named/chroot/var/named/
chown named:named /var/named/chroot/var/named/named.root

I am not going to get into details on how to setup your named.conf — as mainly this is a command reference for myself in the future (aren’t I selfish). However, here is my list:

  • Remove the Caching Server View (localhost_resolver) because we do not need it because we are not using the caching only name server
  • Setup the zones for internal and external and point them to the touched files above (named.external.zones and named.internal.zones)
  • Make sure you are not in a position where you can fall subject to the cache poison.
vi /var/named/chroot/etc/named.conf

Updated Browser.php to version 1.2

The browser detection project in php (Browser.php) has been updated to version 1.2 based on suggestions I received in the comments. The new version is available for download in the project pages.

Thanks to all those who have emailed and commented on the script.

How to install “dig”: -bash: /usr/bin/dig: No such file or directory

If you are missing the dig command it means you are missing a package called bind-utils.  To install this package use yum to install bind utils:

yum install bind-utils

Or if you do not have access to yum, maybe from a hosted VPS solution you can grab the RPM packages (this is 100% assuming you are CentOS):

rpm -i http://mirror.centos.org/centos/5/os/i386/CentOS/bind-utils-9.3.4-6.P1.el5.i386.rpm

Or maybe you want to install the entire bind/named system:

rpm -i http://mirror.centos.org/centos/5/os/i386/CentOS/bind-9.3.4-6.P1.el5.i386.rpm
rpm -i http://mirror.centos.org/centos/5/os/i386/CentOS/bind-chroot-9.3.4-6.P1.el5.i386.rpm
rpm -i http://mirror.centos.org/centos/5/os/i386/CentOS/bind-libs-9.3.4-6.P1.el5.i386.rpm
rpm -i http://mirror.centos.org/centos/5/os/i386/CentOS/caching-nameserver-9.3.4-6.P1.el5.i386.rpm
rpm -i http://mirror.centos.org/centos/5/os/i386/CentOS/bind-utils-9.3.4-6.P1.el5.i386.rpm

TFTP Server Logs (or lack there of)

We have a TFTP server running on our network and sometimes we need to get a handle on the requests on the server.  By default if you are using linux and the tftp server through xinetd you won’t have a log file to look at.  Thus you need to use TCPDUMP… here is how you do it:

tcpdump port 69 -v

This was really helpful for us when we were setting up our Cisco 7960 phones and needed to get a handle on what in the world the crazy Cisco firmware was even requesting!