`
brucectl
  • 浏览: 173402 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

heartbeat+drbd

阅读更多
所使用到的软件:
libnet.tar.gz
Heartbeat-STABLE-2-1-STABLE-2.1.4.tar.bz2
drbd-8.3.1.tar.gz

情景描述:
ivrdrbd01: bond0:192.168.20.191 
ivrdrbd02: bond0:192.168.20.192
VIP: 192.168.20.85


1:编译安装Libnet 。
./configure && make && make install

2.1 添加haclient组 和 heartbeat 用户 :
groupadd haclient
useradd -u 694 -g haclient hacluster

2.2 编译安装 heatbeat。注意 heartbeat编译安装有些不一样,用里面的Configureme 配上 configure ,然后再 make ,make install。
./Configureme configure && make && make install

3:修改系统主机名等相关信息,主机名修改在/etc/sysconfig/network文件中修改。
3.1 修改主机名解析文件 ,/etc/hosts。内容如下:

127.0.0.1 localhost.localdomain localhost
192.168.20.191 ivrdrbd01
192.168.20.192 ivrdrbd02

其中本机业务ip为 192.168.20.191 ,主机名为ivrdrbd01。可以将此文件拷贝至备机。目的就是要保证2台机器可以通过主机名通信。

4:配置 heartbeat
4.1 从heart编译目录/doc 中拷贝文件ha.cf , haresources, authkeys 到 heartbeat的默认配置目录 /etc/ha.d/中。

cp doc/{ha.cf,haresources,authkeys} /etc/ha.d/
4.2 编辑 authkeys ,内容如下:

#auth 1
#1 crc
#2 sha1 HI!
#3 md5 Hello!
auth 1
1 crc

注意文件第1行的提示,要把文件属性改为 600 ,

chmod 600 /etc/ha.d/authkeys



4.3 编辑 ha.cf ,内容如下:

debugfile /var/log/ha-debug #debug日志
logfile /var/log/ha-log # Log file 日志文件位置
keepalive 2 # Heartbeat interval 心跳包间隔
deadtime 10 # How long to say the server's death 宣告服务器死亡时间间隔>=10
warntime 5 # 告警时间间隔
initdead 50 # 在某些系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,该选项用于解决这种情况产生的时间间隔。取值至少为deadtime的两倍。>=10

udpport 694 # Heartbeat port 端口
bcast eth1 # Linux Heartbeat interface 心跳网卡

auto_failback off # How to do when the failure server comes back 服务停止后是否恢复
node node1 # How many servers in the HA system 系统中的节点名称,依次排列
node node2
ping 192.168.20.192 #ping a robust server to ensure the server's health; ping目的地址,由于此次使用的是双机,所以此部分的配置2台服务器互相设为对方ip ,有的建议配置为网关Ip,但如果网关 down了呢??
respawn hacluster /usr/lib64/heartbeat/ipfail #32位系统的将lib64改成lib

#bcast eth0
#说明:采用eth0的udp广播用来发送心跳信息,建议在副节点不只一台时使用
ucast eth0 192.168.20.192
#说明:采用网卡eth0的udp单播来通知心跳,ip应为对方IP(未验证)
#mcast eth0 225.0.0.1 694 1 0
#说明:采用udp多播播来通知心跳,建议在副节点不只一台时使用
#注:广播,单播,多播,以上三种任选其一即可




4.3 编辑 haresources ,内容如下:
这个配置比较重要,直接关系到drbd切换的成功与否
主机名       drbd资源      挂载的文件系统

ivrdrbd01 drbddisk::r0 Filesystem::/dev/drbd0::/opt::ext3
ivrdrbd01 \
  IPaddr2::192.168.20.85/32/bond0/192.168.20.255


5.编译安装drbd
make && make install
modprobe drbd
lsmod | grep drbd
[root@ivrdrbd02 ~]# lsmod |grep drbd
drbd 271560 3

6:配置 drbd
[root@ivrdrbd02 ~]# vi /etc/drbd.conf

global { usage-count no; } #是否参加使用者统计,no为不参与
common { syncer { rate 10M; } } #同步速度为10M
resource r0 { #r0资源
  protocol C; #数据同步协议,C为收到数据并写入后返回,确认成功
  net {
  cram-hmac-alg sha1;
  shared-secret "FooFunFactory";
}
  on ivrdrbd01 {                                                 #主机名
  device /dev/drbd0;                                           #meta块设备,以此挂载到目录
  disk /dev/sda2;                                               #底层真实物理分区
  address 192.168.20.191:7789;                        #IPaddr:Port
  meta-disk internal;
  }
  on ivrdrbd02 {
  device /dev/drbd0;
  disk /dev/sda2;
  address 192.168.20.192:7789;
  meta-disk internal;
  }
}

将两台机子配置写成一样,scp到另一台。

6.2在启动DRBD之前,需要创建供DRBD记录信息的数据块.分别在两台主机上执行:
drbdadm create-md r0

Tip:如果出现code 50错误,使用dd命令将硬盘破坏
dd if=/dev/zero of=/dev/sda2 bs=1M count=1

6.3 Attach to backing device. This step associates the DRBD resource with its backing device:
drbdadm attach resource

Set synchronization parameters. This step sets synchronization parameters for the DRBD resource:
drbdadm syncer resource

Connect to peer. This step connects the DRBD resource with its counterpart on the peer node:
drbdadm connect resource

Tip
You may collapse the steps drbdadm attach, drbdadm syncer, and drbdadm connect into one, by using the shorthand command drbdadm up.

[root@ivrdrbd01 ~]# cat /proc/drbd
version: 8.3.1 (api:88/proto:86-89)
GIT-hash: fd40f4a8f9104941537d1afc8521e584a6d3003c build by root@ivrdrbd01.99bill.com, 2009-05-03 12:22:07
0: cs:Connected ro:Secondary/Secondary ds: Inconsistent/Inconsistent C r----
ns:52 nr:48 dw:100 dr:42 al:2 bm:3 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0


*** Start the initial full synchronization. This step must be performed on only one node, only on initial resource configuration, and only on the node you selected as the synchronization source. To perform this step, issue this command:

drbdadm -- --overwrite-data-of-peer primary resource

service drbd start

mkfs.ext3 /dev/drbd0
mount /dev/drbd0 /opt
只有主drbd上才可以挂载/dev/drbd0和格式化,如需备drbd上做,需提升为主
drbdadm primary r0
原drbd需降成备drbd
drbdadm secondary r0

这时候查看/dev可能没有drbd0这个块设备,但是在/sys/block/下有,说明块备是已经建立成功了,我们需要手动在/dev下面建立

mknod /dev/drbd0 b 147 0

DRBD device. This is the virtual block device managed by DRBD. It has a device major number of 147, and its minor numbers are numbered from 0 onwards, as is customary. The associated block device is always named /dev/drbdm, where m is the device minor number.


可能重启系统后/dev/drbd0设备会丢失,可能将它写入到initrd文件中

cp /boot/initrd-2.6.9-67.ELsmp.img /root

解压initrd文件
$ mkdir initrd
$ cd initrd
$ gzip -dc ../initrd-2.6.9-67.ELsmp.img | cpio –id

vi init在init文件中添加以下命令
mknod /dev/drbd0 b 147 0

压缩init文件

$ find ./ | cpio -H newc -o > ../initrd-2.6.9-67.ELsmp.img
1354 blocks
$ cd ..
$ gzip -9 initrd-2.6.9-67.ELsmp.img
$ mv initrd-2.6.9-67.ELsmp.img.gz /boot/ initrd-2.6.9-67.ELsmp.img

==================================================
Reconnecting primary/unknown and secondary/unknown

On primary node
drbdadm connect all
On secondary node
drbdadm -- --discard-my-data connect all

分享到:
评论
1 楼 sunnylocus 2010-01-07  
老兄,你是快钱公司的?

相关推荐

Global site tag (gtag.js) - Google Analytics