Multiserver Setup in Drupal Tutorial and Configure NFS

If your Site has a lot of large traffic. Normally you tend to increase number of machines (servers) which will divide the traffic using a load balancer. Load balancing distributes the load. Load Balancer can find out from the servers which one is least loaded, so all the servers are doing an equal amount of work. This will give the best performance of Site. Drupal high traffic site setup tutorial.

Learn how to create a multi Server Set-up for Drupal 7.

In the Below Image you can see there are multiple requests to one URL. The Load Balancer sends request to (A,B,C) either of one Server. Each Server is linked to single database (D) server.

And one NFS(Network File Sharing) Server (E) again linked to (A,B,C) where all files(For example : Images, PDF , etc. Uploads by visitor) are saved.

Note : We are assuming the Site is Built in local machine or single server setup. And now we will learn how to transfer the complete setup to multiserver where we will learn how to configure all Servers and Drupal to work in Multi Server Environment.

Note: We will assume IP for all five server as follows
Server A: a.a.a.a
Server B: b.b.b.b
Server C: c.c.c.c
Server D: d.d.d.d
Server E: e.e.e.e

Step 1 : Starting with placing files in Server. Place the complete files and folders of you drupal site and keep it in Server A, B , C . However we will be skipping the folder sites/default/files

Step 2 : Now you can import the database in D Server.

Step 3 : In server (A, B ,C) open file sites/defaut/settings.php and give path to
$databases = array (
  'default' => 
  array (
    'default' => 
    array (
      'database' => 'db_name',
      'username' => 'db_user',
      'password' => 'db_passwd',
      'host' => 'db_host',    //in our case we will have this as "d.d.d.d" 
      'port' => '',
      'driver' => 'mysql',
      'prefix' => '',

Note: You have to make sure that port is opened between Servers

This can tested using telnet command for example open command line(terminal) in A Server and run telnet d.d.d.d or d.d.d.d 443 (in-case of secure connection)
If it gives output as "connected" then port is opened if it gives "could not connect" you need to open port between both servers.

Step 4 : You need to make NFS(Network File Sharing) between following servers and also make sure that ports between them is open.

Before we start with NFS setup we will understand what is NFS. If you have worked in Machines connected to LAN you know normally for miscellaneous purpose there is a common shared drive which is shared by all machines and used for data transfer between machines. We are going to use the same method for Drupal Multi server setup for file storage.

In Drupal we define the path where all files (images,pdfs,etc) is saved Under Configuration > Media > File System (Refer screenshot below)

By default it will be "sites/default/files"
We will create directory under "sites/default/files" say with name "shared" in all three servers (A,B,C).
And now Under Configuration > Media > File System (Refer screenshot above)
We will change it from "sites/default/files" to "sites/default/files/shared"
Using NFS we will mount this "shared" directory to a directory in Server(D) say "mnt/store". So anything saved in Server (A,B,C) inside "sites/default/files/shared" will actually be saved in Server(D) inside "mnt/store".

Step 5 :

Learn how we Configure NFS

As we are assuming Server-E (ip: e.e.e.e) is the server where you are going to save the files, Server-A(ip: a.a.a.a) , Server-B (ip: b.b.b.b) Server-C (ip: c.c.c.c) will have drupal. In Server-E you may be storing the files in /store folder. This is to be mounted to folder /mnt/store in Server-A , Server-B and Server-C.

For this you need to install nfs-kernal-server in Server-E and nfs-common and portmap on all three servers. NFS relies upon Remote Procedure Call(RPC) and portmap service is required to map RPC requests to the correct services.

In Server-E do these configurations:

sudo apt-get install nfs-kernel-server portmap nfs-common
sudo mkdir -p /mnt/store
sudo chmod 777 /mnt/store
sudo mount --bind /shared /mnt/store

sudo vi /etc/default/nfs-kernel-server in this file set NEED_SVCGSSD=no

sudo vi /etc/default/nfs-common in this file set: NEED_IDMAPD=yes and

sudo vi /etc/idmapd.conf in this file under [Mapping] set Nobody-User = nobody and Nobody-Group = nogroup

sudo vi /etc/hosts.deny add this: portmap mountd nfsd statd lockd rquotad : ALL

sudo vi /etc/hosts.allow add this: portmap mountd nfsd statd lockd rquotad : a.a.a.a, b.b.b.b , c.c.c.c {ipaddresses}

sudo vi /etc/exports add this: /mnt/store
a.a.a.a(rw,sync,no_subtree_check,fsid=0) and /mnt/store
and /mnt/store c.c.c.c(rw,sync,no_subtree_check,fsid=0)

sudo exportfs -ra
sudo /etc/init.d/portmap restart
sudo /etc/init.d/nfs-kernel-server restart

In Server-A , Server-B Server-C and do this

sudo apt-get install portmap nfs-common
sudo vi /etc/hosts.deny SET: `portmap : ALL`

sudo vi /etc/hosts.allow SET: portmap : e.e.e.e {Server-X's ipaddress}

sudo vi /etc/default/nfs-common SET: NEED_IDMAPD=yes and NEED_GSSD=no

sudo vi /etc/idmapd.conf under [Mapping] add Nobody-User = nobody and
Nobody-Group = nogroup

modprobe nfs
mkdir /var/www/html/YOUR_DRUPAL_FOLDER/sites/default/files/shared
sudo mount -t nfs4 e.e.e.e:/ /var/www/html/YOUR_DRUPAL_FOLDER/sites/default/files/shared

Step 6 : Now you can place all the files and folders present in "sites/default/files" (that we skipped in Step: 1) place it in "/mnt/store" in Server-E .

And your Multi-Server Drupal Set-up is ready :).

If You Think This Post has helped you buy us a Coffee :)

Make Donation

  • Other: $

Donate now