How to migrate your server from Debian to CentOS
Considering migrating your server from Debian to CentOS? This article provides information on key differences between the two operating systems, along with instructions on moving your applications and configuration files.
Without a doubt, Debian is an excellent and popular Linux distribution, but it may not be your best choice for a server operating system. Even if you're more familiar with Debian, you may want to migrate to CentOS, which many people consider the de facto corporate Linux distribution. CentOS has a few undeniable advantages:
- Better software compatibility and third-party support – Almost every third-party application that runs on Linux is explicitly supported on CentOS, and you can find many high-quality CentOS application repositories that offer an abundance of third-party software.
- More stable software – CentOS includes only extensively tested and proven software. Applications in a CentOS release are usually a few versions behind their latest versions. In contrast, Debian usually provides more recent software with newer version. As a general rule, if you want stability, you should go with CentOS, and if you want functionality, you should choose Debian. Serious corporate users usually prefer stability over functionality.
- Backporting of fixes – Fixes available in newer versions of CentOS are ported to older versions. This can reassure corporate users who seek to avoid changing software versions but need to keep their operating systems current.
- Better trained workforce – Most Linux certifications are CentOS-oriented, so you're more likely to be able to hire CentOS-prepared personnel with certifications.
- Better commercial support – Besides relying on the CentOS community, CentOS users may also purchase reliable and affordable CentOS support plans from serious service providers.
All of these facts make CentOS preferred over other open source operating system for corporate use. If you have decided to migrate your servers, let's learn some best practices for how it can be done.
First, plan the migration by making starting with an inventory of your current Debian environment. This inventory should include all services and installed applications which will be migrated.
If you're compiling software from source, the process is the same for CentOS as it is for any other Linux distribution. However, binary software packages are not portable between Debian and CentOS. CentOS uses binary packages in RPM (RPM Package Manager) format. You can use utilities such as
rpm to install applications from binary packages and repositories. Here are a few examples of ways to use them oriented toward sysadmins with expertise in Debian:
- Searching for software – To look for software to install, use the command
yum search packagename, which is similar to Debian's
apt-cache search packagename. You can check whether a package has been already installed by running
rpm -ql, which lists all installed packages, and pipe the results to grep, as in
rpm -qa |grep packagename, to see whether a certain package is installed. Knowing how to search for software is important because packages don't have always the same name in CentOS as they do in Debian. For example, Apache is called httpd in CentOS and apache2 in Debian.
- Finding out information about software – Use
rpm -q to query information about a package. For general information about a package, use the command
rpm -qi packagename. To find which files belong to a package, run
rpm -ql packagename, or
rpm -qf packagename to show only configuration files for a package.
- Updating software – To update all CentOS packages, use the command
yum update, which is the equivalent of Debian's
apt-cache update && apt-get upgrade. To update a single package only, use
yum update packagename, which corresponds to Debian's
apt-get --only-upgrade install packagename. From security point of view it's a must to ensure your new CentOS system is up-to-date before commencing a migration.
- Installing software – In CentOS use
yum install packagename instead of
apt-get install packagename in Debian. To install a locally downloaded package, use
rpm -i packagename.rpm, similarly to Debian's
dpkg -i packagename.deb.
- Removing software – To remove a package in CentOS, use
yum remove packagename, similarly to
apt-get remove packagename in Debian.
Knowing these commands can save you time and headaches as you're getting used to CentOS during and after the migration process.
CentOS differs from Debian in another way when it comes to managing software. When you need to install a package in CentOS you may not find it in the default CentOS repository, which contains significantly fewer packages than Debian's. To address this deficiency you can add additional CentOS repositories. One of the first to consider is EPEL (Extra Packages for Enterprise Linux), which contains thousands of additional packages for use with
yum. To add the EPEL repository, run the command
rpm -ivh http://ftp-stud.hs-esslingen.de/pub/epel/6/i386/epel-release-6-8.noarch.rpm.
One important rule to observe when installing software is to make sure that the CentOS software versions are equal to or higher than the corresponding ones you were using in Debian. That's because older versions may not support features and specifics of newer versions. This is especially critical if you are going to support dynamic, server-side languages such as PHP or databases such as MySQL. Many PHP scripts depend on a particular PHP version and will not work on older release, and sometimes even on newer, so your only choice is to install the same version. The situation with MySQL is similar. If you need a newer version of an application than CentOS supports by default, you should install the version you need from source or from available binaries.
Migrating configuration files
Once you have everything you need in place to migrate your services and applications, it's time to transfer the corresponding configurations. Even though most software configuration directives are not distribution-specific, it's better to migrate the configuration manually and not just copy over the files, because often hardcoded paths in the files differ among distributions. To make things easier, migrate only essential and critical settings and leave the rest as the defaults. For the settings you decide to preserve, make sure to adapt any hardcoded paths to files, directories, modules, and binaries. This is especially important for Apache and its virtual hosts, where the paths will certainly change, at least for the
DocumentRoot of the vhosts.
CentOS keeps its configuration files to a minimum number, which means that sometimes they become large and hard to navigate through. In contrast, Debian spreads most configuration over multiple files. Here is some information on how the configuration of the most popular services is distributed and what you have to do for the migration:
- MySQL – In CentOS MySQL has only one configuration file: /etc/my.cnf. When migrating from Debian you have to combine in it all the options that in Debian are spread across numerous files in the directory /etc/mysql/.
- Apache – In CentOS the main Apache configuration file is called /etc/httpd/conf/httpd.conf. In this file you have to combine all the Apache directives from the Debian files in the files /etc/apache2/apache2.conf (main Apache conf) and /etc/apache2/ports.conf (Apache listeners) and the directories /etc/apache2/conf.d/ (security and more specific settings) and /etc/apache2/mods-enabled (enabled Apache modules). Also, Debian keeps the configuration for the working vhosts in separate files for each vhost in the directory /etc/apache2/sites-enabled/. This is a good practice that you can also apply in CentOS. Just recreate the vhosts configuration files in the directory /etc/httpd/conf.d/ in CentOS.
- PHP – In CentOS PHP configuration is in the file /etc/php.ini and the .ini files inside the directory /etc/php.d/. You have to transfer to these the PHP configuration from Debian's file /etc/php5/apache2filter/php.ini and the .ini files inside the /etc/php5/apache2filter/conf.d/ directory.
If this uniting of configuration files in CentOS seems confusing to you, there is a way to split the configuration into multiple files. Most software configuration files can be instructed to include external files. To do so in Apache, use the directive
Include, and in MySQL use the option
Sometimes there is a good reason to split configuration files. PHP in both CentOS and Debian uses multiple files for security reasons. PHP processes the configuration directives in the following order: main php.ini file (/etc/php.ini in CentOS), local php.ini files (found in vhost webroots), and finally php.ini files from the global include directory (/etc/php.d/ in CentOS). This ensures that administrators can override any insecure, incorrect configurations that could be found in the webroot of a vhost.
Changing the state of services
Once you think you have everything migrated properly, start your services for the first time and make sure they start and stop with the system. CentOS startup scripts are in the directory /etc/init.d/, just like in Debian. And, just as in Debian, in CentOS the command
/sbin/service is the preferred method for managing the state of a service. Both the /etc/init.d/ scripts and the service command accept the usual start, stop, restart, and reload arguments.
However, the two distributions differ in default runlevels. The default runlevel in CentOS is 3; in Debian it's 2. This matters when you install a service and you want it to start automatically with the system and thus have to add it to the default runlevel. The runlevel start and stop scripts, as in Debian, are in the directories /etc/rcX.d/ where X is the number of the runlevel.
In Debian you manage runlevel scripts with the
update-rc.d command. In CentOS it's
chkconfig. To make sure a service starts and stops automatically with the system, run the command
chkconfig example on. This ensures the example service is added to the proper runlevels and you don't have to edit any files manually.
Once all your services are installed and configured you just have to migrate your content, which should be as straightforward as copying files between the old Debian server and the new CentOS server. You should export databases on the old server and import them on the new one.
That's all it takes for a complete Debian-to-CentOS migration!
This work is licensed under a Creative Commons Attribution 3.0 Unported License