Restoring a cPanel Server From a Crashed Hard Disk OR Migrating a Cpanel Server

  • Recovering a cPanel Server From a Crashed Hard Disk using rSync

Rsync is another very powerful command that is used to synchronize 2 directories between servers and only transfer the new files to the server. This is a great method for backing up data as it is low on bandwidth and it is also commonly used to keep clustered servers working together. The ending slashes are very important when using rsync. If you are not familiar with how it works, always make sure to have an ending slash on both the source and the destination and it should be fine.

In case we fail or accidentally destroy our HDD then we can get a new HDD and operating system from the datacentre and restore the data on a new drive. This concept can be used to migrate cPanel Servers from one server to another without loosing any data or creating any sort of downtime for websites hosted on the server.

This is how it will work:

1) Get the partitions from both the drives with:

#fdisk -l

2) Check to see if there are any drives mounted with:

df -h

3) Let us assume that /dev/hdb3 is our CRASHED old drive and it is mounted as /mnt/old (yours can be different), but keep in mind that you need to know the mount point of the backup drive before we proceed further with the steps below.

Let us mount the CRASHED HDD if not already mounted with:

mount /dev/hdb3 /oldHD

4) Now that the drive is mounted you can browse any files with:

ls /oldHD/home

5) We are all set to move our data over to the new drive:

Run these rSync commands to move everything over:

rsync -vrplogDtH /oldHD/usr/local/apache/conf /usr/local/apache
rsync -vrplogDtH /oldHD/var/named /var
rsync -vrplogDtH /oldHD/home/* /home
rsync -vrplogDtH /oldHD/usr/local/cpanel /usr/local
rsync -vrplogDtH /oldHD/var/lib/mysql /var/lib
rsync -vrplogDtH /oldHD/var/cpanel /var
rsync -vrplogDtH /oldHD/usr/share/ssl /usr/share
rsync -vrplogDtH /oldHD/var/ssl /var
rsync -vrplogDtH /oldHD/usr/local/cpanel/3rdparty/mailman /usr/local/cpanel/3rdparty
rsync -vrplogDtH /oldHD/var/log/bandwidth /var/log
rsync -vrplogDtH /oldHD/usr/local/frontpage /usr/local
rsync -vrplogDtH /oldHD/var/spool/cron /var/spool
rsync -vrplogDtH /oldHD/root/.my.cnf /root
rsync -vrplogDtH /oldHD/etc/httpd/conf/httpd.conf /etc/httpd/conf

cd to the old etc directory:

cd /oldHD/etc

And copy some files from here:

rsync -vrplogDtH secondarymx domainalias valiases vfilters exim* proftpd* pure-ftpd* passwd* group* *domain* *named* wwwacct.conf cpupdate.conf quota.conf shadow* *rndc* ips* ipaddrpool* ssl hosts /etc

6) We are done with the copying of all the files and cPanel should start recognizing all the old users and their files, but after we do all this it is highly suggested that you run all updates, and run the cPanel fix scripts i.e:

Updating software and restarting services:

/scripts/upcp
/scripts/updatenow
/scripts/sysup
/scripts/exim4
/scripts/easyapache
/scripts/securetmp
/scripts/fixeverything

7)This is needed to update cpanel information. Please note, sshd might fail and not start after running fix everything. You have to login to whm, and go to the rpm installer and “FORCE” install opensshd-server, opensshd, opensshd-client and then restart sshd from whm.

Restarting services as:

/scripts/restartsrv httpd
/scripts/restartsrv cpanel
/scripts/restartsrv mysql
/scripts/restartsrv named
/scripts/restartsrv exim

That is all we need to recover data from a CRASHED HDD.

    Procedure to Migrate live cPanel Server to a new cpanel server :-

Same procedure can be used to migrate one server to another without any data loss or downtime. The following steps will be different in this case and for this particular requirement you will need to go through the following configurations :-

1) Share SSH keys between both servers (only if you have full control of both servers). To share SSH keys you will first need to generate keys on both servers with following command :-

ssh-keygen -t rsa -b 1024

Run above command only if you dont have any information in ‘/root/.ssh/ directory’. Once the keys are generated you will see the following files in the directory :-
id_rsa id_rsa.pub known_hosts

Now to share the keys you need to copy the contents of id_rsa.pub file and create a new file called authorized_keys in the same directory on the other server. Paste the contents of id_rsa.pub of server1 in server2 and server2 in server1 authorized_keys. Sharing SSH keys in this way will allow you to sync data between both servers without any sort of password authentication. You will need to create this file (authorized_keys) as it won’t be there by default.

Browse to the ‘/etc’ directory on the source server and run following command from that directory :-

rsync -vrplogDtH secondarymx domainalias valiases vfilters exim* proftpd* pure-ftpd* passwd* group* *domain* *named* wwwacct.conf cpupdate.conf quota.conf shadow* *rndc* ips* ipaddrpool* ssl hosts root@10.10.10.2:/etc

(10.10.10.2 is assumed as the IP of the new server to which we are moving the data.)

Now we need to transfer everything else.

rsync -vrplogDtH /usr/local/apache/conf root@10.10.10.2:/usr/local/apache
rsync -vrplogDtH /var/named root@10.10.10.2:/var
rsync -vrplogDtH /home/* root@10.10.10.2:/home
rsync -vrplogDtH /usr/local/cpanel root@10.10.10.2:/usr/local
rsync -vrplogDtH /var/lib/mysql root@10.10.10.2:/var/lib
rsync -vrplogDtH /var/cpanel root@10.10.10.2:/var
rsync -vrplogDtH /usr/share/ssl root@10.10.10.2:/usr/share
rsync -vrplogDtH /var/ssl root@10.10.10.2:/var
rsync -vrplogDtH /usr/local/cpanel/3rdparty/mailman root@10.10.10.2:/usr/local/cpanel/3rdparty
rsync -vrplogDtH /var/log/bandwidth root@10.10.10.2:/var/log
rsync -vrplogDtH /usr/local/frontpage root@10.10.10.2:/usr/local
rsync -vrplogDtH /var/spool/cron root@10.10.10.2:/var/spool
rsync -vrplogDtH /root/.my.cnf root@10.10.10.2:/root
rsync -vrplogDtH /etc/httpd/conf/httpd.conf root@10.10.10.2:/etc/httpd/conf

One more thing which needs to be done in this case is a mass replace command for changing the IP address in the zone files and httpd.conf. Here’s a command to help you do it in a few seconds :-

replace 10.10.10.1 10.10.10.2 — /var/named/*.db
replace 10.10.10.1 10.10.10.2 — /usr/local/apache/conf/httpd.conf

10.10.10.1 is assumed as the IP of source server.
10.10.10.2 is assumed as the IP of the new destination server which will now run your websites.

If you run this mass replace command on the source server as well then all the websites will start pointing to the new server immediately which will ensure no downtime for your websites.


 

 

phpize: command not found

You may receive the error “-bash: phpize: command not found” while executing the “phpize” command. The reason is the php-devel package is not installed on the server. The easiest way to install the package is to use ‘yum’.

SSH to your server as root and execute:

# yum install php-devel

Once done, you should be able to execute the command ‘phpize’.

 

Installing memcached in Plesk

Install libevent:

cd /usr/local/src
wget http://monkey.org/~provos/libevent-1.3e.tar.gz
tar -zxf libevent-1.3e.tar.gz
cd libevent-1.3e
./configure
make
make install

you may need to link /usr/local/lib/libevent to /usr/lib/libevent

wget http://danga.com/memcached/dist/memcached-1.2.4.tar.gz
tar zxvf memcached-1.2.4.tar.gz
cd memcached-1.2.4
./configure
make
make install
which memcached
/usr/local/bin/memcached -d


memcached -d -m 256 -u nobody -p 11211 -l 192.x.x.x (Server IP)

Enabling it in PHP
check zlib is installed in the server.

cd /usr/src
wget http://pecl.php.net/get/memcache-2.2.5.tgz
tar zxvf memcache-2.2.5.tgz
cd memcache-2.2.5
phpize
./configure
make
make install


php -i | grep php.ini

    Configuration File (php.ini) Path => /usr/local/lib

 

    Loaded Configuration File => /usr/local/lib/php.ini

 

nano /usr/local/lib/php.ini
extension = “memcache.so”

save the file and restart httpd server.

/etc/init.d/httpd restart

ERROR 1146 (42S02): Table ‘mysql.servers’ doesn’t exist

I’m not sure what caused this error in the first place, as it cropped on a server I don’t admin..

ERROR 1146 (42S02): Table ‘mysql.servers’ doesn’t exist

 

This cropped up on Server version: 5.1.36 MySQL Community Server (GPL) by Remi, installed on CentOS whenever I would execute the ‘FLUSH PRIVILEGES’ command.

The solution?  Try this.

USE mysql; 

CREATE TABLE `servers` (
`Server_name` char(64) NOT NULL,
`Host` char(64) NOT NULL,
`Db` char(64) NOT NULL,
`Username` char(64) NOT NULL,
`Password` char(64) NOT NULL,
`Port` int(4) DEFAULT NULL,
`Socket` char(64) DEFAULT NULL,
`Wrapper` char(64) NOT NULL,
`Owner` char(64) NOT NULL,
PRIMARY KEY (`Server_name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT=’MySQL Foreign Servers table’;

Apparently this issue arises sometimes with an incomplete MySQL upgrade.  Beyond just installing new binaries you’ll often need to run scripts/mysql_fix_privilege_tables to ensure the ‘mysql’ database contains all the needed stuff.

 

Install Nagios on Centos 5

Installing Nagios server and network monitoring on Centos 5 server

The official documentation can be found at http://support.nagios.com/knowledge-base/official-documentation

Install necessary packages

    yum install httpd gcc glibc glibc-common gd gd-devel php

Create Nagios User account and group

    useradd -m nagios

Create nagcmd group for allowing external commands to be submitted through
the web interface. Add both the nagios user and the apache user

    groupadd nagcmd
    usermod -a -G nagcmd nagios
    usermod -a -G nagcmd apache

Create Directory to store Nagios installation files

    mkdir /opt/Nagios

Download Nagios and Plugins

Save file to directory /opt/Nagios

http://www.nagios.org/download/download.php

As of this writing Nagios 3.0.6 (Stable) and Nagios Plugins 1.4.13 (Stable)

Extract Files:

    cd /opt/Nagios
    tar xzf nagios-3.0.6.tar.gz
    cd nagios-3.0.6

Compile and Configure Nagios

    ./configure –with-command-group=nagcmd

Compile Nagios:

    make all

Compile binaries, init script, sample config files:

    make install
    make install-init
    make install-config
    make install-commandmode

** Do Not Start Nagios **

Nagios has now been installed to the directory /usr/local/nagios/

Install Nagios Web Interface:

    make install-webconf

Nagios Web Interface installed to /usr/local/nagios/share ( http conf file added to /etc/httpd/conf.d/nagios.conf )

Create Web Interface Login User:

** This is not the most secure method **

We will create user “nagiosadmin” ( remember the password you assign !)

    htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Restart Apache:

    service httpd restart

Install Nagios Plugins

Extract Files:

    cd /opt/Nagios
    tar xzf nagios-plugins-1.4.13.tar.gz
    cd nagios-plugins1.4.13

Compile and Configure Nagios Plugins

    ./configure –with-nagios-user=nagios –with-nagios-group=nagios
    make
    make install

Configure nagiosadmin email address for alerts

    nano /usr/local/nagios/etc/objects/contacts.cfg

email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

Verify the sample Nagios configuration files

    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors: 0

Start Nagios

Enable Nagios to start at system startup / boot

    chkconfig –add nagios
    chkconfig nagios on
    chkconfig httpd on

Start Nagios

    service nagios start

Log into Web Interface

http://ip-address/nagios/