实验环境:server3:172.25.29.3
server4:172.25.29.4
server6:172.25.29.6
下载 heartbeat-3.0.4-2.el6.x86_64.rpm
heartbeat-devel-3.0.4-2.el6.x86_64.rpm
heartbeat-libs-3.0.4-2.el6.x86_64.rpm
ldirectord-3.9.5-3.1.x86_64.rpm
[[email protected] ~]# yum install -y *
[[email protected] ~]# scp * [email protected]:/root/
[[email protected] ~]#cd /etc/ha.d/
[[email protected] hd.d]# rpm -q heartbeat -d
[[email protected] hd.d]# cp /usr/share/doc/heartbeat-3.0.4/{ha.cf,authkeys,haresources} .
[[email protected] hd.d]#vim ha.cf
29 logfile /var/log/ha-log
48 keepalive 2
56 deadtime 30
61 warntime 10
71 initdead 60
76 udpport 723
91 bcast eth0 # Linux
211 node server3.example.com 主服务器
212 node server4.example.com 备服务器
220 ping 172.25.29.250
253 respawn hacluster /usr/lib64/heartbeat/ipfail
259 apiauth ipfail gid=haclient uid=hacluster
[[email protected] hd.d]# vim haresources
151 server3.example.com IPaddr::172.25.29.100/24/eth0 httpd
[[email protected] ha.d]# vim authkeys
23 auth 1
24 1 crc
[[email protected] hd.d]#chmod 600 authkeys
[[email protected] hd.d]#scp ha.cf haresources authkeys 172.25.29.4:/etc/ha.d/
[[email protected] ~]# /etc/init.d/heartbeat start
[[email protected] ~]# yum install -y *
[[email protected] ~]# /etc/init.d/heartbeat start
真机#rpm -qn | grep 172.25.29.100 (查看访问地址)
[[email protected] ~]# /etc/init.d/network stop (当断开网路时集群会把server3踢出去重启)
#######访问172.25.29.100
@@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@
一.编译安装drbd安装包
1.在server3 server4 上分别添加一个4G的虚拟磁盘。
server3:
下载一个drbd-8.4.3.tar.gz 安装包
[[email protected] ~]# ls
drbd-8.4.3.tar.gz
[[email protected] ~]# tar zxf drbd-8.4.3.tar.gz
[[email protected] ~]# ls
drbd-8.4.3.tar.gz
drbd-8.4.3
[[email protected] ~]# cd drbd-8.4.3
[[email protected] drbd-8.4.3]#vim test.spec (以spec结尾的文件为编译安装包文件)
[[email protected] drbd-8.4.3]# ./configure --enable-spec --with-km
[[email protected]ver3 drbd-8.4.3]#yum install -y gcc
[[email protected] drbd-8.4.3]# ./configure --enable-spec --with-km
[[email protected] drbd-8.4.3]#yum install -y flex
[[email protected] drbd-8.4.3]# ./configure --enable-spec --with-km
[[email protected] drbd-8.4.3]#yum install -y rpm-build
[[email protected] drbd-8.4.3]# ./configure --enable-spec --with-km
[[email protected] drbd-8.4.3]#rpmbuild -bb drbd.spec
[[email protected] drbd-8.4.3]#cp ~/drbd-8.4.3.tar.gz ~/rpmbuild/SOURCES/
[[email protected] drbd-8.4.3]#rpmbuild -bb drbd.spec
error: Failed build dependencies:
[[email protected] drbd-8.4.3]#yum install -y kernel-devel
[[email protected] drbd-8.4.3]#rpmbuild -bb drbd.spec
[[email protected] ~]# cd /root/rpmbuild/RPMS/x86_64/
[[email protected] x86_64]# ls
drbd-8.4.3-2.el6.x86_64.rpm
drbd-bash-completion-8.4.3-2.el6.x86_64.rpm
drbd-debuginfo-8.4.3-2.el6.x86_64.rpm
drbd-heartbeat-8.4.3-2.el6.x86_64.rpm
drbd-km-2.6.32_431.el6.x86_64-8.4.3-2.el6.x86_64.rpm
drbd-km-debuginfo-8.4.3-2.el6.x86_64.rpm
drbd-pacemaker-8.4.3-2.el6.x86_64.rpm
drbd-udev-8.4.3-2.el6.x86_64.rpm
drbd-utils-8.4.3-2.el6.x86_64.rpm
drbd-xen-8.4.3-2.el6.x86_64.rpm
[[email protected] x86_64]#rpm -ivh *
[[email protected] x86_64]#scp * [email protected]:/root/
server4:
[[email protected] ~]#ls
drbd-8.4.3-2.el6.x86_64.rpm
drbd-bash-completion-8.4.3-2.el6.x86_64.rpm
drbd-debuginfo-8.4.3-2.el6.x86_64.rpm
drbd-heartbeat-8.4.3-2.el6.x86_64.rpm
drbd-km-2.6.32_431.el6.x86_64-8.4.3-2.el6.x86_64.rpm
drbd-km-debuginfo-8.4.3-2.el6.x86_64.rpm
drbd-pacemaker-8.4.3-2.el6.x86_64.rpm
drbd-udev-8.4.3-2.el6.x86_64.rpm
drbd-utils-8.4.3-2.el6.x86_64.rpm
drbd-xen-8.4.3-2.el6.x86_64.rpm
[[email protected] ~]#rpm -ivh *
二.DRBD配置
[[email protected] ~]# cd /etc/drbd.d
[[email protected] drbd.d]# vim dbdata.res
resource dbdata {
meta-disk internal;
device /dev/drbd1;
syncer {
verify-alg sha1;
}
on server3.example.com {
disk /dev/vda;
address 172.25.29.3:7789;
}
on server4.example.com {
disk /dev/vda;
address 172.25.29.4:7789;
}
}
[[email protected] drbd.d]# scp dbdata.res 172.25.29.4:/etc/drbd.d/
[[email protected] drbd.d]# drbdadm create-md dbdata
[[email protected] drbd.d]# /etc/init.d/drbd start
Starting DRBD resources: [
create res: dbdata
prepare disk: dbdata
adjust disk: dbdata
adjust net: dbdata
]
.
[[email protected] drbd.d]# drbdadm create-md dbdata
[[email protected] drbd.d]# /etc/init.d/drbd start
Starting DRBD resources: [
create res: dbdata
prepare disk: dbdata
adjust disk: dbdata
adjust net: dbdata
]
.
[[email protected] drbd.d]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
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:f oos:4194140
[[email protected] drbd.d]# drbdadm primary dbdata --force
[[email protected] drbd.d]# watch cat /proc/drbd
[[email protected] drbd.d]# cat /proc/drbd (server3和server同步)
[[email protected] drbd.d]# mkfs.ext4 /dev/drbd1
[[email protected] drbd.d]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:4326500 nr:0 dw:132360 dr:4195168 al:34 bm:256 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] drbd.d]# mount /dev/drbd1 /mnt/
[[email protected] drbd.d]# cd /mnt
[[email protected] mnt]# ls
lost+found
[[email protected] mnt]# cp /etc/* .
[[email protected] mnt]# cd
[[email protected] ~]# umount /mnt/
[[email protected] drbd.d]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
ns:4326500 nr:0 dw:132360 dr:4195168 al:34 bm:256 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] ~]# drbdadm secondary dbdata
[[email protected] ~]# cat /proc/dr
drbd driver/
[[email protected] ~]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
ns:4328648 nr:0 dw:134508 dr:4195529 al:34 bm:256 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] ~]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
ns:4328648 nr:0 dw:134508 dr:4195529 al:34 bm:256 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] drbd.d]# drbdadm primary dbdata
[[email protected] drbd.d]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:4326500 nr:0 dw:132360 dr:4195168 al:34 bm:256 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] drbd.d]# mount /dev/drbd1 /mnt/
[[email protected] drbd.d]# cd /mnt
[[email protected] mnt]# ls (看到server3挂载的内容)
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
[[email protected] ~]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate 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:f oos:0
[[email protected] drbd.d]# drbdadm primary dbdata
[[email protected] drbd.d]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:4326500 nr:0 dw:132360 dr:4195168 al:34 bm:256 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[[email protected] drbd.d]# mount /dev/drbd1 /mnt/
[[email protected] drbd.d]# cd /mnt
[[email protected] mnt]# ls
(查看到创建的内容)
[[email protected] mnt]#rm -fr *
[[email protected] mnt]#ls
lost+found
[[email protected] mnt]#cd /var/lib/mysql
[[email protected]r3 mysql]# ll
总用量 20488
-rw-rw---- 1 mysql mysql 10485760 9月 25 21:38 ibdata1
-rw-rw---- 1 mysql mysql 5242880 9月 25 21:38 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 9月 25 21:37 ib_logfile1
drwx------ 2 mysql mysql 4096 9月 25 21:37 mysql
drwx------ 2 mysql mysql 4096 9月 25 21:37 test
[[email protected] mysql]#mv * /mnt/
[[email protected] mysql]#chown mysql.mysql /mnt/
[[email protected] mysql]#umount /mnt/
[[email protected] ~]#mount /dev/drbd1 /var/lib/mysql/
[[email protected] ~]#/etc/init.d/mysqld start
[[email protected] ~]#umount /dev/lib/mysql/
[[email protected] ~]#/etc/init.d/mysqld stop
[[email protected] drbd.d]# drbdadm secondary dbdata
[[email protected] ~]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by [email protected], 2016-09-23 09:29:11
1: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate 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:f oos:0
[[email protected] drbd.d]# drbdadm primary dbdata
[[email protected] drbd.d]# mount /dev/drbd1 /var/lib/mysql/
[[email protected] drbd.d]#/etc/init.d/mysqld start
[[email protected] drbd.d]#cd /var/lib/mysql/
[[email protected] drbd.d]#ls
lost+found ibdata1 ib_logfile0 ib_logfile1 mysql test mysql.sock
[[email protected] drbd.d]#/etc/init.d/mysqld stop
[[email protected] drbd.d]#cd
[[email protected] ~]#umount /var/lib/mysql/
[[email protected] ~]#drbdadm secondary dbdata
[[email protected] ~]#/etc/init.d/heartbeat stop
@@@@@@@@@@@@@@@@@
[[email protected] ~]#/etc/init.d/heartbeat stop
[[email protected] ~]#cd /etc/ha.d/
[[email protected] ha.d]# vim haresources
151 server3.example.com IPaddr::172.25.29.100/24/eth0 drbddisk::dbdata Filesystem::/dev/drbd1::/var/lib/mysql mysqld
[[email protected] ha.d]#scp haresources 172.25.29.4:/etc/ha.d/
[[email protected] ha.d]#/etc/init.d/heartbeat start
[[email protected] ha.d]#tail -f /var/log/ha-log
[[email protected] ~]#/etc/init.d/heartbeat start
[[email protected] ha.d]#tail -f /var/log/ha-log
集群自动把/dev/drbd1 挂载到server3的 /var/lib/mysql 上
@@@@@@@@@@@@
[[email protected] ~]#mysql
mysql> grant all on test.* to [email protected]‘172.25.29.%‘ identified by ‘Westos-123‘;
mysql> flush privileges;
mysql> quit
[[email protected] ~]#/etc/init.d/heartbeat stop
[[email protected] ~]#mysql -h 172.25.29.100 -u zheng -pWestos-123
mysql>show databases;
+--------------------+
| Database |
+--------------------+
| information_schema
| #mysql50#lost+found
| mysql |
| test | (集群帮助挂载成功)
+--------------------+