Take 2 Centos Servers (nfs1 and nfs2 will do nicely) and install ELrepo and EPEL on them both:
1 2 3
Each of them should ideally have 2 NICS, with the secondary ones just used for DRBD sync purposes. We’ll give these the address 10.0.0.1/32 and 10.0.0.2/32.
I am also assuming that you have disabled the firewall and SELinux – I do not recommend that for production, but for testing it is fine.
Install DRBD 8.4 on the both:
On each node the file /etc/drbd.d/global_common.conf should contain:
1 2 3 4 5 6 7 8
and /etc/drbd.d/main.res should contain:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
On both nodes you will need to create the resource metadata:
and start the daemons
service drbd status will give you:
1 2 3 4 5
Both devices or secondary and inconsistent, this is normal at this stage. Choose a node to be your primary and run:
And it start sync’ing, which will take a long time. You can temporarily make it faster with (on one node:
Put it back again with drbdadm adjust main
On your primary node you can now create a fiiesystem. I’m using ext4 for no good reason other than it being the default. Use whatever you are most comfortable with.
If you diid a minimal Centos install, then you willl need to install the nfs-utils package (yum install nfs-utils). Prepare your mount points and exports on both servers:
Now we do the actual NFS set up. We previously choose nfs1 as our master when you used it to trigger the initial sync. On nfs1 mount the replicated volumes, move the NFS data to it, then create symlinks to our replicated data.
1 2 3 4 5
If you get errors about not bring able to remove directories in /var/lib/nfs do not worry.
Now a little preparation on nfs2:
This will create a broken symbolic link, but it will be fixed when everything fails over.
Heartbeat is in the EPEL repository, so enable that and install it on both nodes:
Make sure that /etc/ha.d/ha.cf contains:
1 2 3 4
The values in node should be whatever
uname -n returns.
Now create /etc/ha.d/haresources:
That is a little cryptic, so I’ll explain; nfs1 is the primary node, IPaddr sets up a floating address on eth0 that our clients will connect to. This has a resource drbddisk::main bound to it, which sets our main to resource to primary on nfs1. Filesystem mounts /dev/drbd0 at /drbd on nfs1. Finally the the services nfslock and nfs are started on nfs1.
Finally, it needs an authentication file in /etc/ha.d/authkeys, which should be chmod’ed to 600 to be only readable by root.
You should also make sure that nfslock and nfs do not start up by themselves:
Now you can start heartbeat and check it is working:
ifconfig on nfs1 should give you something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Note an entry for eth0:0 has miraculously appeared.
df should include the entry:
Reboot nfs1 and the services should appear on nfs2.
Connect an NFS client to you floating address (10.0.0.100) and you should be able to kill the live node and it will carry on.