I currently am running about 10 domains all on one server using the multisite.

I am looking to scale out to a new server and was wondering if it is possible to somehow use the same Drupal information on this new server.

The best I have come up with is sharing the database and then copying all the Drupal files to the new server but it still bothers me because I will now have to update modules on both servers.

Is there anyway to sync the 2 servers or have one Drupal install or anything? Perhaps some type of XML-RPC solution?

I am guessing this probably isn't possible but if there was a way that would rule.

Any ideas?

Thanks,
Quinton

Comments

rmpel’s picture

Not that complicated, but a few prerequisites;

1. The database must be accessible from both servers
2. Both servers should be running a *nix os where you have SSH access
3. You need access to a cron-tab (SSH to server, login and type crontab -e . If this works, its ok)

With the database shared by both servers all you need, as you stated, keep the two codebases in sync. rSync will do that for you.

first you will need to make it possible for SSH to login remotely without password. Then you will need to script rsync to use SSH passwordless and sunc the files from server 1 to server 2. Don't worry, passwordless does NOT mean insecure; we will generate a keypair, public and private, to secure the connection.

ok. let's get cracking

we will have 2 servers; server1 and server2
we will have a user named 'server1user' to indicate its the user on server1
ideally you should have the same username and usergroup on both servers. This will be very hard on rented server space.

on server2, via SSH, do the following:

ssh-keygen -t dsa -b 2048 -f /tmp/rsync-key
Generasting public/private dsa key pair.
Enter passphrase (empty for no passphrase): [press enter here]
Enter same passphrase again: [press enter here]
Your identification has been saved in /tmp/rsync-key.
Your public key has been saved in /tmp/rsync-key.pub.
The key fingerprint is:
8c:57:af:68:cd:b2:7c:aa:6d:d6:ee:0a:5a:a4:29:03 server2user@server2

then place your keys in a location where the outside world cannot touch it

something like this:

cd ~
mkdir -m 700 .shh
cd .ssh
mv /tmp/rsync-key /tmp/rsync-key.pub .

now copy the keys to the first server;

scp rsync-key.pub server1user@server1:~

Now you will need to register the key for ssh and store the key safely

{this is still on server2}

touch authorized_keys
chmod 600 authorized_keys
cat rsync-key.pub >> authorized_keys

Now use IP restriction on top of key-authorisation

use an editor to edit the authorized_keys file (nano, pico, vi, vim, whichever you prefer)

the line ssh-dss AAAAB3NzaC1yc2EAAA [line continues and ends in]xw/+Da=server2user@server2
should be edited so in FRONT of it the following text is added:
from="123.123.123.123" where 123.123.123.123 is the ip of server1

now we ssh to server1 where we need to store the keys in a safe spot.

{this is via SSH on server1}

cd ~
mkdir -m 700 .shh
cd .ssh
mv ~/rsync-key ~/rsync-key.pub .

at this point we should be able to try (and succeed) to login without a password;

ssh -i ~/.ssh/rsync-key server2user@server2

you might have to accept the storage of an RSA key, but there should be no password prompt.

Now we need a script to sync your files

create a file ~/rsync-puch.sh;

touch ~/rsync-push.sh
chmod 700 ~/rsync-push.sh
cat >> ~/rsync-push.sh
#! /bin/sh
# This pushes the drupal codebase to the mirror server
rsync -avz -e "ssh -i ~/.ssh/rsync-key" ~/public_html/path_to_drupal/ server2user@server2:~/public_html/path_to_drupal/

Make sure the rsync line containes FULL paths INCLUDING end-slash for both paths!

Last step will be installing the cron but we do this AFTER testing the script.

at the prompt type: ~/rsync-push.sh

if your files are being copied (and they should) you can add the following line to your cron (using command crontab -e);

if you don't like vi or vim and want to use nano (or any other editor) type:
export EDITOR=nano<code> before entering <code>crontab -e

add the following line:
0 0 * * * ~/rsync-push.sh
this will sync your codebase every night 0.00 hours.

you can, however, keep doing it manually.

Hope this helps and hope i typed it all correctly.

one more remark; the ~/ links are links to your user-profile folder. It is preferred, however, to use full system paths from root (like /home/users/server1user/ instead of ~/, but you will have to figure out the path yourself, hint: use the pwd command )

Good luck!

slayerment’s picture

Wow, excellent response. I am going to go through what you wrote and try to get this working.

One more question: I have SSH access to my main server, but not to the mirrored client(s). This still should be possible since I will only need to be running a cron on the main server and only copying files to the client, correct?

If I have any problems perhaps I could get some help from you on a contract basis.

Thank you very much!
Quinton

rmpel’s picture

... unfortunately without SSH it won't work

rSync copies files over SSH and therefore you need to have access to the mirror server with SSH.

Remon.