高可用heartbate+DRBD

实验环境: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               |      (集群帮助挂载成功)
+--------------------+

时间: 2024-08-05 07:06:53

高可用heartbate+DRBD的相关文章

Mysql高可用(drbd+heartbeat+mysql)

Heartbeat和drbd和之前配的一样.这里微调了下drbd通信用专门的网卡,因此考虑限速就只有IO了. 关于mysql: yum install mysql-server mysql 把之前的/var/lib/mysql的数据和配置文件/etc/my.cnf备份出来,注意权限都是mysql 然后drbd挂载到/var/lib/mysql上把数据在copy到此目录. mkdir  /backup cd/var/lib/mysql/ cp  -ar * /backup/ cp  /etc/my

基于Corosync + Pacemaker+DRBD实现MySQL高可用集群

前言 在众多的高可用集群解决方案中,除了Heartbeat之外,Corosync也能提供类似于Heartbeat一样的功能,而且目前RedHat官方提供的高可用集群解决方案的程序包都以Corosync为主,所以在未来的日子Corosync会逐渐取代Heartbeat.本文带来的是基于Corosync + Pacemaker+DRBD的MySQL高可用集群解决方案. 相关介绍 Corosync Corosync是从OpenAIS中分支出来的一个项目,它在传递信息的时候可以通过一个简单的配置文件来定

高可用集群corosync+pacemaker+drbd+httpd----手动配置篇

共享存储高可用方案 -----DRBD Drbd  :Distributed Replicated Block Device 高可用集群中的文件共享方案之一 共享存储的常见实现方式 DAS:直接附加存储 Direct attached storage:通过专用线缆直接连接至主板存储控制器接口的设备成为直接附加存储.,如外置的raid阵列 并行口: IDE  SCSI 两种接口的区别: ide接口的存取过程: 首先将从文件的读取说起;当用户空间进程要读写文件时首先向内核发起系统调用,然后进程有用户

drbd与corosync/pacemaker 结合构建高可用mariadb服务

drbd与corosync/pacemaker 结合构建高可用mariadb drbd介绍: 高可用节点之间为了使切换节点时数据一致,不得不使用共享存储,共享存储一般只有两种选择:NAS 和 SAN.NAS是文件系统级别的共享,性能低下,访问也受限制,使用时有诸多不变:SAN块级别共享存储,但又太贵.当资金不足时,就可以考虑drbd. drbd是跨主机的块设备镜像系统,一主一从(两个主机只能有一个能进行写操作,slave主机只能接受master主机传过来的数据).drbd是工作于内核中的,工作时

corosync+drbd+mysql实现的高可用

要求: 一.能够在同一网段内直接通信 二.节点名称,要和uname的结果一样,并保证可以根据节点名称解析到节点的IP地址,配置本地/etc/hosts 三.SSH互信通信 四.保证时间同步 环境准备配置: test1,192.168.10.55配置 1.配置IP地址 [[email protected] ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0 2.配置主机名 [[email protected] ~]# uname -n [[email

理解 OpenStack 高可用(HA) (6): Pacemaker 和 OpenStack Resource Agent (RA)

本系列会分析OpenStack 的高可用性(HA)概念和解决方案: (1)OpenStack 高可用方案概述 (2)Neutron L3 Agent HA - VRRP (虚拟路由冗余协议) (3)Neutron L3 Agent HA - DVR (分布式虚机路由器) (4)Pacemaker 和 OpenStack Resource Agent (RA) (5)RabbitMQ HA (6)MySQL HA 1. Pacemaker 1.1 概述 Pacemaker 承担集群资源管理者(CR

理解 OpenStack 高可用(HA)(4):RabbitMQ 和 Mysql HA

本系列会分析 OpenStack 的高可用性(HA)解决方案: (1)概述 (写着中...) (2)Neutron L3 Agent HA - VRRP (虚拟路由冗余协议) (3)Neutron L3 Agent HA - DVR (分布式虚机路由器) (4)RabbitMQ 和 Mysql HA 1. 基础知识 1.1 Pacemaker Pacemaker 承担集群资源管理者(CRM - Cluster Resource Manager)的角色,它是一款开源的高可用资源管理软件,适合各种大

NFS存储高可用快速实施方案

Note:以下为NFS+DRBD+HEARTBEAT快速实施文档,若要用于生产环境,请仔细阅读官方文档并结合实际业务调整参数,涉及数据部署请慎重!!! (个人建议:在基于个人熟悉服务的情况下并通过测试环境才可在线上使用.) 存储高可用 NFS+DRBD+HEARTBEAT快速实施方案 环境: nfs-utils-1.2.3-75.el6_9.x86_64 heartbeat-3.0.4-2.el6.x86_64 drbd84-utils-8.9.8-1.el6.elrepo.x86_64 Cen

MySQL数据库高可用快速实施方案

Note:以下为MySQL+DRBD+HEARTBEAT快速实施文档,若要用于生产环境,请仔细阅读官方文档并结合实际业务调整参数,涉及数据部署请慎重!!! (个人建议:在基于个人熟悉服务的情况下并通过测试环境才可在线上使用.) 数据库高可用 MySQL+DRBD+HEARTBEAT实施方案 环境: mysql-5.5.49 heartbeat-3.0.4-2.el6.x86_64 drbd84-utils-8.9.8-1.el6.elrepo.x86_64 CentOS release 6.7