DRBD MySQL HowTo
Mysql- apache- Pacemaker- openais- drbd active/passive cluster with debian lenny
First we need 2 machines, each with 2 NIC's. On both node' s we install debian with 5 partitions:
/boot / /swap /drbd for the meta data /service the partition you want to mirror
Now we have to do some basic steps.
zero out the drbd-meta-data partition
dd if=/dev/zero of=/dev/sda7
umount /dev/sda7 /drbd
nano /etc/fstab
cause mounting the drbd device will do pacemaker.
proc /proc proc defaults 0 0 /dev/mapper/vol--root-root / ext3 errors=remount-ro 0 1 /dev/sda1 /boot ext3 defaults 0 2 #/dev/sda7 /drbd ext3 defaults 0 2 /dev/sda6 none swap sw 0 0 /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0 /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0 /dev/drbd0 /service ext3 defaults 0 2
Configure both network cards, one for the outside world, the other for the cluster interconnect, which should be a own net. ex.
nano /etc/network/interfaces
The loopback network interface auto lo iface lo inet loopback # The primary network interface #allow-hotplug eth0 auto eth0 iface eth0 inet static address 10.100.100.203 netmask 255.255.255.0 gateway 10.100.100.3 dns-nameservers 10.100.100.3 auto eth1 iface eth1 inet static address 10.100.101.2 netmask 255.255.255.248
you have to edit
nano /etc/hosts:
10.100.101.1 bart.nopanic.loc bart 10.100.101.2 lisa.nopanic.loc lisa
these hostnames are used in drbd.conf.
fromdrbd.org
We have to install some additional software: make, gcc, build-essential, flex After this we beginn to install drbd. Best choice is to do it from source : http://oss.linbit.com/drbd/ and take the latest stable release. apt-get install kernel-headers-$(uname -r) tar xzvf drbd-8.3.2.tar.gz After changing into your unpacked DRBD sources directory, you should now change into the kernel module subdirectory, simply named drbd, and build the module there: cd drbd make clean all cd /usr/src/drbd-x.y.z make tools cd /usr/src/drbd-x.y.z make install cd /usr/src/drbd-x.y.z make install-tools nano /etc/drbd.conf on bart { device /dev/drbd0; disk /dev/sdb5; #The partition you want to mirror address 10.100.101.1:7788; # the cluster interconnect IP meta-disk /dev/sda7 [0]; #The partition for the meta-data # meta-disk is either 'internal' or '/dev/ice/name [idx]' # # You can use a single block device to store meta-data # of multiple DRBD's. # E.g. use meta-disk /dev/hde6[0]; and meta-disk /dev/hde6[1]; # for two different resources. In this case the meta-disk # would need to be at least 256 MB in size. # # 'internal' means, that the last 128 MB of the lower device # are used to store the meta-data. # You must not give an index with 'internal'. } on lisa { device /dev/drbd0; disk /dev/sdb5; address 10.100.101.2:7788; meta-disk /dev/sda7 [0]; } } Copy the drbd.conf it to the other node, it has to be the same on both nodes. 1.Create device metadata. This step must be completed only on initial device creation. It initializes DRBD's metadata: For „resource“ you have the resource name you defined in drbd.conf. If this is untouched it should be r0. drbdadm create-md resource v08 Magic number not found Writing meta data... initialising activity log NOT initialized bitmap New drbd meta data block sucessfully created. success 2.Attach to backing device. This step associates the DRBD resource with its backing device: drbdadm attach resource 3.Set synchronization parameters. This step sets synchronization parameters for the DRBD resource: drbdadm syncer resource 4.Connect to peer. This step connects the DRBD resource with its counterpart on the peer node: drbdadm connect resource Tip You may collapse the steps drbdadm attach, drbdadm syncer, and drbdadm connect into one, by using the shorthand command drbdadm up. 5.Observe /proc/drbd. DRBD's virtual status file in the /proc filesystem, /proc/drbd, should now contain information similar to the following: cat /proc/drbd version: 8.3.0 (api:88/proto:86-89) GIT-hash: 9ba8b93e24d842f0dd3fb1f9b90e8348ddb95829 build by buildsystem@linbit, 2008-12-18 16:02:26 1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r--- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:200768 The Inconsistent/Inconsistent disk state is expected at this point. By now, DRBD has successfully allocated both disk and network resources and is ready for operation. What it does not know yet is which of your nodes should be used as the source of the initial device synchronization. ** ** from drbd.org
On the node which should be the primary:
drbdadm – --overwrite-data-of-peer primary r0
create under / a service directory That drbd can mount you have to edit:
nano /etc/fstab /dev/drbd0 /service ext3 defaults 0 2
Now the drbd failover should work.
Pacemaker add to your source.list:
nano /etc/apt/sources.list For Debian 5.0 (lenny): deb http://people.debian.org/~madkiss/ha-corosync lenny main For Debian unstable (sid): deb http://people.debian.org/~madkiss/ha-corosync sid main Once this has been completed, run: apt-get update Finally, to install Pacemaker simply decide which stack you wish to use and run apt-get install pacemaker-openais
generate key for openais
lisa:~ # ais-keygen
bart:~ # ais-keygen
nano /etc/ais/openais.conf interface { # The following values need to be set based on your environment ringnumber: 0 bindnetaddr: 10.100.100.0 mcastaddr: 226.94.1.1 mcastport: 5405 } } logging { to_stderr: yes debug: off timestamp: on to_file: no to_syslog: yes syslog_facility: daemon } amf { mode: disabled } service { # Load the Pacemaker Cluster Resource Manager ver: 0 name: pacemaker use_mgmtd: yes } aisexec { user: root group: root }
lisa:~ # scp /etc/ais/openais.conf root@bart:/etc/ais/openais.conf lisa:~ # /etc/init.d/openais start bart:~ # /etc/init.d/openais start
generate a file with:
nano /root/config
copy & paste:
primitive drbd_mysql ocf:linbit:drbd \ params drbd_resource="r0" \ op monitor interval="15s" primitive fs_mysql ocf:heartbeat:Filesystem \ params device="/dev/drbd/by-res/r0" directory="/service/" fstype="ext3" primitive ip_mysql ocf:heartbeat:IPaddr2 \ params ip="10.100.100.200" nic="eth0" primitive mysqld lsb:mysql primitive apache lsb:apache2 group mysql fs_mysql ip_mysql mysqld apache ms ms_drbd_mysql drbd_mysql \ meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true" colocation mysql_on_drbd inf: mysql ms_drbd_mysql:Master order mysql_after_drbd inf: ms_drbd_mysql:promote mysql:start property $id="cib-bootstrap-options" \ no-quorum-policy="ignore" \ stonith-enabled="false" \ expected-quorum-votes="2" \ dc-version="1.0.4-2ec1d189f9c23093bf9239a980534b661baf782d" \ cluster-infrastructure="openais"
Mysql
aptitude install mysql-server nano /etc/mysql/my.cnf datadir = /service/mysql bind-address = 10.100.100.200 # clusterIP
have a look which node is the primary drbd node.:
cat /proc/drbd lisa:~# cat /proc/drbd version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by , 2009-09-07 00:18:26 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r---- ns:136 nr:336 dw:472 dr:3186 al:6 bm:8 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
you see primary on the left side. This is okay, otherwise when primary is on the right site the other node is the primary and we have to do the following steps there. On primary:
mount /dev/drbd0 /service cp -Ra /var/lib/mysql/ /service/mysql when we also have want apache: mkdir /service/etc cp -Ra /etc/apache2/ /service/etc/ ls /service/etc/apache2 apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled umount /dev/drbd0 /service
if you dont want apache dont forget to take it away from “config“ file no we have to edit:
nano /etc/apache2/apache2.conf and correct the pathes for ls /service/etc/apache2 apache2.conf conf.d envvars httpd.conf mods-available mods-enabled ports.conf sites-available sites-enabled
aptitude install phpmyadmin
lisa:~# crm crm(live)# configure crm(live)configure# load replace /root/config crm(live)configure# commit crm(live)configure# quit bye
lisa:~# crm status==
Last updated: Tue Sep 22 18:33:02 2009 Stack: openais Current DC: lisa - partition with quorum Version: 1.0.4-2ec1d189f9c23093bf9239a980534b661baf782d 2 Nodes configured, 2 expected votes 2 Resources configured.==
Online: [ bart lisa ] Master/Slave Set: ms_drbd_mysql Masters: [ lisa ] Slaves: [ bart ] Resource Group: mysql fs_mysql (ocf::heartbeat:Filesystem): Started lisa ip_mysql (ocf::heartbeat:IPaddr2): Started lisa mysqld (lsb:mysql): Started lisa apache (lsb:apache2): Started lisa</re>