环境
物理机 |
|
|
|
|
|
IBM |
X3650 M4 |
RHEL 6.4 |
itspafcmail01 |
IP:10.183.104.11 |
|
IBM |
X3650 M4 |
RHEL 6.4 |
itspafcmail01 |
IP:10.183.104.12 |
|
DRBD服务
安装drbd
wget http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
red hat 本身的源有问题,更改为清华源后可以解决
1 2
| [root@itspafcmail01 Tools]# yum install drbd kmod-drbd84 -y [root@itspafcmail01 Tools]# modprobe drbd
|
安装完后加载模块不成功,需要重启解决,虚拟机下可不用重启直接加载
配置文件
主节点配置:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| global { usage-count no; } common { syncer { rate 100M; verify-alg crc32c; } } # primary for drbd1 resource data { protocol C; disk { on-io-error detach; } on itspafcmail01 { device /dev/drbd0; disk /dev/mapper/vg_0-lv_maildata; address 192.168.1.1:7788; meta-disk internal; } on itspafcmail02 { device /dev/drbd0; disk /dev/mapper/vg_0-1v_maildata; address 192.168.1.2:7788; meta-disk internal; } }
|
备节点配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| global { usage-count no; } common { syncer { rate 100M; verify-alg crc32c; } } # primary for drbd1 resource data { protocol C; disk { on-io-error detach; } on itspafcmail01 { device /dev/drbd0; disk /dev/mapper/vg_0-lv_maildata; address 192.168.1.1:7788; meta-disk internal; } on itspafcmail02 { device /dev/drbd0; disk /dev/mapper/vg_0-1v_maildata; address 192.168.1.2:7788; meta-disk internal; } }
|
主节点操作
1 2 3 4 5 6 7 8 9 10 11 12 13
| [root@itspafcmail01 ~]# drbdadm create-md data md_offset 420814516224al_offset 420814483456bm_offset 420801638400 Found some data ==> This might destroy existing data! <== Do you want to proceed? [need to type 'yes' to confirm] yes initializing activity log NOT initializing bitmap Writing meta data...New drbd meta data block successfully created.
|
启动并查看
1 2 3 4 5
| [root@itspafcmail01 ~]# drbdadm up all [root@itspafcmail01 ~]# cat /proc/drbd version: 8.4.9-1 (api:1/proto:86-101)`GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15 0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----s ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:410939100`
|
备点操作
1 2 3 4 5 6 7 8 9 10 11 12 13
| [root@itspafcmail02 ~]# drbdadm create-md data md_offset 420814516224al_offset 420814483456bm_offset 420801638400 Found some data ==> This might destroy existing data! <== Do you want to proceed? [need to type 'yes' to confirm] yes initializing activity log NOT initializing bitmap Writing meta data...New drbd meta data block successfully created.
|
启动并查看
1 2 3 4 5
| [root@itspafcmail02 ~]# cat /proc/drbd version: 8.4.9-1 (api:1/proto:86-101) GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15 0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----s ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:410939100
|
目前主备都为Unknow状态,有可能是网络不通导致的
已关闭iptables和setlinux后解决
同步数据
只需要在一端操作,此处在主节点操作
1 2
| [root@data-1-1 ~]# drbdadm primary data#如果出现“drbdsetup-84 primary 0”错误可用下面方式执行 [root@data-1-1 ~]# drbdadm -- --overwrite-data-of-peer primary data#上面这步操作会非常旧,需要确定彻底执行完毕才可进行接下来的操作
|
同步完后的结果,在从节点看到的内容
1 2 3 4
| [root@itspafcmail02 ~]# cat /proc/drbdversion: 8.4.9-1 (api:1/proto:86-101) GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r----- ns:0 nr:410939100 dw:410939100 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
|
格式化并挂载
1 2 3
| [root@itspafcmail01 ~]# mkfs.ext4 /dev/drbd0 [root@itspafcmail01 ~]# mkdir /maildata/ [root@itspafcmail01 ~]# mount /dev/drbd0 /maildata#并在maildata下创建一个测试用的文件,确保同步完毕之后进行故障模拟操作
|
再次查看状态:
1 2 3 4
| [root@itspafcmail01 ~]# cat /proc/drbdversion: 8.4.9-1 (api:1/proto:86-101) GIT-hash: 9976da086367a2476503ef7f6b13d4567327a280 build by mockbuild@Build64R6, 2016-12-13 18:38:15 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:417499764 nr:0 dw:6560664 dr:410940969 al:1696 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
|
状态说明
- ro是角色信息
- Primary/Secondary(代表这个是主节点)
- Secondary/Primary(代表这个是副节点)
- ds是磁盘状态
- UpToDate/Inconsistent(正在同步,数据还没有一致)
- UpToDate/UpToDate (同步完成,数据一致)
- ns是网络传输的数据包
- dw 是磁盘写操作
- dr 是磁盘读操作
- of 运行中(过时的)模块号码
- pe 待解决的 模块号码
- ua 未答复的 模块号码(最好为0)
DRDB模拟测试
将主节点设置为备节点
1 2
| [root@itspafcmail01 ~]# umount /maildata/ [root@itspafcmail01 ~]# drbdadm secondary data
|
将备用节点设置为主节点
1 2
| [root@itspafcmail02 ~]# drbdadm primary data [root@itspafcmail02 ~]# mount /dev/drbd0 /maildata/
|
测试完毕后,恢复原来的主备关系
禁止DRBD开机启动两端都需要禁用,由HA控制
1 2 3 4
| [root@itspafcmail01 ~]# chkconfig --list drbd drbd 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@itspafcmail02 ~]# chkconfig --list drbd drbd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
|
drbd常见问题
问题1 DRBD依赖于基于其内核模块,需手工加载
问题2 命令drbdadm up all 相当于如下命令的组合:
1 2 3
| drbdadm attach all //Attach to backing device. drbdadm syncer all //Set synchronization parameters. drbdadm connect all //drbdadm connect resource
|
问题3 处理drbd裂脑问题(ro:Secondary/Unknown)
1 2 3 4 5 6 7 8 9 10 11 12 13
| 裂脑的状态为:ro:Secondary/Unknown 可选择一个节点作为secondary,在该机器上执行 drbdadm secondrat all #<==备节点设置为被 drbdadm dis`connect all drbdadm -- --discard-my-data connect all #<==本端放弃数据连接 有时也需要在另一个节点上执行 drbdadm connect all
|
HeartBeat服务
安装heartbeat
1 2 3 4 5 6 7
| [root@itspafcmail01 ~]# mkdir /opt/Tools/ [root@itspafcmail01 ~]# cd /opt/Tools/ [root@itspafcmail01 Tools]# wget http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@itspafcmail01 Tools]# rpm -ivh epel-release-6-8.noarch.rpm [root@itspafcmail01 Tools]# rpm -qa|grep epel [root@itspafcmail01 Tools]# yum install heartbeat* -y
|
_#在red-hat下直接安装会报错
#修改下面两个文件将https变为http即可解决_
1 2
| [root@itspafcmail01 yum.repos.d]# ls epel* epel.repo epel-testing.repo
|
由于客户方的操作系统不是我们安装的,存在很多的依赖关系,我这里选择在本地yum安装的时候保留一份,然后直接放到生产的机器上
配置文件说明
配置文件:
启动脚本:
资源控制目录:
1
| /etc/ha.d/resource.d <==脚本,控制资源的脚本,被HA调用。也可以放/etc/init.d/下
|
拷贝配置文件
1 2
| [root@itspafcmail01 ha.d]# cd /usr/share/doc/heartbeat-3.0.4/ [root@itspafcmail01 heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/
|
配置ha.cf文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #日志配置 debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility local0 #基础参数 keepalive 2 deadtime 30 warntime 10 initdead 120#串口#serial /dev/ttys0 #选择多播的方式,需要改动的仅有eth2这块网卡,端口694上 mcast eth4 225.0.0.7 694 1 0 auto_failback on #两台服务器主机名node itspafcmail01node itspafcmail02 crm no
|
配置authkey文件
生成sha1值
1
| [root@itspafcmail01 ha.d]# echo turbo423|sha1sum7d44656e1b9fac646608cfa1452453eb7c0710d0 -
|
写入配置文件
1 2
| [root@itspafcmail01 ha.d]# cat authkeys auth 11 sha1 7d44656e1b9fac646608cfa1452453eb7c0710d0
|
配置权限600
1
| [root@itspafcmail01 ha.d]# chmod 600 authkeys
|
配置haresource文件
#/etc/ha.d/resource.d/IPaddr 实际就是一个脚本,用于服务启动后优先绑定在哪个IP上 itspafcmail01 IPaddr::192.168.2.10/24/eth4 itspafcmail02
IPaddr::192.168.2.11/24/eth4 配置说明:
#itspafcmail01 为主机名,表示初始状态会在itspafcmail01 绑定IP 10.0.0.17
#IPaddr为heartbeat配置IP的默认脚本,其后的IP等都是脚本的参数
#192.168.2.1/24/eth4为集群对外服务的VIP,初始启动在data-1-1上,24为子网掩码,eth0为ip绑定的实际物理网卡,为heartbeat提供对外服务的通信接口。
启动测试
1 2 3 4 5 6 7 8 9
| [root@itspafcmail01 ha.d]# /etc/init.d/heartbeat start Starting High-Availability services: INFO: Resource is stopped INFO: Resource is stopped Done. [root@itspafcmail01 ha.d]# ps auxw|grep heart root 13193 0.0 0.0 50124 7168 ? SLs 16:13 0:00 heartbeat: master control process root 13197 0.0 0.0 49944 6988 ? SL 16:13 0:00 heartbeat: FIFO reader root 13198 0.0 0.0 49940 6984 ? SL 16:13 0:00 heartbeat: write: mcast eth4 root 13199 0.0 0.0 49940 6984 ? SL 16:13 0:00 heartbeat: read: mcast eth4
|
检查IP初始启动情况
1 2
| [root@itspafcmail01 ha.d]# ip a|grep -E "192.168.2.10|192.168.2.11" inet 192.168.2.10/24 brd 192.168.2.255 scope global secondary eth4
|
接管的过程:
模拟主机down机,看看VIP是否会被备机接管
成功则表示heartbeat部署正常
Heartbeat 控制drbd高可用的实现
Ha本生有一个脚本用于控制drbd的即drbddisk启动drbd也可以用:
1
| /etc/ha.d/resource.d/drbddisk data start #这样执行之后就直接选主了
|
haresoures写法如下
1 2
| itspafcmail01 drbddisk::data IPaddr::192.168.2.10/24/eth4 itspafcmail02 IPaddr::192.168.2.11/24/eth4
|
关于drbd选主的问题,在drbd都是secondary的情况下ha可以根据haresoures的内容进行选主,确保先把两边的drbd都启动好,再启动ha
通过脚本挂载和卸载drbd
手动挂载的形式
1
| /etc./ha.d/resource.d/Filesystem /dev/drbd0 /maildata ext4 start
|
手动卸载的形式
1
| /etc./ha.d/resource.d/Filesystem /dev/drbd0 /maildata ext4 start
|
haresoures写法如下
1 2 3
| itspafcmail01 drbddisk::data Filesystem::/dev/drbd0::/maildata::ext4 IPaddr::192.168.2.10/24/eth4 itspafcmail02 IPaddr::192.168.2.11/24/eth4 itspafcmail01 drbddisk::data Filesystem::/dev/drbd0::/maildata::ext4 IPaddr::192.168.2.10/24/eth4
|
上述命令等同于:
1 2 3
| /etc./ha.d/resource.d/drbddisk data start /etc./ha.d/resource.d/Filesystem /dev/drbd0 /maildata ext4 start /etc./ha.d/resource.d/IPaddr 192.168.2.10/24/eth4 start
|
关于停止的顺序
先停VIP 再停挂载 最后改角色为secondary
killall -9 heartbeat的情况需要清理释放IP地址
ip addr del 192.168.2.11/24 dev eth4
关于Primary/Unknow状态的修复
手工处理裂脑问题,主机宕机后的修复
自动接管参数开启
1,itspafcmail01 主不能自动开启heartbeat,drbd(#auto_failback on)。
2,itspafcmail01 主故障备接管后,备对外提供服务,写数据(实现模拟100个文件)。
itspafcmail02 备节点提升为主节点后的状态(Primary/Unknow )
3,itspafcmail01 主修复了,不要开启heartbeat及drbd
手工处理:
- 确保心跳线通信正常
- drbdadm up data #此时itspafcmail01状态(Secondary /Primary )
- 同步完成启动heartbeat(/etc/init.d/heatbeat start
- itspafcmail01 (Primary/Secondary )
- itspafcmail02 (Secondary /Primary )
建议操作:自动接管参数关闭
1,itspafcmail01 主不能自动开启heartbeat,drbd(auto_failback off)。
2,itspafcmail01 主故障备接管后,备对外提供服务,写数据(实现模拟100个文件)。
itspafcmail02 备节点提升为主节点后的状态(Primary/Unknow )
3,itspafcmail01 主修复了,不要开启heartbeat及drbd
手工处理:
- 确保心跳线通信正常
- drbdadm up data #此时itspafcmail01状态(Secondary /Primary )
- 此时数据流从itspafcmail02 流向itspafcmail01
- itspafcmail01启动heartbeat itspafcmail01(Secondary /Primary )
- itspafcmail02 /usr/share/heartbeat/hb_standby (服务器回切)
- itspafcmail01 (Primary /Secondary )
DRBD主从自动切换测试
首先启动node1的heartbeat,接着再启动node2的heartbeat。
然后启动node1上的drbd,接着启动node2上的drbd
Heartbeat控制turbomail
编写资源脚本
主从两台机都要有
在资源目录下创建turbomail脚本
/etc/ha.d/resource.d/turbomail
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #!/bin/bash #Author :Adair #Filename :turbomail #chkconfig :2345 54 65 SUCC="\033[32m" END="\033[0m" turbomail="/turbomail"cd $turbomailif [ $# -ne 1 ] thenecho "USAGE:$0 {start|stop|restart}"exit 1 fi if [ "$1" = "start" ] then nohup ./startall.sh >nohup.txt 2>&1 echo -e "Start turbomail... ${SUCC} [OK] ${END}" elif [ "$1" = "stop" ] then nohup ./shutdownall.sh >nohup.txt 2>&1 echo -e "Stop turbomail... ${SUCC} [OK] ${END}" elif [ "$1" = "restart" ] then nohup ./shutdownall.sh >nohup.txt 2>&1 echo -e "Stop turbomail... ${SUCC} [OK] ${END}" nohup ./startall.sh >nohup.txt 2>&1 echo -e "Start turbomail... ${SUCC} [OK] ${END}" fi
|
主的haresource文件变为:
1
| itspafcmail01 IPaddr::10.0.0.12/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/maildata::ext4 turbomail
|
备的haresource文件变为:
1
| itspafcmail02 IPaddr::10.0.0.12/24/eth0 drbddisk::data Filesystem::/dev/drbd0::/maildata::ext4 turbomail
|
测试模拟和drbd的类似