Let's talk about Network Filesystem Replication.
Network filesystem replication is often used today in many scenarios:
Replication of a filesystem for security reasons: if one node fails, the other node isaccessible. To replicate a filesystem to another company headquarter, so each emplyee has accessto his data locally and not through a public network. But if he goes to the other headquarter he has all his data, and again he can access locally.As you can imagine, this kind of system isoften used to build filesystems for cluster environment.
We have chosen to implement the solution with DRDB. It's main porpouse is (as other systems like this) High Availability and Disaster Recovery for file systems.
We implement the solution with Debian 8, but it should work also on Ubuntu.
PrerequisitesBefore we start, here are the prerequisites:
At least 2 Debian servers. Debian is installed as a minimal installation (not necessary at all if you know what are you doing on production systems) recommended guide https://www.howtoforge.com/tutorial/debian-8-jessie-minimal-server/ At least 2 linux disks in each server: /dev/sda for the linux installation, /dev/sdb for the DRDB installation.ATTENTION!!!: During installation, all data on disk /dev/sdb will be destroyed, so don't work on a disk with data inside.
DRBD InstallationIn our example, I will use two nodes, wich are:
192.168.152.100 mysql1.local.vm 192.168.152.110 mysql2.local.vmOn all nodes, modify the file /etc/hosts as follows:
127.0.0.1 localhost
192.168.152.100 mysql1.local.vm mysql1
192.168.152.110 mysql2.local.vm mysql2
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Then execute the following commands to install DRDB:
apt-get update
apt-get -y upgrade
apt-get installdrbd-utils
Configuration Primary/Secondary - Disaster RecoveryThe main configuration file is /etc/drbd.conf wich looks like the following one:
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
By convention, /etc/drbd.d/global_common.conf contains the global andcommon sections of the DRBD configuration, whereas the .res files contain oneresource in each section.
In our example we do a minimalsetup that replicates the data on the two nodes. O n each node do the following modification:
We'll start editing the file /etc/drbd.d/global_common.conf modify the default line from
global {
usage-count yes ;
# minor-count dialog-refresh disable-ip-verification
}
...
net {
protocol C;
# protocol timeout max-epoch-size max-buffers unplug-watermark
# connect-int ping-int sndbuf-size rcvbuf-size ko-count
# allow-two-primaries cram-hmac-alg shared-secret after-sb-0pri
# after-sb-1pri after-sb-2pri always-asbp rr-conflict
# ping-timeout data-integrity-alg tcp-cork on-congestion
# congestion-fill congestion-extents csums-alg verify-alg
# use-rle
}
...
Now we'll create the configuration file /etc/drbd.d/r0.resfor our resource. Create the file on all nodes and add this inside:
resource r0 {on mysql1.local.vm {
device /dev/drbd1;
disk /dev/sdb;
address 192.168.152.100:7789;
meta-disk internal;
}
on mysql2.local.vm {
device /dev/drbd1;
disk /dev/sdb;
address 192.168.152.110:7789;
meta-disk internal;
}
}
What we have done until now is the following:
You "opt in" to be included in DRBD’s usage statisticswithusage-count parameter. Resources are configured to use fully synchronous replication with Protocol Cunless explicitly specified otherwise. Our cluster consists of twonodes:mysql1andmysql2. We have a resource arbitrarily named r0 which uses /dev/sdb as the lower-level device, and is configured with internal meta data. The resource uses TCP port 7789 for its network connections, and binds to the IP addresses 192.168.152.100and 192.168.152.110 respectively.On all nodes initialize the metadata with the following command:
drbdadm create-md r0
You should see something like this:
--== Thank you for participating in the global usage survey ==--
The server's response is:
you are the 2963th user to install this version
initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.
success
Next, we enable the resource and initialize the first replication run, only on first node, it should start replicating:
drbdadm up r0drbdadm primary --force r0
To check if all is working well you can check the file /proc/drbd on both nodes and you shold see something like this:
Mysql1 [emailprotected]:# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
srcversion: 1A9F77B1CA5FF92235C2213
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:54624 nr:0 dw:0 dr:55536 al:0 bm:3 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:5188060
[>....................] sync'ed: 1.1% (5064/5116)Mfinish: 0:17:21 speed: 4,964 (4,964) K/sec Mysql2 [emailprotected]:# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
srcversion: 1A9F77B1CA5FF92235C2213
1: cs:SyncTarget ro:Secondary/Primary ds:Inconsistent/UpToDate C r-----
ns:0 nr:17496 dw:17496 dr:0 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:5225188
[>....................] sync'ed: 0.4% (5100/5116)Mfinish: 0:29:41 speed: 2,916 (2,916) want: 5,160 K/secDuring the build phase you can notice the UpToDate/Inconsistent , it's correct because this is the first sync of data.
After the filsystem is synced this shloud change to UpToDate/UpToDate like in the following log:
[emailprotected]:/home/sysop# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
srcversion: 1A9F77B1CA5FF92235C2213
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:5242684 nr:0 dw:0 dr:5243596 al:0 bm:320 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
Now we have a new block device, called/dev/drbd1 that we can format with our preferred filesystem type. For example, if we want to format it in ext4 and mount it on /var/www we can simply do:
[emailprotected]:/home/sysop# mkfs.ext4 /dev/drbd1
mke2fs 1.42.12 (29-Aug-2014)
Creazione del fil