Clone Ubuntu Server to new location

Imagine you have to move your server to another provider. It is a time-consuming task to set up a new server, install all the applications, databases, and so on… and then configure it all the same way as before.

Of course you would copy a lot of that from the old to the new server. You could even make an image from the old server and copy it to the new. But wait, is it that simple though? Well, considering a few things it isn’t all that hard. I didn’t fetch an image, but made a backup from the old server using rdiff-backup. Then I set up my new server with the same OS as the old server (Ubuntu 14.04). Then I would adapt a few things to the configs of the backup and play the backup back into the new server. Voilà.

Remote Password-less Root Access

At first you need remote root access. For this to work you usually have to modify your ssh daemon config found at /etc/ssh/sshd_config

If you can access your remote server with ssh root@<your server> you’re good to go.

rdiff-backup

Install rdiff-backup on both machines (server and your local machine).

sudo apt-get install rdiff-backup

Then we backup our remote server. Create a directory where you can put the backup and ensure you have enough space left. Run this as the root user:

rdiff-backup --exclude '/tmp/*' --exclude '/proc/*' --exclude '/sys/*' --exclude '/media/*/*' <your server>::/ <your local backup folder>

Now we have a backup of our server.

Preparing the new server

You probably have some kind of control panel. Install the same OS as you had on the old server.

We then again need remote root access to the new server.

Restore

On your local machine as root user:

rdiff-backup --force -r now --exclude '/boot' --exclude '/dev' --exclude '/tmp' --exclude '/proc' --exclude '/sys' --exclude '/media' --exclude '/etc' <your local backup folder> <your new server>::/

You can see I excluded the etc directory to not overwrite some important configuration files that need to stay the same on the new server.

On your new server make a new temporary directory anywhere. From your local machine as root we now copy the old configuration files to the temporary directory. I use rsync for this:

rsync -av /etc <your new server>:<your tmp folder>

Then go back to the shell of your new server and copy the file system and network configuration back into the configuration from your old server.
cp -a /etc/network <tmp-folder>/etc/ # network configuration
cp -a /etc/fstab <tmp-folder>/etc/ # file system table
cp -a /etc/resolvconf <tmp-folder>/etc/ # nameserver information

Finally overwrite the etc folder from your new server:

cp -a <tmp-folder>/etc /

Everything should be up and running by now.

Flattr this!

Check_mk and Ubuntu 14.04 Server

If you want a quick monitoring solution with a comprehensive list of automatically generated checks then check_mk is the way to go.

Requirements for this guide

  • Ubuntu 14.04 Server
  • Running Nagios3 installation

Agent

On the systems that you want to monitor you have to install the check-mk-agent and the xinetd package from the Ubuntu repos. Also recommended is the check-mk-agent-logwatch package.

Open the /etc/xinetd.d/check_mk file and change the disabled attribute from yes to no. Also uncomment the only_from attribute and adapt accordingly.

Restart the xinetd daemon:

/etc/init.d/xinetd restart

And check if the agent port is open:

netstat -tulpn | grep 6556

 

Server

On the system where the Nagios installation is running, install the check-mk-server package.

Adapt the check_mk configuration found at:

vim /etc/check_mk/main.mk

Insert the hosts you want to monitor.

Make an inventory of the hosts by running the following command:

su nagios -c "check_mk -I"

Check_mk will now automatically retrieve the possible checks for the hosts! Awesome! 😉

Write out the configuration by running the following:

su nagios -c "check_mk -O"

And restart Nagios. Voilá!

If you want nice visualizations of your data, then you also have to install the pnp4nagios package.

Flattr this!