frcd 发表于 2015-9-5 12:49:36

HA-drbd+heartbeat+nfs搭建

公司最近NFS有问题,决定要把NFS做成(HA)heartbeat+drbd+NFS,保证服务不间断
Distributed Replicated Block Device(DRBD)是一个用软件实现的、无共享的、服务器之间镜像块设备内容的存储复制解决方案
系统:Centos6.3
masterdr 192.168.56.136
slavedr 192.168.56.137
vip   192.168.56.140

首先安装drbd 决定用yum安装,修改yum源
# wget http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm

# rpm -iUvh elrepo-release-6-6.el6.elrepo.noarch.rpm
# yum --enablerepo=elrepo install drbd83-utils kmod-drbd83
# modprobe drbd
# lsmod |grep drbd
drbd 351464 0
# drbdadm adjust drbddata
0: Failure: (119) No valid meta-data signature found.
==> Use 'drbdadm create-md res' to initialize meta-data area. <==
Command 'drbdsetup 0 disk /dev/sda1 /dev/sda1 internal --set-defaults --create-device --on-io-error=detach' terminated with exit code 10
# drbdadm create-md drbddata
md_offset 2097147904
al_offset 2097115136
bm_offset 2097049600
Found ext3 filesystem
2048000 kB data area apparently used
2047900 kB left usable by current configuration
Device size would be truncated, which
would corrupt data and result in
'access beyond end of device' errors.
You need to either
* use external meta data (recommended)
* shrink that filesystem first
* zero out the device (destroy the filesystem)
Operation refused.
Command 'drbdmeta 0 v08 /dev/sda1 internal create-md' terminated with exit code 40
drbdadm create-md drbddata: exited with code 40
# dd if=/dev/zero of=/dev/sda1 bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.417199 秒,251 MB/秒
# drbdadm create-md drbddata
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
# service drbd start
Starting DRBD resources: [ d(drbddata) s(drbddata) n(drbddata) ]..........
***************************************************************
DRBD's startup script waits for the peer node(s) to appear.
- In case this node was already a degraded cluster before the
reboot the timeout is 30 seconds.
- If the peer was available before the reboot the timeout will
expire after 30 seconds.
(These values are for resource 'drbddata'; 0 sec -> wait forever)
To abort waiting enter 'yes' [ -- ]:[ 10]:[ 11]:[ 12]:[ 13]:[ 14]:[ 15]:[ 16]:[ 17]:[ 18]:[ 19]:[ 20]:[ 21]:[ 22]:[ 23]:[ 24]:[ 25]:[ 26]:[ 27]:[
28]:[ 29]:
.
# drbd-overview
0:drbddata Connected Secondary/Secondary Inconsistent/Inconsistent C r-----
# cat /proc/
Display all 151 possibilities? (y or n)
# cat /proc/d
devices diskstats dma drbd driver/
# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: 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:2047900
# drbd-overview
0:drbddata Connected Secondary/Secondary Inconsistent/Inconsistent C r-----
# cat /proc/dr
drbd driver/
# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: 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:2047900
# drbdadm -- --overwrite-data-of-peer primary drbddata
# drbd-overview
0:drbddata SyncSource Primary/Secondary UpToDate/Inconsistent C r-----
[>....................] sync'ed: 4.8% (1951772/2047900)K

# mkfs -t ext3 -L drbddata /dev/drbd0
mke2fs 1.41.12 (17-May-2010)
文件系统标签=drbddata
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
128000 inodes, 511975 blocks
25598 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=524288000
16 block groups
32768 blocks per group, 32768 fragments per group
8000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
# mount /dev/drbd0 /mnt/
# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda3 16G 2.3G 13G 16% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/drbd0 2.0G 35M 1.8G 2% /mnt
# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
m:res cs ro ds p mounted fstype
0:drbddata Connected Primary/Secondary UpToDate/UpToDate C /mnt ext3
# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
m:res cs ro ds p mounted fstype
0:drbddata Connected Secondary/Primary UpToDate/UpToDate C
# tar xvf libnet-1.1.2.1.tar.gz
# cd libnet
# ./configure && make && make install
# rpm -ivh perl-TimeDate-1.16-11.1.el6.noarch.rpm
Preparing... ###########################################
1:perl-TimeDate ###########################################
# rpm -ivh PyXML-0.8.4-19.el6.x86_64.rpm
Preparing... ###########################################
1:PyXML ###########################################
# rpm -ivh heartbeat-*
warning: heartbeat-3.0.4-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
error: Failed dependencies:
cluster-glue is needed by heartbeat-3.0.4-1.el6.x86_64
cluster-glue-libs is needed by heartbeat-3.0.4-1.el6.x86_64
libplumb.so.2()(64bit) is needed by heartbeat-3.0.4-1.el6.x86_64
resource-agents is needed by heartbeat-3.0.4-1.el6.x86_64
libpils.so.2()(64bit) is needed by heartbeat-libs-3.0.4-1.el6.x86_64
libplumb.so.2()(64bit) is needed by heartbeat-libs-3.0.4-1.el6.x86_64
libplumbgpl.so.2()(64bit) is needed by heartbeat-libs-3.0.4-1.el6.x86_64
libstonith.so.1()(64bit) is needed by heartbeat-libs-3.0.4-1.el6.x86_64
# rpm -ivh cluster-glue-1.0.5-6.el6.x86_64.rpm
error: Failed dependencies:
cluster-glue-libs = 1.0.5-6.el6 is needed by cluster-glue-1.0.5-6.el6.x86_64
liblrm.so.2()(64bit) is needed by cluster-glue-1.0.5-6.el6.x86_64
libpils.so.2()(64bit) is needed by cluster-glue-1.0.5-6.el6.x86_64
libplumb.so.2()(64bit) is needed by cluster-glue-1.0.5-6.el6.x86_64
# rpm -ivh cluster-glue-libs-1.0.5-6.el6.x86_64.rpm
Preparing... ###########################################
1:cluster-glue-libs ###########################################
# rpm -ivh cluster-glue-1.0.5-6.el6.x86_64.rpm
Preparing... ###########################################
1:cluster-glue ###########################################
# rpm -ivh heartbeat-libs-3.0.4-1.el6.x86_64.rpm
warning: heartbeat-libs-3.0.4-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
error: Failed dependencies:
heartbeat = 3.0.4-1.el6 is needed by heartbeat-libs-3.0.4-1.el6.x86_64
# rpm -ivh heartbeat-3.0.4-1.el6.x86_64.rpm
warning: heartbeat-3.0.4-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
error: Failed dependencies:
libapphb.so.2()(64bit) is needed by heartbeat-3.0.4-1.el6.x86_64
libhbclient.so.1()(64bit) is needed by heartbeat-3.0.4-1.el6.x86_64
resource-agents is needed by heartbeat-3.0.4-1.el6.x86_64
# rpm -ivh resource-agents-3.9.2-12.el6_3.1.x86_64.rpm
Preparing... ###########################################
1:resource-agents ###########################################
# rpm -ivh heartbeat-3.0.4-1.el6.x86_64.rpm heartbeat-libs-3.0.4-1.el6.x86_64.rpm
warning: heartbeat-3.0.4-1.el6.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ###########################################
1:heartbeat-libs ########################################### [ 50%]
2:heartbeat ###########################################
# cd /etc/ha.d/
# cp /usr/share/doc/heartbeat-3.0.4/ha.cf .
# cp /usr/share/doc/heartbeat-3.0.4/haresources .
# cp /usr/share/doc/heartbeat-3.0.4/authkeys .
# grep -Ev '^$^|#' /etc/ha.d/ha.cf
logfacility local0
auto_failback on
logfacility local0
auto_failback on
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 20
warntime 10
initdead 60
udpport 694
ucast eth0 192.168.56.137
auto_failback on
node masterdr
node slavedr
# grep -Ev '^$^|#' /etc/ha.d/authkeys
auth 3
3 md5 Hello1!
# grep -Ev '^$^|#' /etc/ha.d/resource.d/killnfs
killall -9 nfsd;/etc/init.d/nfs restart;exit 0
# grep -Ev '^$^|#' /etc/ha.d/haresources
masterdr IPaddr::192.168.56.140/24/eth0 drbddisk::drbddata Filesystem::/dev/drbd0::/data::ext4 nfs
# /etc/init.d/heartbeat start
# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda3 16G 2.4G 13G 16% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/drbd0 2.0G 35M 1.8G 2% /data
# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:8f:9b:cf brd ff:ff:ff:ff:ff:ff
inet 192.168.56.136/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.140/24 brd 192.168.56.255 scope global secondary eth0:0
inet6 fe80::20c:29ff:fe8f:9bcf/64 scope link
valid_lft forever preferred_lft forever
# /etc/init.d/heartbeat stop
Stopping High-Availability services: Done.
# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda3 16G 2.4G 13G 16% /
tmpfs 495M 0 495M 0% /dev/shm
/dev/drbd0 2.0G 35M 1.8G 2% /data
# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:67:53:26 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.137/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.140/24 brd 192.168.56.255 scope global secondary eth0:0
inet6 fe80::20c:29ff:fe67:5326/64 scope link
valid_lft forever preferred_lft forever
drbdadm primary drbddata
# drbdadm secondary drbddata
  
页: [1]
查看完整版本: HA-drbd+heartbeat+nfs搭建