DRBD9配置手册

snow chuai汇总、整理、撰写---2020/2/22


1. 拓扑
+----------------------+ +----------------------+ | [ DRBD Node 1 ] | | [ DRBD Node 2 ] | | srv1.1000cc.net +----------+----------+ srv2.1000cc.net | | 192.168.10.1 1 | | 192.168.10.12 | | 增加vdb磁盘一块 | | 增加vdb磁盘一块 | +----------------------+ +----------------------+
2. 配置及启动DRBP
1) 在所有节点上安装drbd工具
[root@srv1 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org && \
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm && \
yum install -y drbd90-utils kmod-drbd90
[root@srv2 ~]# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org && \ rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm && \ yum install -y drbd90-utils kmod-drbd90
2) 在所有节点上加载drbd内核模块 [root@srv1 ~]# modprobe drbd [root@srv1 ~]# echo drbd > /etc/modules-load.d/drbd.conf
[root@srv2 ~]# modprobe drbd [root@srv2 ~]# echo drbd > /etc/modules-load.d/drbd.conf
3) 做好FQDN解析
4) 创建全局配置文件 [root@srv1 ~]# mv /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.bak
[root@srv1 ~]# vim /etc/drbd.d/global_common.conf global { usage-count no; } common { net { protocol C; } }
[root@srv2 ~]# mv /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.bak
[root@srv2 ~]# vim /etc/drbd.d/global_common.conf global { usage-count no; } common { net { protocol C; } }
5) 在所有节点上创建资源配置文件 [root@srv1 ~]# vim /etc/drbd.d/drbd0.res resource drbd0 { disk /dev/vdb; device /dev/drbd0; meta-disk internal; on srv1.1000cc.net { address 192.168.10.11:7789; } on srv2.1000cc.net { address 192.168.10.12:7789; } }
[root@srv2 ~]# vim /etc/drbd.d/drbd0.res resource drbd0 { disk /dev/vdb; device /dev/drbd0; meta-disk internal; on srv1.1000cc.net { address 192.168.10.11:7789; } on srv2.1000cc.net { address 192.168.10.12:7789; } }
6) 在所有节点上初始化设备 [root@srv1 ~]# drbdadm create-md drbd0 initializing activity log initializing bitmap (640 KB) to all zero Writing meta data... New drbd meta data block successfully created.
[root@srv2 ~]# drbdadm create-md drbd0 initializing activity log initializing bitmap (640 KB) to all zero Writing meta data... New drbd meta data block successfully created.
7) 启动服务 [root@srv1 ~]# systemctl enable --now drbd [root@srv2 ~]# systemctl enable --now drbd
8) 将srv1.1000cc.net节点设置为主节点(如果设备已经启用不用执行drbdadm up drbd0) [root@srv1 ~]# drbdadm up drbd0 [root@srv1 ~]# drbdadm primary drbd0 --force
9) 将srv2.1000cc.net节点启用(如果设备已经启用不用执行drbdadm up drbd0) [root@srv2 ~]# drbdadm up drbd0
10) 查看同步进程 [root@srv1 ~]# cat /proc/drbd version: 9.0.20-1 (api:2/proto:86-115) GIT-hash: 7dce3c8be99f4912f1490f9bb37f5aff6c873335 build by mockbuild@, 2019-10-17 20:27:56 Transports (api:16): tcp (9.0.20-1)
[root@srv2 ~]# cat /proc/drbd version: 9.0.20-1 (api:2/proto:86-115) GIT-hash: 7dce3c8be99f4912f1490f9bb37f5aff6c873335 build by mockbuild@, 2019-10-17 20:27:56 Transports (api:16): tcp (9.0.20-1)
3. 测试
1) 在主节点srv1.1000cc.net上执行一下测试操作
[root@srv1 ~]# mkfs.ext4 /dev/drbd0
[root@srv1 ~]# mkdir /mnt/drbd/ [root@srv1 ~]# mount /dev/drbd0 /mnt/drbd [root@srv1 ~]# df -Th | grep /mnt/drbd /dev/drbd0 ext4 20G 45M 19G 1% /mnt/drbd
[root@srv1 ~]# touch /mnt/drbd/test{1..3}.txt [root@srv1 ~]# ls -l /mnt/drbd/ total 16 drwx------ 2 root root 16384 Feb 22 21:28 lost+found -rw-r--r-- 1 root root 0 Feb 22 21:29 test1.txt -rw-r--r-- 1 root root 0 Feb 22 21:29 test2.txt -rw-r--r-- 1 root root 0 Feb 22 21:29 test3.txt
2) 切换至备节点 [root@srv1 ~]# umount /mnt/drbd/ [root@srv1 ~]# drbdadm secondary drbd0
3) 在备节点上确认文件同步 [root@srv2 ~]# mkdir /mnt/drbd [root@srv2 ~]# mount /dev/drbd0 /mnt/drbd [root@srv2 ~]# ls -l /mnt/drbd total 16 drwx------ 2 root root 16384 Feb 22 21:28 lost+found -rw-r--r-- 1 root root 0 Feb 22 21:29 test1.txt -rw-r--r-- 1 root root 0 Feb 22 21:29 test2.txt -rw-r--r-- 1 root root 0 Feb 22 21:29 test3.txt

 

如对您有帮助,请随缘打个赏。^-^

gold