本文最后更新于 2020 年 3 月 9 日,文章已超过 6 个月!内容可能已失效,请自行测试 ~
实验环境
NFS(nhd1) | 192.168.230.101 |
NFS(nhd2) | 192.168.230.102 |
安装drbd及heartbeat
[root@nhd1 ~]# fdisk /dev/sdb
[root@nhd1 ~]# yum -y install perl-TimeDate kernel-devel kernel-headers flex cluster-glue-libs glib2-devel libxml2 libxml2-devel bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel make wget docbook-dtds docbook-style-xsl bzip2-devel libuuid-devel
[root@nhd1 ~]# wget --no-check-certificate http://ym68.cc/download/asciidoc-8.4.5-4.1.el6.noarch.rpm
[root@nhd1 ~]# wget --no-check-certificate http://ym68.cc/download/Heartbeat-3.0.tar.bz2
[root@nhd1 ~]# wget --no-check-certificate http://ym68.cc/download/Cluster_Glue_1.0.12.tar.bz2
[root@nhd1 ~]# wget --no-check-certificate http://ym68.cc/download/resource-agents-3.9.6.tar.gz
[root@nhd1 ~]# wget --no-check-certificate http://ym68.cc/download/drbd-8.4.3.tar.gz
[root@nhd1 ~]# tar xf drbd-8.4.3.tar.gz
[root@nhd1 ~]# tar xf Cluster_Glue_1.0.12.tar.bz2
[root@nhd1 ~]# tar xf Heartbeat-3.0.tar.bz2
[root@nhd1 ~]# tar xf resource-agents-3.9.6.tar.gz
[root@nhd1 ~]# rpm -ivh asciidoc-8.4.5-4.1.el6.noarch.rpm
[root@nhd1 ~]# groupadd haclient
[root@nhd1 ~]# useradd -M -g haclient -s /sbin/nologin hacluster
[root@nhd1 ~]# cd Reusable-Cluster-Components-glue--0a7add1d9996/
[root@nhd1 Reusable-Cluster-Components-glue--0a7add1d9996]# ./autogen.sh
[root@nhd1 Reusable-Cluster-Components-glue--0a7add1d9996]# ./configure --prefix=/usr/local/heartbeat &&make &&make install
[root@nhd1 Reusable-Cluster-Components-glue--0a7add1d9996]# cd ../resource-agents-3.9.6
[root@nhd1 resource-agents-3.9.6]# ./autogen.sh
[root@nhd1 resource-agents-3.9.6]# ./configure --prefix=/usr/local/heartbeat/
[root@nhd1 resource-agents-3.9.6]# ln -s /usr/local/heartbeat/lib/* /lib64/
[root@nhd1 resource-agents-3.9.6]# ln -s /usr/local/heartbeat/lib/* /lib/
[root@nhd1 resource-agents-3.9.6]# make &&make install
[root@nhd1 resource-agents-3.9.6]# cd ../Heartbeat-3-0-958e11be8686
[root@nhd1 Heartbeat-3-0-958e11be8686]# ./bootstrap
[root@nhd1 Heartbeat-3-0-958e11be8686]# export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
[root@nhd1 Heartbeat-3-0-958e11be8686]# ./configure --prefix=/usr/local/heartbeat/
[root@nhd1 Heartbeat-3-0-958e11be8686]# sed -nr 's#\#define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d/"#/* & */#gp' /usr/local/heartbeat/include/heartbeat/glue_config.h
/* #define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d/" */
[root@nhd1 Heartbeat-3-0-958e11be8686]# make &&make install
[root@nhd1 Heartbeat-3-0-958e11be8686]# cd ../drbd-8.4.3
[root@nhd1 drbd-8.4.3]# ./configure --prefix=/usr/local/drbd --with-km --with-heartbeat &&make KDIR=/usr/src/kernels/2.6.32-696.el6.x86_64/
[root@nhd1 drbd-8.4.3]# make &&make install
[root@nhd1 drbd-8.4.3]# mkdir -p /usr/local/drbd/var/run/drbd
[root@nhd1 drbd-8.4.3]# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/init.d/
[root@nhd1 drbd-8.4.3]# chkconfig --add drbd
[root@nhd1 drbd-8.4.3]# cd drbd
[root@nhd1 drbd]# make clean
[root@nhd1 drbd]# make KDIR=/usr/src/kernels/2.6.32-696.el6.x86_64/
[root@nhd1 drbd]# cp drbd.ko /lib/modules/2.6.32-696.el6.x86_64/kernel/lib/
[root@nhd1 drbd]# depmod
[root@nhd1 drbd]# cd /usr/local/drbd/etc/drbd.d/
[root@nhd1 drbd.d]# cp global_common.conf{,-$(date +%s)}
配置文件修改
[root@nhd1 drbd.d]# vim global_common.conf
global {
usage-count yes;
}
common {
handlers {
}
startup {
wfc-timeout 120;
degr-wfc-timeout 120;
}
options {
}
disk {
on-io-error detach;
}
net {
protocol C;
}
}
[root@nhd1 drbd.d]# vim r0.res
resource r0 {
on nhd1 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.230.101:7788;
meta-disk internal;
}
on nhd2 {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.230.102:7788;
meta-disk internal;
}
}
[root@nhd1 drbd.d]# modprobe drbd
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
[root@nhd1 drbd.d]# dd if=/dev/zero bs=1M count=1 of=/dev/sdb1
[root@nhd1 drbd.d]# drbdadm create-md r0
[root@nhd1 drbd.d]# /etc/init.d/drbd start
主执行
[root@nhd1 drbd.d]# drbdadm -- --overwrite-data-of-peer primary r0
[root@nhd1 drbd.d]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@nhd1, 2018-07-07 21:16:39
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n-
ns:125584 nr:0 dw:0 dr:127648 al:0 bm:7 lo:0 pe:1 ua:2 ap:0 ep:1 wo:f oos:20839188
[>....................] sync'ed: 0.7% (20348/20472)M
finish: 0:13:52 speed: 24,984 (24,984) K/sec
[root@nhd1 drbd.d]# mkfs.ext4 /dev/drbd0
[root@nhd1 drbd.d]# mkdir /nfs
[root@nhd1 drbd.d]# mount /dev/drbd0 /nfs/
配置NFS
[root@nhd1 ~]# yum -y install nfs-utils rpcbind
[root@nhd1 ~]# chkconfig nfs on
[root@nhd1 ~]# chkconfig rpcbind on
[root@nhd1 ~]# chkconfig nfs on
[root@nhd1 ~]# chkconfig rpcbind on
[root@nhd1 ~]# vim /etc/exports
/nfs 192.168.230.0/24(rw,sync,no_root_squash)
[root@nhd1 ~]# service rpcbind start
[root@nhd1 ~]# service nfs start
验证
[root@nhd2 ~]# showmount -e 192.168.230.101
Export list for 192.168.230.101:
/nfs 192.168.230.0/24
[root@nhd2 ~]# showmount -e 192.168.230.102
Export list for 192.168.230.102:
/nfs 192.168.230.0/24
[root@nhd2 ~]# mkdir /nfstest
[root@nhd2 ~]# mount -t nfs 192.168.230.101:/nfs /nfstest/
[root@nhd2 ~]# ls /nfstest/
filetest lost+found
该文章采用「CC 协议」,转载必须注明作者和本文链接.