1. Planning
System CentOS 64bit
DRBD version 9.0.0
Heartbeat version 3.0.6< /span>
MySQL version 5.6.27
< span style="font-family:'黑体', SimHei;"> DRBD disk/dev/sdb1< /span>
Host name (IP) node1(192.168.10.132)
node2(192.168.10.133) node2(192.168.10.133)
Note: SeLinux and Firewalld have been closed.
Second, installation
Heartbeat installation: http://www.voidcn.com/article/p-ksprrvhx-bcx.html
DRBD installation: http://www.voidcn.com/article/p-dgufxion- bcx.html
MySQL installation:
#wget http://dev.mysql.com/get/mysql-community-release -el7-5.noarch.rpm# rpm -ivh mysql-community-release-el7-5.noarch.rpm ##Install MySQL源# yum -y install mysql-server mysql-devel ##Install MySQL
< p>
Three, configure mutual trust
HA-01:
ssh-keygen rsa -f ~/.ssh/id_rsa -P ``ssh-copy-id -i.ssh/id_rsa.pub [email protected]
HA-02:
ssh-keygen -t rsa -f ~/.ssh/id_rsa -P''ssh-copy-id -i.ssh/id_rsa.pub [email protected]
four, configuration
①Configure DRBD
a. The main configuration file drbd.conf
#cat/etc/drbd.conf# You can find an example in /usr/share/doc/drbd.../drbd.conf.exampleinclude"drbd.d/global_common.conf";include"drbd.d /*.res";
b. Configure global_common.conf
#cat /etc/drbd.d/global_common.conf|grep-v"#" global {usage-count no; no; ##Whether to participate in drbd user statistics, the default option is YES}common {handlers {}startup {}options {}disk{}net{}}
c. New res resource configuration file
#vi/etc/drbd.d/drbd.res ##Create a new res resource named drbd resource r1 # definition of resources group name r1 net {cram-hmac-alg sha1; ## sha1 using encryption shared-secret "123456"; ## generating a shared key} volume 1 {## defines the volume group device / dev / drbd1; ## logical device path (to establish block device) disk / dev / sdb1; ## physical device paths meta-disk internal (partition for replication); ## meta data mode information is stored, and where an internal storage, i.e., real data, and on the stored together} on node1 {## on the beginning, followed by a host name (required -n same uname) node-id 0; address 192.168.10.132:7000; ## drbd listen address and port disposed} on node2 {node-id 1; address 192.168.10.133:7000;} connection {host node1 port 7000; host node2 port 7000; net {protocol C; ## drbd using the third synchronization protocol, the host interface receives write represents After the entry is confirmed, it is considered that the writing is completed}}}}}}}}}}}}}}}}}}}}}}}}}}
d. Mount a new disk
# fdisk /dev/sdb
—–> n
—–> 1
– —-> Default
—–> +300M —–> w
f. Create device metadata and Format the disk
#dd if=/dev/zero of=/dev/sdb1 bs=1M count=10#Use the specified size Block copy of a file# drbdadm -c /etc/drbd.conf create-md all ##Create equipment metadata# mkfs.ext4 /dev/drbd1 dir # mkfs.ext4 /dev/drbd1 # mkfs.ext4 /dev/drbd1 # mkfs. -R mysql.mysql/data/mysql/#ln-s/etc/ha.d/resource.d/drbddisk/usr/local/heartbeat/etc/ha.d/resource.d/##Create drbddisk script to heartbeat Soft link of /etc/ha.d/resource.d/
< br>
②Heartbeat configuration
< /p>
The configuration of Heartbeat mainly involves three files: ha.cf, haresources, and authkeys . Among them, ha.cf is the main configuration file, haresource is used to configure the service to be hosted by Heartbeat, and authkey is used to specify the authentication method of Heartbeat.
< p style="white-space:normal;">a. Configure ha.cf
#cat/usr/local/heartbeat/etc/ha.d/ha.cf|grep ^[^#] logfile/var/log/ha-log #log file#alk#alility log file #Set the heartbeat (monitoring) time to 2 seconds deadtime 30 ##Specify that if the standby node does not receive the heartbeat signal of the master node within 30 seconds, it will take over the resources of the master server warntime 10 #Specify the time of the heartbeat delay #120 The neglected time period reserved after the system is started or restarted, the value is at least twice the deadtime udpport 694 ##Broadcast/unicast communication Udp port ucast eno16777736#Using network card eno16777736 of udp unicast , The following is the opposite IP auto_failback on the white node name of the node 1-p-node display 2-p-node name, consistent with u 192.168. space:normal;">
b. Configure haresources
# cp resource-agents-3.9.6/heartbeat/mysql /usr/local/heartbeat/ etc/ha.d/resource.d/##Copy the MySQL script to heartbeat's /etc/ha.d/resource.d/下#cat /usr/local/heartbeat/etc/ha.d/haresources|grep^[ ^#]node1 IPaddr::192.168.10.222/24/eno16777736 drbddisk::r1 Filesystem::/dev/drbd1::/data::ext4 mysql
node1 is the master node of the HA cluster, IPaddr is the heartbeat self With the execution script, heartbeat will first execute the operation of /etc/ha.d/resource.d/IPaddr 192.168.10.222/24 start, that is, a virtual address with a subnet mask of 255.255.255.0 and an IP of 192.168.10.222. This IP is the network address used by Heartbeat to provide services to the outside world. At the same time, specify the network interface used by this IP. Then, specify the resources of the DRBD used, and then Heartbeat will perform the mounting operation of the shared disk partition, "Filesystem::/dev/sdb1 ::/data::ext4" is equivalent to performing the mount operation on the command line, that is, "mount -t ext4 /dev/sdb1 /data", and finally start the MySQL service in turn.
c. Configure authkeys
#grep-v"#"/usr/local/heartbeat/etc/ha .d/authkeys auth 22 sha1 HI!Fill in the serial number after auth, which can be any Fill in, but the beginning of the second line must be the serial number name, and then the verification method, which supports three (crc md5 sha1) verification methods, and the last is a custom key
d. Copy the configuration file to node2
# Scp /usr /local/heartbeat/etc/ha.d/* [email protected]:/usr/local/heartbeat/etc/ha.d/Note: You need to change the IP in the ucast of ha.cf to the IP of node1 (here is 192.168.10.132).
③Configure MySQL
#vi/etc/my.cnfdatadir=/data/mysql ##modify MySQL data storage directory
5. Test
①
#drbdadmup r1 #drbdadm up r1 ##Enable this resource#drbd-overview1:r1/1Connected(2*)UpSecondTostart(2*)SecondTostart(2*)Up) systemctl start heartbeat
Automatic mounting has been implemented
②Failover test
node1:
#systemctl stop heartbeatnode2:
Normal switching has been achieved