Wednesday, August 23, 2017

How to fix DRBD recovery from split brain

Step 1: Start drbd manually on both nodes
Step 2: Define one node as secondary and discard data on this
drbdadm secondary all
drbdadm disconnect all
drbdadm -- --discard-my-data connect all
Step 3: Define anoher node as primary and connect
drbdadm primary all
drbdadm disconnect all
drbdadm connect all

Tuesday, August 22, 2017

Change Mysql Data Directory

  1. Stop MySQL using the following command:
    sudo /etc/init.d/mysql stop
  2. Copy the existing data directory (default located in /var/lib/mysql) using the following command:
    sudo cp -R -p /var/lib/mysql /newpath
  3. edit the MySQL configuration file with the following command:
    sudo gedit /etc/mysql/my.cnf   # or perhaps /etc/mysql/mysql.conf.d/mysqld.cnf
  4. Look for the entry for datadir, and change the path (which should be /var/lib/mysql) to the new data directory.
  5. In the terminal, enter the command:
    sudo gedit /etc/apparmor.d/usr.sbin.mysqld
  6. Look for lines beginning with /var/lib/mysql. Change /var/lib/mysql in the lines with the new path.
  7. Save and close the file.
  8. Restart the AppArmor profiles with the command:
    sudo /etc/init.d/apparmor reload
  9. Restart MySQL with the command:
    sudo /etc/init.d/mysql restart

Friday, August 18, 2017

Configuration DRDB

1. install DRBD  > sudo apt install drbd8-utils
To configure drbd, on the first host edit /etc/drbd.conf

global { usage-count no; }
common { syncer { rate 100M; } }
resource r0 {
        protocol C;
        startup {
                wfc-timeout  15;
                degr-wfc-timeout 60;
        net {
                cram-hmac-alg sha1;
                shared-secret "secret";
        on eoblas03 {
                device /dev/drbd0;
                disk /dev/sdb1;
                meta-disk internal;
        on eoblas03 {
                device /dev/drbd0;
                disk /dev/sdb1;
                meta-disk internal;
3.  Now copy /etc/drbd.conf to the second host:
     scp /etc/drbd.conf drbd02:~
4.  Now using the drbdadm utility initialize the meta data storage.  On each server
    suudo drbdadm create-md r0
5.  Next, on both hosts, start the drbd daemon:
    sudo systemctl start drbd.service 
6.  On the drbd01, or whichever host you wish to be the primary, enter the following:
    sudo drbdadm -- --overwrite-data-of-peer primary all 
7.  After executing the above command, the data will start syncing with the secondary host.  To watch the progress, on
          drbd02 enter the following:
    watch -n1 cat /proc/drbd
    To stop watching the output press Ctrl+c.
8.  Finally, add a filesystem to /dev/drbd0 and mount it:
    sudo mkfs.ext3 /dev/drbd0
    sudo mount /dev/drbd0 /srv