Ubuntu HA-Cluster mit DRBD und Heartbeat
Aus Howtos und Gedankenstuetzen
Inhaltsverzeichnis |
einfache Grundconfig für einen 2Node Cluster mit Apache2 Mysql PHP5
apt-get install heartbeat drbd8-utils apt-get install apache2 php5 mysqlserver libapache2-mod-php5
DRBD
drbd.conf
nano /etc/drbd.conf
global {
usage-count yes;
}
common {
syncer {
rate 100M;
}
}
resource web {
protocol C;
handlers {
pri-on-incon-degr "echo o > /proc/sysrq-trigger ; halt -f";
pri-lost-after-sb "echo o > /proc/sysrq-trigger ; halt -f";
local-io-error "echo o > /proc/sysrq-trigger ; halt -f";
# outdate-peer "/usr/sbin/drbd-peer-outdater";
}
startup {
wfc-timeout 0; ## Infinite!
degr-wfc-timeout 120; ## 2 minutes.
}
disk {
on-io-error detach;
}
net {
# timeout 60;
# connect-int 10;
# ping-int 10;
# max-buffers 2048;
# max-epoch-size 2048;
# on-disconnect-reconnect;
after-sb-0pri discard-younger-primary;
after-sb-1pri consensus;
after-sb-2pri disconnect;
rr-conflict disconnect;
# allow-two-primaries;
}
syncer {
rate 100M;
al-extents 257;
}
on ha1 {
device /dev/drbd0;
disk /dev/sdb;
address 192.168.0.1:7788;
flexible-meta-disk internal;
}
on ha2 {
device /dev/drbd0;
disk /dev/sdb;
address 192.168.0.2:7788;
flexible-meta-disk internal;
}
}
Hinweis
allow-two-primaries; sagt aus das zwei paralelle Zugriffe auf das DRBD Device möglich sind. Dabei schreiben die Nodes jeweils erstmal in ihre Metadata d.h. die Nodes haben auf ihren Bereich exclusiven Zugriff. Es ist nur eine erweiterte Option für ein aktive/aktive Setup.
DRDB Autostart
Muss nicht sein hat sich bei mir aber als gute brauchbare Lösung herausgestellt.
nano /etc/init.d/mountdrbd.sh
auf der 1. Node
#!/bin/bash drbdadm primary web mount /dev/drbd0 /pfad/zu/Mountpoint
auf der 2. Node
#!/bin/bash drbdadm secondary web
Das ganze muss noch ausführbar gemacht werden und verlinkt werden nach:
sudo chmod +x /etc/init.d/mountdrbd.sh sudo ln -s /etc/init.d/mountdrbd.sh /etc/rc2.d/S99mountdrbd.sh
Test DRBD
Nach einem Neustart kann man nun sehen ob die gemachten Einstellungen funktionieren.
cat /proc/drbd
sollte folgendes auf der Primären Node liefern:
version: 8.0.11 (api:86/proto:86)
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by phil@mescal, 2008-02-12 11:56:43
0: cs:Connected st:Primary/Secundary ds:UpToDate/UpToDate C r---
ns:257 nr:257 dw:515 dr:609 al:0 bm:0 lo:0 pe:0 ua:0 ap:0
resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0
act_log: used:0/257 hits:27 misses:0 starving:0 dirty:0 changed:0
auf der Sekundären:
version: 8.0.11 (api:86/proto:86)
GIT-hash: b3fe2bdfd3b9f7c2f923186883eb9e2a0d3a5b1b build by phil@mescal, 2008-02-12 11:56:43
0: cs:Connected st:Secundary/Primary ds:UpToDate/UpToDate C r---
ns:257 nr:257 dw:515 dr:609 al:0 bm:0 lo:0 pe:0 ua:0 ap:0
resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0
act_log: used:0/257 hits:27 misses:0 starving:0 dirty:0 changed:0
Heartbeat
ha.cf
nano /etc/ha.d/ha.cf
logfile /var/log/ha-log logfacility local0 udpport 694 keepalive 1 deadtime 10 warntime 5 initdead 15 bcast eth0 #deadping 10 node ha1 ha2 crm off #auto_failback on #respawn root /usr/lib/heartbeat/ipfail
Autofailback also die Funktion das die Resourcen wieder auf die primäre Node "zurückwandern" scheint nicht zu funktionieren. Deswegen habe ich diese Funktion auskommentiert.
haresources
nano /etc/ha.d/haresources
- 10.16.0.52 ist die IP des Clusters d.h die IP-Adresse unter der, der Apache Service zu erreichen ist.
- ha1 ist eigentlich der Name der primären Node (für autofailback).
- drbddisk::web ist das DRBD Device welches als Resource im Cluster benutzt wird.
- hinter Filesystem steht das DRBD Device sowie dessen Mountpoint und die Art Filesystem
- apache2 ist der Dienst der geclustert werden soll.
Auf beiden Nodes:
ha1 10.16.0.52 drbddisk::web Filesystem::/dev/drbd0::/home/data::xfs apache2
authkeys
nano /etc/ha.d/authkeys
auth 3 3 md5 dein-Super-geheimes-passwort
Die Datei authkeys braucht dann noch:
chmod 600 /etc/ha.d/authkeys
Test Gesamtkonfiguraton
Nun kann getestet werden mit:
/etc/init.d/heartbeat stop
Wenn man nun auf der anderen Node schaut:
ps -ef |grep apache
läuft der Apache nun hier.
www-data 6343 6342 0 14:00 ? 00:00:00 /usr/sbin/apache2 -k start www-data 6345 6342 0 14:00 ? 00:00:00 /usr/sbin/apache2 -k start www-data 6350 6342 0 14:00 ? 00:00:00 /usr/sbin/apache2 -k start root 6459 5144 0 14:27 pts/0 00:00:00 grep apache
und die virtuelle IP-Adresse des Cluster befindet sich nun auf der zweiten Node.
ifconfig
eth0:0 Link encap:Ethernet HWaddr 00:0c:29:11:b3:c6
inet addr:10.16.0.52 Bcast:10.16.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:17 Base address:0x2000
Das nützt uns so aber noch nichts sondern wir wollen ja das Umswitchen der Nodes wenn z.B. auf einer das Netz also eth0 weg ist.
Also auf der aktiven Node:
ifconfig eth0 down
und der Apache und die virtuelle Adresse ziehen um.