Open Source Software Technical Articles

Want the Best of the Wazi Blogs Delivered Directly to your Inbox?

Subscribe to Wazi by Email

Your email:

Connect with Us!

Current Articles | RSS Feed RSS Feed

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 yum and 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 !includedir.

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
Creative Commons License.

Comments

Are you serious? 
 
http://w3techs.com/blog/entry/debian_is_now_the_most_popular_linux_distribution_on_web_servers 
Posted @ Monday, July 22, 2013 10:44 AM by Badiane
Ok, I can see the point if the author is wanting to write about how to transition from Ubuntu to CentOS... but from Debian? First off, packages are fully tested in Debian too. There are also tons of 3rd party repos available. Have an rpm you want to use on Debian... check out Alien. It converts from .rpm to .deb and vice versa. I have yet to have a problem and I've converted about 15-20 packages that I use.
Posted @ Tuesday, July 23, 2013 11:00 AM by Alan
Early you say: 
 
"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." 
 
Then later you say: 
 
"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." 
 
Also: 
 
"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." 
 
 
Although CentOS is an excellent Distro, I agree with @Badiane, I see no reason to move from Debian to CentOS. Different is not necessarily better. 
 
I have installed many Distros including most all of the most popular Distros, and I keep coming back to Debian. Unless Debian takes a bad turn, my choice will not change.
Posted @ Tuesday, July 23, 2013 11:21 AM by Rick Stanley
Hi Alan, 
 
It's not that Debian hasn't been fully tested. It's just that CentOS has been better tested.  
 
Take for example MySQL. In Debian 7 MySQL 5.5 is bundled. In CentOS 6 MySQL 5.1 is bundled. No matter how we look at this, we have to confess 5.1 is better tested than 5.5. 
 
Sorry if it looks like I don't appreciate Debian.
Posted @ Tuesday, July 23, 2013 11:23 AM by Anatoliy
CentOS _isn't_ a corporate distribution. Red Hat Enterprise Linux is. 
 
CentOS is repackaged RHEL - but the certifications and backports are Red Hat's effort not CentOS's primarily. 
 
CentOS is OLD because Red Hat packages software at the beginning of a release and releases relatively few updates other than security updates thereafter. 
Red Hat's support cycle now extends to 10 years per major release. CentOS 5.10 is directly related to CentOS 5 from some years ago 
 
The need for EPEL, RPMForge, Repoforge is a huge problem - you need anything and you have to go to a third party repository.  
 
Debian releases once every two years or so with a year of support thereafter. One cycle of CentOS is three Debian releases
Posted @ Tuesday, July 23, 2013 1:04 PM by Andy Cater
debian is totally unacceptable for corporate servers. 
 
I suggest you all read up on the benefits of an enterprise system. 
 
Anything less is potentially a litigious nightmare. 
 
The use of debian is hilarious. 
Posted @ Sunday, July 13, 2014 5:53 PM by fred
IN IY(NS)HO! 
 
Why??? 
 
Both are equally acceptable! 
 
"Anything less is potentially a litigious nightmare." 
 
If that is the case then ALL Linux Distros are as well! Debian, CentOS, Red Hat, etc... 
 
You and the article are so wrong! Both are hilarious!
Posted @ Sunday, July 13, 2014 6:08 PM by Rick Stanley
Post Comment
Name
 *
Email
 *
Website (optional)
Comment
 *

Allowed tags: <a> link, <b> bold, <i> italics