first uninstall the mounts corresponding to the original disk devices on the two nodes Directory, and comment out the relevant lines in fstab to prevent automatic mounting when the system starts
yum install heartbeat.x86_64 heartbeat-libs.x86_64 -y
1. The mysql uid and gid of the two nodes must be the same< /p>
2. The heartbeat configuration files in the attachment are placed under /etc/ha.d/
3. The communication between DRBD and Heartbeat adopts a direct connection method to prevent interference and avoid Single point of failure of the switch.
4.Service needs the following settings, and the nodes on both sides must be consistent span>
mysqld does not start after booting,
drbd boot up
Heartbeart starts on boot
< /span>
Add static routing and go straight to the network card for communication, em2 is the DRBD directly connected network card, put in
HB1(10.0.1.11)
route add -host 10.0.1.12 dev em2
HB2(10.0.1.12)
route add -host 10.0.1.11 dev em2
Add static routing and go straight to the network card to communicate, eth2 is the Heartbeat directly connected network card
DRBD1(10.0.0.11)
route add -host 10.0 .0.12 dev eth2
DRBD2(10.0.0.11)
route add- host 10.0.0.11 dev eth2
< /span>
ha.cf
The 2 side profile of the file Keep the same, but if the heartbeat adopts unicast mode, remember that the corresponding lines of the configuration files on both sides need to be modified to the IP of the other node.
================= ================================================= ============
debugfile /var/log/ ha-debug
logfile /var/log/ha-log
logfacility local1
#options configure
keepalive 2
deadtime 30
warntime 10
initdead 120< /span>
#Multicast on the heartbeat network card
< span style="font-family:helvetica, arial, sans-serif;">#mcast eth2 225.0.0.7 694 1 0 //Multi-node adopts multicast mode, but dual-node is also possible
ucast eth2 192.168.0.82 //For dual nodes, you can consider using unicast mode, and the IP can be filled in with the other node
#node configure
#Do not automatically failback
auto_failback off //Master node After the downtime is restored, the resources will not be automatically taken over, and the database is okay. Don’t cut and go.
node cluster1 //Host name, use uname -n to view
node cluster2
crm no
========= ================================================= ====================
< p>haresources
< p>1.IPaddr, drbddisk, Filesystem, and mysqld are all files that exist in /etc/ha.d/resource.d or /etc/init.d. Heartbeat will automatically go to these two directories to find the corresponding commands.
2.IPaddr::192.168.1.151/24/eth1, which indicates the address/mask/and which network card the VIP is bound to.< /p>
3.drbddisk::r0, where r0 is the resource name of drbd, which can be viewed in drbd.conf
======================================== =======================================
cluster1 IPaddr::192.168.1.151/24/eth1 drbddisk::r0 Filesystem::/dev/drbd0 ::/var/lib/mysql::ext4 mysqld
========================================== =====================================
< p>
authkeys
span>
The configuration files on both sides of the file are the same
The file permission attribute must be 600
< span style="font-family:helvetica, arial, sans-serif;">================================ ===============================================
auth 1
1 sha1 47e9336850f1db6fa58bc470bc9b7810eb397f04
================================================= ==============================
< span style="font-size:14px;">
drbd.conf
============================= =================================================
#
# please have aa look at the example configuration file in
# /usr /share/doc/drbd83/drbd.conf
#
global {
# minor-count 64;
# dialog-refresh 5; # 5 seconds
# disable-ip-verification;
usage-count no;
}
common {
< span style="font-family:helvetica, arial, sans-serif;"> syncer {rate 100M; }
}
resource r0 { span>
protocol C;
handlers {
pri-on- incon-degr “/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b> /proc/sysrq-trigger; reboot- f”;
pri-lost-after-sb “/usr/lib/drbd/notify -pri-lost-after-sb.sh; /usr/lib/drbd/notify-emerg ency-reboot.sh; echo b> /proc/sysrq-trigger; reboot -f”;
local-io-error “/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o> /proc/sysrq-trigger; halt- f”;
fence-peer “/usr/lib/drbd/crm-fence-peer .sh”;
after-resync-target “/usr/lib/drbd/crm- unfence-peer.sh”;
}
net {
# timeout 60;
# connect-int 10;
# ping-int 10;
# max-buffers 2048;
# max-epoch-size 2048;< /span>
after-sb-0pri disconnect;
< span style="font-family:helvetica, arial, sans-serif;"> after-sb-1pri disconnect;
after-sb-2pri disconnect;
rr-conflict disconnect;< /span>
cram-hmac-alg “sha1”;
shared-secret “FDD123456”;
# Use the dopd (drbd outdate-peer daemon) function to ensure no switching when the data is out of sync (Heartbeat)
}
< span style="font-family:helvetica, arial, sans-serif;">disk {
On-io-error detach;
# fencing resource-only;< br clear="none"> # Use the dopd (drbd outdate-peer daemon) function to ensure no switching when the data is out of sync
}
startup {
wfc-timeout 120;
degr-wfc-timeout 120;
}
#on must be followed by the host name, Use uname -n to get
on cluster1 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.0.81:7788 ;
meta-disk internal;
< span style="font-family:helvetica, arial, sans-serif;">}
on cluster2 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.0.82:7788;
meta-disk internal;
}
}
========================================= =====================================
< p>< /p>
chk_mysql.sh
The function of this file is to check whether the MySQL process exists, and if it does not exist, it will kill heartbeat and trigger the standby node to take over the business.
The file is added with executable permissions and placed under /usr/bin, and then placed at the end of the start section of /etc/init.d/mysql: span>
case “$1” in
start )
start
bash /usr/bin/chk_mysql.sh &
;;
This can be started with mysql startup span>
===================================== ======================================< /span>
< span style="font-size:14px;">#!/bin/bash
< span style="font-family:helvetica, arial, sans-serif;">#filename:chk_mysql.sh
CHK_MYSQL=$(ps -C chk_mysql.sh –no-header|wc -l)
if [[ “$CHK_MYSQL” -gt 0 ]]
then
echo “chk_mysql.sh is started” p>
exit 0
else
while test 1 = 1
do
DRBD=$(drbd-overview |awk'{print $3}’|awk -F/'{print $1}’)
if [[ “$DRBD” = “Primary” ]]
then
echo “DRBD is Primary,it’s going to check MySQL status”
MYSQL=$(ps -C mysqld –no-header|wc -l)
if [[ “$MYSQL” -eq 0 ]]
echo heart echo heart” clear=”none”> $(killall heartbeat) && sleep 60 && break
else
echo echo MySQL is runing,do nothing”
sleep 60
fi fi
else
echo “DRBD is not Primary, do nothing”< br clear="none"> sleep 60
fi
done
fi
============ ===============================================