topleft topright

Tranquil Hosting Blog

Archive for the ‘sysadmin’ Category

HP Blows Up A Datacenter

Friday, June 29th, 2007

HP crafted a clever attention-getting for its current marketing campaign: they basically blew up a small datacenter. Why? Well actually it wasn’t just to start an arms race with Mythbusters. They suggest that if your company uses HP networking and server products, you will also magically be able to withstand having a bomb hit your datacenter. If you plan for it, of course.

Link to video from HP

What else can we take away from this?

  • HP’s new spin on going Green: fight energy-users with explosives
  • If you use HP products, you may want to blow them up too!
  • HP has a lot of extra money that they would rather not invest in R&D and driving sales (this could be argued either way, but as a stockholder I don’t think I would be happy with a company that wastes its own products).

Regardless, HP did have some success because tech bloggers and writers around the world are talking about it. From a logical perspective, I don’t see this being a very effective marketing pitch. Any network, regardless of specific manufacturer, can be made redundant. Especially if you are carefully planning for an exact failure at an exact time. The challenge in the real world is to build redundancy on multiple layers, while weighing costs and benefits to create a network setup that is as redundant as possible from human error, geographical locations, complexity problems and hardware failures.

PHP MySQL error: Client does not support authentication protocol

Saturday, May 19th, 2007

This is a fairly common error to see on a web server setup with PHP and MySQL:

Client does not support authentication protocol requested by server

The most likely cause for this is that PHP is built with MySQL support, using its bundled MySQL client. The bundled MySQL client is old, version 3.23.x. MySQL introduced a new password mechanism in version 4.1 of the server. If the MySQL server is setup for the new style of passwords, clients older than 4.1 will not be able to authenticate properly.

To see if this is your problem, look at a phpinfo() on your server. Scroll down to the mysql section and check the “Client API version”. Chances are, the version displayed there is not the same as your MySQL server. For an RPM-based Linux distribution, you can fix this by installing the proper mysql-devel package and then re-compiling PHP passing “–with-mysql=/usr” to the configure script. This way, when php compiles it will use the header files for your version of MySQL.


php mysql client

PHP Acceleration through Caching

Thursday, April 19th, 2007

The PHP scripting language is very flexible and gives a lot of bang for the buck. However, it is often criticized by supporters of J2EE and other web development platforms for not scaling well. Nevertheless, we see plenty of large sites running on PHP as well as popular applications like Vbulletin.

Whenever a PHP script is run, mod_php or a php binary in CGI mode parses the script and spits the output to the web server to send along to the web browser. Basically, the php code is “compiled” on the fly. This works great until we start getting traffic to our site and have to compile the same code over, and over, and over again. Imagine having to compile an everyday program like Microsoft Office each time you load it - loading is already slow enough as it is! A PHP-driven site with lots of dynamic content will easy chew up the server’s CPU resources once the traffic hits hard enough.

Some advanced PHP applications use caching at the application level, such as Wordpress which now has some caching features. But what do you do when you have a large custom-written PHP content management system based on a sport that is now getting worldwide attention and traffic? That is the situation one of our customers was in recently. We implemented eAccelerator, an open-source project that implements caching in the PHP scripting engine. Their website explains that it “increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated.”

Sure enough, eAccelerator worked as advertised. It cut the CPU usage on this particular server in half.

Account transfers in DirectAdmin

Saturday, March 17th, 2007

DirectAdmin is a web hosting control panel that we work with frequently. It certainly isn’t the most popular control panel out there, but with its clean and simple interface, spee, and price point, its a worthy contender. I recently ran into one of its shortcomings while doing a server migration.

I have been spoiled by WHM/Cpanel’s transfer scripts. They allow you to transfer sites pretty easily between servers. The scripts are automated to the point of saving and restoring user’s files, email accounts, forwarders, mysql databases, and all other relevant settings almost flawlessly. When moving sites between server’s its almost as simple as point-and-click. DirectAdmin has pretty good backup and restore features that can be used for transfers. The backup scripts packages a user’s account into a nice little tarball encapsulating all of their files, email accounts, settings, passwords, etc, much like cPanel’s scripts. The only problem is that when restoring these backups, all of the files are restored using the user’s permissions.

This becomes a problem when site owners and server admins set files to be owned by the Apache user, so that php apps can write to certain files. I contacted DirectAdmin about this and they say this is not a bug, and they wouldn’t want to restore files as root for security reasons. A server admin could then restore a malicious backup file, and if restored with root permissions, could drop a trojan or exploit on the server.

To work around this, I threw together some quick and dirty scripts to assist with a DirectAdmin server migration. I also got some random errors when DirectAdmin was importing MySQL databases, so these scripts will handle that as well

1. Export script
On the “old” server that we are moving sites away from, make a directory called /root/export and put this script in that directory, naming it export.sh:


#!/bin/bash
#
#
mysqluser="da_admin"
mysqlpass="YOUR.PASS.HERE"
cd /root/export
for i in `ls /var/lib/mysql/ | grep $1`;
do
mysqldump -Q --opt --user=$mysqluser --password=$mysqlpass $i > $i.sql
done
cd /home/$1
tar cvfpz /root/bin/$1-domains.tar.gz domains
cd /root/export
tar cvfz $1.tar.gz $1-domains.tar.gz $1*sql
rm -f $1*sql
rm $1-domains.tar.gz
scp $1.tar.gz root@10.1.1.1:import
rm -f $1.tar.gz

This script relies on you having passwordless ssh authentication setup to copy files via scp from oldserver to newserver.

2. Import script
On the new server that we are restoring sites to, make a directory called /root/import and place this script there named import.sh


#!/bin/bash
#
#
mysqluser="da_admin"
mysqlpass="YOUR.PASS.HERE"
tar xfz $1.tar.gz
cd /home/$1
rm -rf domains
mv /root/import/$1-domains.tar.gz .
tar xvfpz $1-domains.tar.gz
rm $1-domains.tar.gz
cd /root/bin
for i in `ls *sql | grep $1`;
do
dbname=`echo $i | awk -F. '{print $1}'`
echo $dbname
mysql --user=$mysqluser --password=$mysqlpass $dbname < $dbname.sql
rm -f $dbname.sql
done

chmod +x both scripts. Here is the process I follow when moving sites:

  1. Create a list of sites from the old server to move
  2. From the Reseller panel on the old server, create backups of all of the usernames you want to move
  3. For each username, run “export.sh” on the old server with the username as an argument (i.e. ./export.sh joeuser)
  4. The export.sh script will copy our custom tarball to the new server. You also need to manually copy all of the backup files from Step 2 to the reseller’s backup directory on the new server.
  5. Restore all of the users from the Reseller panel on the new server
  6. Import all of the custom backups on the new server. For each username, run import.sh with the username as the argument.

That should be it, happy transferring!

Copyright © 2007, Tranquil Hosting, Inc.
Managed Dedicated Servers | Managed Virtual Private Servers | Raleigh Datacenter Colocation
Raleigh, North Carolina Premium Hosting Provider
Terms of Service