Server migratie met DirectAdmin

30 december 2008 (21:22) | HOWTO's | Geen reacties

Hoewel het niet erg veel specifiek met VPS te maken heeft, plaats ik deze HOWTO ook maar eens hier. De doelgroep van deze website is toch redelijk gelijk aan de doelgroep die deze HOWTO aanspreekt. Hij is in het Engels, maar dat lijkt me geen probleem!

We, as a company, migrate DA servers on a very regular basis. Sometimes because a server is past its expiration date, sometimes because clients move to our services. Anyway, because we feel we’ve conquered this quite nicely so far, I decided to share our knowledge and maybe start a discussion on how to improve this technique.

It’s just a basic checklist based on many other howto’s and knowledgebase items, but I’ll try to make it a comprehensive set of “tools” making sure you minimize your downtime.

We start four to six hours before our server is at its quietest by lowering the TTL. As DA support has a guide for this, I decided not to go too deep into this. Don’t lower it to 100 though, lower it to 301. Some access providers tend to overrule a TTL lower than or equal to 300, 301 has the best results, although I must add to that that these experiences are with Dutch APs.

These four hours give us plenty of time to setup the new server. Of course, you have experience with setting up a server and you will want to do it your way, I respect that. Basically, what we do is we install our OS (CentOS 5), do a custombuild DA install and proceed from there. Add all the IPs you need to the server in advance. Then you could look into using ELS as your basis for securing the server. After that I would advise on securing Exim with ClamAV, SpamAssassin and SpamBlocker (an obsolete version is currently provided with DA, look here for the current stable version (v2) or the latest beta (v3)). Guides can be found on the forums. But again, this is just one of many ways. Of course, install the packages you need, you’ll know better what you want.

Fine, then you’ll have some spare time left, get a nice cup of coffee, start testing whether everything is setup properly. Make a test reseller account and try giving it two nameservers and one user (with a domain) on those nameservers. Check whether they are functioning normally using your favorite nameserver checking service (Google will find it for you). We’ve had some problems with bind/named in the past, so I always advise to do so. If everything works, remove the reseller and the user(s).

At least four hours should have passed and it should be an off-peak time by now. If not, get another cup of coffee and go do something useful.

Right before your start backup up, there’s a very important decision to make: whether to shutdown httpd/mysql/exim/dovecot etc. on the old server or not. Basically, that’s a choice between downtime and information loss. And it’s your choice. I always stop all services just before I make the backup, inform all clients on it two days in advance and depend on my mail relay service for relaying e-mail. But again, it’s your choice. It should all be offline for no longer than 30 - 40 minutes.

Now, we’ll start by backing up all accounts on the old server. I don’t know how your server is setup, but I always advise not to transfer the admin account along with the other accounts. If you’re experienced with DA, you’ll know not to use the admin account too much and use a reseller account for all the rest, but if you didn’t, well, you’ll have to backup the admin account as well. Use the admin backup/transfer tool. System backup is nice to use for redundancy, but it’s very hard to restore a system backup, so this way is better imho. You can have DA send the backup to the new server using FTP, but you could also have DA just focus on the backing up process and throw each individual backup to the other server as soon as it’s done. The last way is probably faster as DA doesn’t backup and transfer at the same time (thanks to jlasman for pointing that out!).

Login to the new server and wait until the old server’s DA tells you the backups have been successful.

After the backup’s done, start restoring the backups on the new server. Make sure you check that the new IP is being used for restoring. If certain users have their own IPs, restore them individually or change it later on. DA will have it done quite fast in my experience, but it could take a while longer or fail. If it fails, make sure to restore the failed accounts again.

Then, as fast as you can, fire up an SSH session to the old server and change the IPs in the DNS configurations. This is to make sure that all traffic is now going to the new server, even if an AP overrided the new TTL. To do that, use the following steps:

# cd /var/named
# perl -pi -e 's/1.2.3.4/4.3.2.1/' *.db
# service named restart

1.2.3.4 is your old IP, 4.3.2.1 is the new one. Make sure you execute the perl command for every IP that needs to be changed, so also for the nameserver IPs and dedicated IPs.

Just to be sure, stop all processes on the old server except for DA, named and SSH. To speed up the process, you could change the IP for the domain that has the nameservers at your registrar’s. After you have made sure everything resolves fine, you can do with the old server whatever you want.

After making sure everyting works like it should, you’re done. Great stuff, give yourself a nice pat on the back!

VPS security

23 december 2008 (21:44) | HOWTO's | Geen reacties

Security is key. Er bestaan geen publieke servers meer die niet blootgesteld worden aan de kwade buitenwereld. Server logs staan vol met pogingen om in te breken en kwaad te doen. Maar hoe kun je deze pogingen nu het beste tegengaan? In het onderstaande voorbeeld wordt uitgegaan van een vrij standaard VPS configuratie met CentOS 5 en een volledige DirectAdmin installatie (Custombuild). Het is wel een vrij algemene set tips, dus veel informatie zal uitwisselbaar zijn met andere opstellingen.

Een zeer goede en eenvoudige mogelijkheid is het installeren van het pakket ELS (Easy Linux Security), speciaal opgezet voor gebruik met zowel DirectAdmin als cPanel. Volg de onderstaande stappen (als root):

# cd /var/tmp
# wget -O installer.sh http://els.web4host.net/installer.sh; chmod +x installer.sh; sh installer.sh

ELS is erg uitgebreid en het is aan iedere server admin om te bepalen welke stappen hij wil ondernemen om zijn server goed te beveiligen. Heb je echter erg veel vertrouwen in de makers van ELS, voer dan gewoon het volgende commando uit (als root):

# els –vps
// Hierboven moeten dubbele streepjes staan, niet elke browser lijkt dat op de juiste manier over te nemen, type gewoon “els” voor een lijst met commando’s

Dan zullen alle veiligheidsmaatregelen passend bij een VPS voorgesteld worden. Je kunt zelf kiezen welke wel en welke niet geinstalleerd worden. Het gaat dan onder andere om een firewall, pakketten om rootkits op te sporen, een aantal applicaties worden beter geconfigureerd, belangrijke bestanden beschermd, directe root access wordt uitgeschakeld en meer. Een zeer handig pakket dat je veel werk kan schelen. Uiteraard hoeft ELS niet alles op de manier te doen waarop je het graag doet. Kies bijvoorbeeld je eigen firewall of configureer hem zoals jij dat wil. Trek echter wel lering uit alles wat ELS doet, elke maatregel heeft een reden.

E-mail virussen

Om virussen in e-mail tegen te gaan wordt vaak gebruik gemaakt van ClamAV. Dat doen we (op een CentOS server) als volgt (inloggen als root):

# cd /var/tmp
# wget http://packages.sw.be/clamav/ [de-laatste-clamav-versie] .rpm
# wget http://packages.sw.be/clamav/ [de-laatste-clamd-versie] .rpm
# rpm -Uvh clamav-versie.rpm
# rpm -Uvh clamd-versie.rpm
# nano /etc/crontab

voeg toe: 50 * * * * /usr/bin/freshclam –quiet (pas de 50 zo aan dat hij niet samenvalt met een andere cronjob)
ctrl-x -> y(es)

# clamd start
# chkconfig clamd on
# freshclam // hiermee update je de virusdefinities, niet noodzakelijk omdat de cronjob het ook al doet
# nano /etc/exim.conf

Voeg bovenaan toe (voor primary_hostname):
av_scanner = clamd:127.0.0.1 3310
Zoek dan (ctrl-W) naar:

# ACL that is used after the DATA command
check_message:
accept

en verander dat naar:

# ACL that is used after the DATA command
check_message:
# Virus Check
deny message = This message contains a virus or other malware ($malware_name)
demime = *
malware = *
accept

ctrl-x -> y

# service exim restart

Dat zou het moeten doen. Voor hulp bij problemen verwijs ik je naar de bron van bovenstaande handleiding.

Spam

Spam is de grootste “pain in the ass” waar moderne webhosts mee te maken hebben. Gelukkig kent DirectAdmin een zeer doeltreffend, specifiek voor DA ontwikkeld anti spam pakket om bijvoorbeeld naast de gebruikelijke SpamAssasin te gebruiken. Het heet SpamBlocker en is in feite een aangepaste exim.conf file specifiek bedoeld om spam te weren. Het is te gebruiken in combinatie met SpamAssassin, verwijder dan even de comment-tags voor de SpamAssassin regels in je exim.conf file. Alle domeinen die je wil laten scannen door SpamBlocker voeg je toe in /etc/virtual/use_rbl_domains.

LET OP: De meegeinstalleerde versie van SpamBlocker is op het moment van spreken achterhaald. Wil je echt up-to-date zijn, installeer dan zelf met behulp van de instructies de nieuwste SpamBlocker. Houd wel goed rekening met ClamAV, SpamAssassin en andere customisaties aan je huidige exim.conf.

Wees een goede sysadmin

Uiteindelijk ben je zelf altijd verantwoordelijk voor de veiligheid van de server. Denk niet dat je server 100% veilig is na het volgen van bovenstaande stappen. Ik ben hierboven ongetwijfeld zaken vergeten en daarnaast ontwikkelen ook kwaadwillenden zich altijd zo dat er weer nieuwe gaten in de muur gedicht moeten worden. Houd je systeem up-to-date en controleer je logs regelmatig. Een enkel onveilig (php-)script kan al voor enorme problemen zorgen. Weet wie je toelaat op je servers en zorg dat als zij er niets meer te zoeken hebben, zij ook geen toegang meer hebben. Verander al je eigen wachtwoorden regelmatig en deel ze met niemand.