I have recently installed DRBD + heartbeat + replication. I'm afraid I will forget it later. record it.
1, operating system: centOs 5.6 64-bit, mysql-5.5.11
2. Four machines, two as DRBD, and two as replication slave servers.
3. Name: MYSQLM1 IP: 172.17.94.209 name: MYSQLM2 IP: 172.17.94.210
The above two computers are respectively mounted on one 10 Gb hard disk as the DRBD Data Synchronization drive letter. Drive letter name:
/Dev/sdb1, Mount Directory:/data, synchronized disk name/dev/brbd0.
Name: MYSQLS1 IP: 172.17.94.211 name: MYSQLS2 IP: 172.17.94.212
VIP: 172.17.94.208
4. Edit the Host Name:
# Vi/etc/hosts
Add the following two rows;
172.17.94.209 MYSQLM1
172.17.94.210 MYSQLM2
Both Computers need to be added.
5. Install DRBD and Heartbeat
Yum-y install drbd83 kmod-drbd83
Yum-y install heartbeat
Yum-y install heartbeat-ldirectord heart-pils heartbeat-stonith
6. Configure DRBD
#
# Please have a look at the example configuration file in
#/Usr/share/doc/drbd83/drbd. conf
#
Global {usage-count yes ;}
Common {syncer {rate 100 M ;}}
Resource r0 {
Protocol C;
Startup {
}
Disk {
On-io-error detach;
# Size 1G;
}
Net {
}
On MYSQLM1 {
Device/dev/drbd0;
Disk/dev/sdb1;
Address 172.17.94.209: 7898;
Meta-disk internal;
}
On MYSQLM2 {
Device/dev/drbd0;
Disk/dev/sdb1;
Address 172.17.94.210: 7898;
Meta-disk internal;
}
}
The configuration of slave node MYSQLM2 is exactly the same.
6. Run the following commands on two computers:
#/Etc/init. d/drbd start # start drbd
# Drbdadm create-md r0
# Mkfs. ext3/dev/brbd0
In this way, the/dev/drbd0 has been created for both computers.
7. Execute the following command on MYSQLM1 as the master server
# Drbdadm primary all # Set MYSQLM1 to primary
# Mount/dev/drbd0/data # mount/dev/drbd0 to/data Directory
Run the following command to view the status of drbd:
# Service drbd status
# Cat/proc/drbd
This completes the drbd configuration.
Then install mysql. you can install mysql by default in other places, but you need to install the database in the/data directory. Both servers must be installed in the/data directory.
Note 1: Write basedir and datadir TO my. cnf
NOTE 2: grant/data and/dev/drbd0 permissions to the mysql: mysql user group.
8. Configure heartbeat
8.1: Configure/etc/ha. d/authkeys
Vi/etc/ha. d/authkeys
Auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello!
Save and exit.
# Chmod 600/etc/ha. d/authkeys
The input operations on two computers are the same.
8.2: Configure/etc/ha. d/ha. cf
Debugfile/var/log/ha-debug
Logfile/var/log/ha-log
Logfacility/local0
Keepalive 2
Deadtime 30
Warntime 10
Udpport 694
Bcast eth0
Ucast eth0 172.17.94.210 # MYSQLM2 here is ucast eth0 172.17.94.209.
Node MYSQLM1
Node MYSQLM2
Ping 172.17.64.1 # Gateway
Ping group1 172.17.94.209 172.17.94.210
Worker fudge 1 # Number of active servers. The two servers are configured the same.
Save and exit. The configuration of MYSQLM2 is roughly the same. The difference is: "#" Red comment
8.3 Configure/etc/ha. d/haresources
Vi/etc/ha. d/haresources
MYSQLM1 IPaddr: 172.17.94.208/24/eth0: 0 drbddisk: r0 Filesystem:/dev/drbd0:/data: ext3 mysqld
Save and exit. The two computers have the same configuration.
8.4, start heartbeat
# Service heartbeat start
# Chkconfig -- add heartbeat
# Chkconfig heartbeat on
9. Split-brain processing
9.1: perform the following operations on the slave node:
# Dbdadm secondary r0
# Drbdadm -- discard-my-data connect r0
The master node is as follows:
# Drbdadm connect r0
Or use the 9.2 method.
9.2 perform the following operations on both ends:
# Drbdadm -- discard-my-data connect all
# Drbdadm connect all
The overall architecture is illustrated below: