In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Drbd+keepalived nfs High availability solution practice https://docs.linbit.com/ drbd official website environment centos7 Master: 192.168.212.10 (chy) (nfs+keepalived+drdb are all on one machine) backup: 192.168.212.11 (chy01) client: 192.168.212.12 (chy02) architecture figure is as follows:
Basic preparatory work
Ensure that all server times are synchronized. Yum-y install ntp ntpdate-u time.nist.gov (clock synchronization command)
two。 Make sure that all server firewalls are turned off and Selinux is off.
And the host name is configured in place, and the server role can be known according to the host name. Make sure that the hostname of any server can be parsed in all server hosts.
Description: as the simple command above, this does not introduce the principle of building DRDBdrbd. Here we use C protocol (after the backup network receives it, it is written to the disk and then returns the OK status to Master). Start installing DRDB (the following operations are required for both master and slave, and I am using yum installation instead of source code) [root@chy ~] # yum-y update kernel kernel-devel [root@chy ~] # rpm-Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm[root@chy ~] # yum-y install drbd84-utils kmod-drbd84
Create a disk partition (master and standby operate at the same time) after both the master and standby install drbd, we begin to format the disk. Here I directly divide / dev/sdb into primary partitions with a size of 20g. On this basis, I do LVM volumes and divide them into 10G.
[root@chy ~] # lsblk / / list all block devices NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 20G 0 disk sda1 8:1 0200M 0 part / boot └─ sda2 8:2 0 18.9G 0 part ├─ cl-root 253 cl-root 0 09G 0 lvm / ├─ cl-swap 253 ├─ 1 0800M 0 lvm [SWAP] ├─ cl-home 253v 2 0500M 0 Lvm / home └─ cl-var 253 lvm / varsdb 8:16 020G 0 disk sr0 11:0 14.1G 0 rom [root@chy] # fdisk / dev/sdb [root@chy] # pvcreate / dev/sdb1Physical volume "/ dev/sdb" successfully created. [root@chy] # vgcreate nfsdisk / dev/sdb1 [root@chy] # lvcreate-L 10G-n nfsvolume nfsdiskLogical volume "nfsvolume" created. [root@chy01 ~] # lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 20G 0 disk ├─ sda1 8:1 0200M 0 part / boot └─ sda2 8:2 0 18.9G 0 part ├─ cl-root 253 sda2 009G 0 lvm / ├─ cl-swap 253 0 800M 0 lvm [SWAP] ├─ cl-home 253:2 0 500M 0 lvm / home └─ cl-var 253:3 0 8.6G 0 lvm / varsdb 8:16 0 20G 0 disk └─ sdb1 8:17 0 20G 0 part └─ nfsdisk-nfsvolume 253:4 0 100M 0 lvm sr0 11:0 1 4 .1G 0 rom [root@chy drbd.d] # ls-l / dev/nfsdisk/nfsvolume / / check whether it has been created successfully. Use lrwxrwxrwx 1 root root 7 December 19 00:29 / dev/nfsdisk/nfsvolume->.. / dm-4 [root@chy ~] # lvdisplay / / View information
Do the following configuration on the master (drbd)
[root@chy etc] # cat drbd.conf # You can find an example in / usr/share/doc/drbd.../drbd.conf.example
# include "drbd.d/global_common.conf"; # comment out this line to avoid conflicts with the configuration we wrote ourselves.
Include "drbd.d/.res"
Include "drbd.d/.cfg"; add a line of cfg
[root@chy drbd.d] # cat drbd_basic.cfg # # main configuration file (create drbd_basic.cfg under / etc/drbd.d)
Global {
It doesn't matter whether usage-count yes; # participates in DRBD user statistics or not. The default is yes,yes or no.
}
Common {
Syncer {rate 30m;} # sets the maximum network rate for synchronization between master and slave nodes. The default unit is bytes, which can be set to megabytes.
}
Resource R0 {# R0 is the resource name, which can be initialized with the resource name when initializing the disk.
Protocol C; # uses the C protocol.
Handlers {
Pri-on-incon-degr "echo o > / proc/sysrq-trigger; halt-f"
Pri-lost-after-sb "echo o > / proc/sysrq-trigger; halt-f"
Local-io-error "echo o > / proc/sysrq-trigger; halt-f"
Fence-peer "/ usr/lib4/heartbeat/drbd-peer-outdater-t 5"
Pri-lost "echo pri-lst. Have a look at the log file. | mail-s' Drbd Alert' root"
Split-brain "/ usr/lib/drbd/notify-split-brain.sh root"
Out-of-sync "/ usr/lib/drbd/notify-out-of-sync.sh root"
}
Net {
Cram-hmac-alg "sha1"
Shared-secret "NFS-HA"
# Authentication method and password information used in drbd synchronization
}
Disk {
On-io-error detach
Fencing resource-only
Use the DOPD (drbd outdate-peer deamon) function to ensure that there is no switching when the data is out of sync. } startup {wfc-timeout 120; degr-wfc-timeout 120;} device / dev/drbd0; # where / dev/drbd0 is the device name when the user mounts it. The description of each hostname created by the DRBD process begins with on, followed by hostname (which must be resolvable in / etc/hosts) disk/ dev/nfsdisk/nfsvolume; # uses this disk as the disk / dev/drbd0 of / dev/nfsdisk/nfsvolume. Address 192.168.212.10 address 7788; # sets the listening port of DRBD, which is used to communicate with another host meta-disk internal; # drbd metadata storage mode} on chy01 {disk/ dev/nfsdisk/nfsvolume; address 192.168.212.11140 7788; meta-disk internal;}
}
[root@chy drbd.d] # drbdadm create-md R0 / / create Metabase
WARN:
You are using the 'drbd-peer-outdater' as fence-peer program.
If you use that mechanism the dopd heartbeat plugin program needs
To be able to call drbdsetup and drbdmeta with root privileges.
You need to fix this with these commands:
Chgrp haclient / lib/drbd/drbdsetup-84
Chmod Omurx / lib/drbd/drbdsetup-84
Chmod Utility / lib/drbd/drbdsetup-84
Chgrp haclient / usr/sbin/drbdmeta
Chmod Omurx / usr/sbin/drbdmeta
Chmod Utility / usr/sbin/drbdmeta
Initializing activity log
Initializing bitmap (320KB) to all zero
Writing meta data...
New drbd meta data block successfully created. # # created successfully
Success
# the commands prompted above are as follows, which are not necessary:
Useradd haclient
Chgrp haclient / lib/drbd/drbdsetup-84
Chmod Omurx / lib/drbd/drbdsetup-84
Chmod Utility / lib/drbd/drbdsetup-84
Chgrp haclient / sbin/drbdmeta
Chmod Omurx / sbin/drbdmeta
Chmod Utility / sbin/drbdmeta
[root@chy drbd.d] # service drbd start
[root@chy drbd.d] # ps aux | grep drbd
Root 11624 0.0 0.0 0 0? S
< 02:33 0:00 [drbd-reissue] root 60363 0.0 0.0 0 0 ? S< 05:36 0:00 [drbd0_submit] root 64193 0.0 0.0 112660 972 pts/0 R+ 05:51 0:00 grep --color=auto drbd [root@chy drbd.d]# drbdadm primary all #把当前服务器设置为primary状态(主节点),如果这一步执行不成功,那么执行这个命令"drbdadm -- --overwrite-data-of-peer primary all" [root@chy drbd.d]# drbdadm primary all WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta 0: State change failed: (-2) Need access to UpToDate data Command 'drbdsetup-84 primary 0' terminated with exit code 17 [root@chy drbd.d]# drbdadm up r0 // [root@chy drbd.d]# drbdadm primary r0 --force //强制设置成主节点 如果可以正常启动,那么就把/etc/drbd.d/drbd_basic.cfg和/etc/drbd.conf复制到备的机器上我用的是scp [root@chy01 drbd.d]# scp 192.168.212.10:/etc/drbd.conf /etc/drbd.conf drbd.conf 100% 158 0.2KB/s 00:00 [root@chy01 drbd.d]# scp 192.168.212.10:/etc/drbd.d/drbd_basic.cfg /etc/drbd.d/drbd_basic.cfg drbd_basic.cfg 使用drbdadm create-md r0 创建元数据库在/dev/mapper/nfsdisk-nfsvolume (在备的机器上操作) [root@chy01 drbd.d]# drbdadm create-md r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta initializing activity log initializing bitmap (320 KB) to all zero Writing meta data... New drbd meta data block successfully created. success 1. 这里我就简要说说11(备)做的操作了,其实两者做的操作也一样。格式化磁盘,使用配置文件指定的/dev/sdb1,两者的容量要大小相同。2. 使用drbdadm create-md r0 创建元数据库在/dev/sdb1。3. 启动服务。service drbd start。4. 查看状态。service drbd status.在backup服务器上做完上述说的操作后,我们在bakcup服务器查看drbd的状态: [root@chy01 drbd.d]# service drbd status Redirecting to /bin/systemctl status drbd.service ● drbd.service - DRBD -- please disable. Unless you are NOT using a cluster manager. Loaded: loaded (/usr/lib/systemd/system/drbd.service; disabled; vendor preset: disabled) Active: active (exited) since Fri 2017-12-15 06:12:37 CST; 3min 46s ago Process: 3995 ExecStart=/lib/drbd/drbd start (code=exited, status=0/SUCCESS) Main PID: 3995 (code=exited, status=0/SUCCESS) Dec 15 06:12:37 chy01 drbd[3995]: to be able to call drbdsetup and drbdmeta with root privileges. Dec 15 06:12:37 chy01 drbd[3995]: You need to fix this with these commands: Dec 15 06:12:37 chy01 drbd[3995]: chgrp haclient /lib/drbd/drbdsetup-84 Dec 15 06:12:37 chy01 drbd[3995]: chmod o-x /lib/drbd/drbdsetup-84 Dec 15 06:12:37 chy01 drbd[3995]: chmod u+s /lib/drbd/drbdsetup-84 Dec 15 06:12:37 chy01 drbd[3995]: chgrp haclient /usr/sbin/drbdmeta Dec 15 06:12:37 chy01 drbd[3995]: chmod o-x /usr/sbin/drbdmeta Dec 15 06:12:37 chy01 drbd[3995]: chmod u+s /usr/sbin/drbdmeta Dec 15 06:12:37 chy01 drbd[3995]: . Dec 15 06:12:37 chy01 systemd[1]: Started DRBD -- please disable. Unless you are NOT using a cluster manager.. [root@chy01 drbd.d]# drbdadm dstate r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta Inconsistent/UpToDate [root@chy01 drbd.d]# drbdadm role r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta Secondary/Primary [root@chy drbd.d]# service drbd status # drbd master上查看 Redirecting to /bin/systemctl status drbd.service ● drbd.service - DRBD -- please disable. Unless you are NOT using a cluster manager. Loaded: loaded (/usr/lib/systemd/system/drbd.service; disabled; vendor preset: disabled) Active: active (exited) since 五 2017-12-15 02:33:20 CST; 3h 40min ago Main PID: 11620 (code=exited, status=0/SUCCESS) CGroup: /system.slice/drbd.service 12月 15 02:33:20 chy systemd[1]: Starting DRBD -- please disable. Unless you are NOT using a cluster manager.... 12月 15 02:33:20 chy drbd[11620]: Starting DRBD resources: no resources defined! 12月 15 02:33:20 chy drbd[11620]: no resources defined! 12月 15 02:33:20 chy drbd[11620]: WARN: stdin/stdout is not a TTY; using /dev/consoleWARN: stdin/stdout is...ined! 12月 15 02:33:20 chy drbd[11620]: . 12月 15 02:33:20 chy systemd[1]: Started DRBD -- please disable. Unless you are NOT using a cluster manager.. Hint: Some lines were ellipsized, use -l to show in full. [root@chy drbd.d]# drbdadm dstate r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta UpToDate/Inconsistent [root@chy drbd.d]# drbdadm role r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta Primary/Secondary 挂载DRBD的磁盘(drbd master)上操作: [root@chy drbd.d]# mkfs.ext4 /dev/drbd0 //需要格式化 mke2fs 1.42.9 (28-Dec-2013) 文件系统标签= OS type: Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 2621351 blocks 131067 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=2151677952 80 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: 完成 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 [root@chy drbd.d]# mkdir /database [root@chy drbd.d]# mount /dev/drbd0 /database/ [root@chy drbd.d]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/cl-root 8.8G 7.6G 748M 92% / devtmpfs 737M 0 737M 0% /dev tmpfs 748M 4.0K 748M 1% /dev/shm tmpfs 748M 8.6M 739M 2% /run tmpfs 748M 0 748M 0% /sys/fs/cgroup /dev/sda1 190M 136M 41M 77% /boot /dev/mapper/cl-var 8.4G 3.5G 4.5G 44% /var /dev/mapper/cl-home 497M 66M 431M 14% /home tmpfs 150M 0 150M 0% /run/user/0 /dev/drbd0 9.8G 37M 9.2G 1% /database [root@chy ~]# cat /proc/drbd //centos7用这个查看drbd当前主的状态 version: 8.4.10-1 (api:1/proto:86-101) GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22 0: cs:Connected ro:Primary/Secondary ds:Diskless/UpToDate C r----- ns:135468 nr:1440 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0 [root@chy01 ~]# cat /proc/drbd //centos7用这个查看drbd当前主的状态 version: 8.4.10-1 (api:1/proto:86-101) GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22 0: cs:Connected ro:Secondary/Primary ds:UpToDate/Diskless C r----- ns:1440 nr:135468 dw:10620872 dr:1440 al:125 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:10485404 主端挂载完后去格式化备端和挂载,主要是检测备端是否能够正常挂载和使用,格式化之前需要主备状态切换,切换的方法请看下面的DRBD设备角色切换的内容。下面就在备端格式化和挂载磁盘。(备端也可以这样挂载磁盘,但是挂载的前提是备端切换成master端。只有master端可以挂载磁盘。)DRBD设备角色切换DRBD设备在角色切换之前,需要在主节点执行umount命令卸载磁盘先,然后再把一台主机上的DRBD角色修改为Primary,最后把当前节点的磁盘挂载 第一种方法: 在192.168.212.10上操作(当前是primary)。 [root@chy ~]# umount /dev/drbd0 [root@chy ~]# drbdadm secondary r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta [root@chy ~]# cat /proc/drbd version: 8.4.10-1 (api:1/proto:86-101) GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22 0: cs:Connected ro:Secondary/Secondary ds:Diskless/UpToDate C r----- ns:135552 nr:1917 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0 发现两台都是备机 在192.168.212.11上操作。 [root@chy01 ~]# drbdadm primary r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta [root@chy01 ~]# cat /proc/drbd version: 8.4.10-1 (api:1/proto:86-101) GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22 0: cs:Connected ro:Primary/Secondary ds:UpToDate/Diskless C r----- ns:1917 nr:135552 dw:10784752 dr:2829 al:148 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:10485404 已经切换成功 [root@dbbackup136 ~]# mkfs.ext4 /dev/drbd0 # 在没有切换成primary状态的时候,是没法格式化磁盘的。 第二种方法: 在192.168.212.11上操作(当前是primary)。 [root@dbbackup136 ~]# service drbd stop # 先停止服务 Stopping all DRBD resources: [root@chy01 ~]# service drbd start //之后在启动 在192.168.212.10上操作 [root@chy ~]# drbdadm primary r0 WARN: You are using the 'drbd-peer-outdater' as fence-peer program. If you use that mechanism the dopd heartbeat plugin program needs to be able to call drbdsetup and drbdmeta with root privileges. You need to fix this with these commands: chgrp haclient /lib/drbd/drbdsetup-84 chmod o-x /lib/drbd/drbdsetup-84 chmod u+s /lib/drbd/drbdsetup-84 chgrp haclient /usr/sbin/drbdmeta chmod o-x /usr/sbin/drbdmeta chmod u+s /usr/sbin/drbdmeta [root@chy ~]# cat /proc/drbd version: 8.4.10-1 (api:1/proto:86-101) GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22 0: cs:Connected ro:Primary/Secondary ds:Diskless/UpToDate C r----- ns:135552 nr:2829 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0 一般我用的是第一种方法 说明:如上只是一个来回切换的小测试,接下来开始做keepalived keepalived主上的操作(具体的配置介绍我这就不说了,https://blog.51cto.com/chy940405/2052014 这里是我更新的文章有需要的可以看看) [root@chy keepalived]# cat keepalived.conf global_defs{ notification_email {chy@chy.combr/>Chy@chy.com
Notification_email_from root@chy.com
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
Vrrp_scriptchk_nfs {
Script "/ etc/keepalived/check_nfs.sh"
Interval 5
}
Vrrp_instance VI_1 {
State MASTER
Interface br0
Virtual_router_id 51
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass chylinux > com
}
Virtual_ipaddress {
Address of 192.168.212.100 / / vip
}
Track_script {
Chk_nfs
}
Script for notify_master / etc/keepalived/notify_master.sh / / master
Notify_stop / etc/keepalived/notify_stop.sh
}
[root@chy keepalived] # cat check_nfs.sh
#! / bin/sh
# check the availability of nfs: process and whether it can be mounted
/ sbin/service nfs status & > / dev/null
If [$?-ne 0]; then
# if the service status is abnormal, try to restart the service first
/ sbin/service nfs status & > / dev/null
If [$?-ne 0]; then
# if the nfs service is restarted, it is still abnormal.
# Uninstall drbd0 device
Umount / dev/drbd0
# downgrade drbd master to standby
Drbdadm secondary r0
# turn off keepalived
/ sbin/service keepalived stop
Fi
Fi
[root@chy keepalived] # cat notify_master.sh
#! / bin/bash
Time=date "+ F H:%M:%S"
Echo-e "$time-notify_master-\ n" > > / etc/keepalived/logs/notify_master.log
/ sbin/drbdadm primary R0 & > > / etc/keepalived/logs/notify_master.log
/ bin/mount / dev/drbd0 / database & > > / etc/keepalived/logs/notify_master.log
/ sbin/service nfs restart & > > / var/log/master.log
Echo-e "\ n" > > / etc/keepalived/logs/notify_master.log
Standby operation
[root@chy01 keepalived] # cat keepalived.conf
Global_defs {
Notification_email {chy@chy.combr/ > chy@chy.com
Notification_email_from root@chy.com
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
Router_id LVS_DEVEL
}
Vrrp_scriptchk_nfs {
Script "/ etc/keepalived/check_nfs.sh"
Interval 5
}
Vrrp_instance VI_1 {
State BACKUP
Interface ens33
Virtual_router_id 51
Priority 90
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass chylinux
}
Virtual_ipaddress {
192.168.212.100
}
Track_script {
Chk_nfs
}
Notify_master / etc/keepalived/notify_master.sh
Notify_backup / etc/keepalived/notify_backup.sh
}
[root@chy01 keepalived] # cat check_nfs.sh
#! / bin/sh
# check the availability of nfs: process and whether it can be mounted
/ sbin/service nfs status & > / dev/null
If [$?-ne 0]; then
# if the service status is abnormal, try to restart the service first
/ sbin/service nfs status & > / dev/null
If [$?-ne 0]; then
# if the nfs service is restarted, it is still abnormal.
# Uninstall drbd0 device
Umount / dev/drbd0
# downgrade drbd master to standby
Drbdadm secondary r0
# turn off keepalived
/ sbin/service keepalived stop
Fi
Fi
[root@chy01 keepalived] # cat notify_backup.sh
#! / bin/bash
Time=date "+ F H:%M:%S"
Echo-e "$time-notify_backup-\ n" > > / etc/keepalived/logs/notify_backup.log
/ sbin/service nfs stop & > > / etc/keepalived/logs/notify_backup.log
/ bin/umount / database & > > / etc/keepalived/logs/notify_backup.log
/ sbin/drbdadm secondary all & > > / etc/keepalived/logs/notify_backup.log
Echo-e "\ n" > > / etc/keepalived/logs/notify_backup.log
[root@chy01 keepalived] # cat notify_master.sh
#! / bin/bash
Time=date "+ F H:%M:%S"
Echo-e "$time-notify_master-\ n" > > / etc/keepalived/logs/notify_master.log
/ sbin/drbdadm primary R0 & > > / etc/keepalived/logs/notify_master.log
/ bin/mount / dev/drbd0 / database & > > / etc/keepalived/logs/notify_master.log
/ sbin/service nfs restart & > > / var/log/master.log
Echo-e "\ n" > > / etc/keepalived/logs/notify_master.log
If you close the host keepalived, you will follow the expected process. Shut down the nfs-- uninstall resource device on the master-- Primary drbd downgrade-- standby drdb upgrade-- standby mount resource device-- standby start nfs service. The general meaning of the script.
Operation of nfs master
[root@chy ~] # cat / etc/exports
/ database 192.168.212.12Accord 24 (rw,sync,no_root_squash)
The directory I share here is the database directory. Why should I share this because I mounted drbd to this directory before?
[root@chy ~] # exportfs-avr
Exporting 192.168.212.12/24:/database
The nfs backup operation can directly operate the main scp on the server side of the nfs.
[root@chy02 mnt] # showmount-e 192.168.212.100
Export list for 192.168.212.100:
/ database 192.168.212.12/24
[root@chy02 mnt] # mount-t nfs 192.168.212.100:/database/ / mnt
[root@chy02 mnt] # df-h
File system capacity used available used% mount point
/ dev/mapper/cl-root 8.8G 5.7G 2.6G 69% /
Devtmpfs 737M 0737M 0% / dev
Tmpfs 748M 0748M 0% / dev/shm
Tmpfs 748M 8.6m 739m 2% / run
Tmpfs 748M 0748M 0% / sys/fs/cgroup
/ dev/sda1 190m 107m 70m 61% / boot
/ dev/mapper/cl-var 8.4G 276m 7.7G 4% / var
/ dev/mapper/cl-home 497M 26M 472m 6% / home
Tmpfs 150M 0 150m 0% / run/user/0
192.168.212.100:/database 93M 1.5m 85m 2% / mnt
[root@chy02 mnt] # touch 1.19
Start testing on the active and standby (all of the following are related to testing)
[root@chy keepalived] # df-h
File system capacity used available used% mount point
/ dev/mapper/cl-root 8.8G 7.6G 744m 92% /
Devtmpfs 737M 0737M 0% / dev
Tmpfs 748M 4.0K 748m 1% / dev/shm
Tmpfs 748M 26M 722m 4% / run
Tmpfs 748M 0748M 0% / sys/fs/cgroup
/ dev/sda1 190m 136m 41m 77% / boot
/ dev/mapper/cl-var 8.4G 3.1G 4.9G 39% / var
/ dev/mapper/cl-home 497M 66M 431M 14% / home
Tmpfs 150M 0 150m 0% / run/user/0
/ dev/drbd0 93M 1.6m 85m 2% / database
[root@chy keepalived] # cd / database/
[root@chy database] # ls
~ 111 112 1.19 12.19 222 333 444 bbb
Now stop the main keepalivedd and see if it can still be operated on the server.
[root@chy database] # systemctl stop keepalived
[root@chy database] # ps aux | grep keepalived
Root 83980 0.0 112660 980 pts/1 R + 06:53 0:00 grep-color=auto keepalived
[root@chy database] # cat / proc/drbd
Version: 8.4.10-1 (api:1/proto:86-101)
GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:29 nr:56 dw:85 dr:3674 al:2 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
That's weird. How did that happen? Shouldn't we switch over? Don't worry. We can check the log.
[root@chy database] # cat / etc/keepalived/logs/notify_stop.log
This is the log defined in the script before. The following error message is found in the log.
Redirecting to / bin/systemctl stop nfs.service
Umount: / database: target busy.
(in some cases, through lsof (8) or fuser (1)
Find useful information about processes using the device)
WARN:
You are using the 'drbd-peer-outdater' as fence-peer program.
If you use that mechanism the dopd heartbeat plugin program needs
To be able to call drbdsetup and drbdmeta with root privileges.
You need to fix this with these commands:
Chgrp haclient / lib/drbd/drbdsetup-84
Chmod Omurx / lib/drbd/drbdsetup-84
Chmod Utility / lib/drbd/drbdsetup-84
Chgrp haclient / usr/sbin/drbdmeta
Chmod Omurx / usr/sbin/drbdmeta
Chmod Utility / usr/sbin/drbdmeta
0: State change failed: (- 12) Device is held open by someone
Command 'drbdsetup-84 secondary 0' terminated with exit code 11
[root@chy database] # df-h
File system capacity used available used% mount point
/ dev/mapper/cl-root 8.8G 7.6G 744m 92% /
Devtmpfs 737M 0737M 0% / dev
Tmpfs 748M 4.0K 748m 1% / dev/shm
Tmpfs 748M 26M 722m 4% / run
Tmpfs 748M 0748M 0% / sys/fs/cgroup
/ dev/sda1 190m 136m 41m 77% / boot
/ dev/mapper/cl-var 8.4G 3.1G 4.9G 39% / var
/ dev/mapper/cl-home 497M 66M 431M 14% / home
Tmpfs 150M 0 150m 0% / run/user/0
/ dev/drbd0 93M 1.6m 85m 2% / database
[root@chy database] # umount / database/ is also not allowed to uninstall manually
Umount: / database: target busy.
(in some cases, through lsof (8) or fuser (1)
Find useful information about processes using the device)
The solution is as follows:
[root@chy database] # fuser-m / dev/drbd0/
/ dev/drbd0: 595c
[root@chy database] # ps aux | grep 595
Root 595 0.0 0.1 115720 2340 pts/1 Ss 02:31 0:00-bash
Root 90942 0.0 112660 976 pts/1 R + 07:02 0:00 grep-color=auto 595
[root@chy database] # kill 595
[root@chy keepalived] # sh-x notify_stop.sh
+ + date'+% F% HRV% MVR% S'
Time='2017-12-19 07:04:19'echo-e '2017-12-19 07:04:19-notify_stop-\ n'/sbin/service nfs stop/bin/umount / database/sbin/drbdadm secondary allecho-e'\ n'
[root@chy keepalived] # df-h View is no longer mounted
File system capacity used available used% mount point
/ dev/mapper/cl-root 8.8G 7.6G 744m 92% /
Devtmpfs 737M 0737M 0% / dev
Tmpfs 748M 4.0K 748m 1% / dev/shm
Tmpfs 748M 26M 722m 4% / run
Tmpfs 748M 0748M 0% / sys/fs/cgroup
/ dev/sda1 190m 136m 41m 77% / boot
/ dev/mapper/cl-var 8.4G 3.1G 4.9G 39% / var
/ dev/mapper/cl-home 497M 66M 431M 14% / home
Tmpfs 150M 0 150m 0% / run/user/0
[root@chy01 ~] # cat / proc/drbd / / View on slave has been switched normally
Version: 8.4.10-1 (api:1/proto:86-101)
GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-
Ns:57 nr:113 dw:170 dr:3665 al:2 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[root@chy01] # df-h
Filesystem Size Used Avail Use% Mounted on
/ dev/mapper/cl-root 8.8G 5.8G 2.6G 69% /
Devtmpfs 737M 0737M 0% / dev
Tmpfs 748M 0748M 0% / dev/shm
Tmpfs 748M 17M 731m 3% / run
Tmpfs 748M 0748M 0% / sys/fs/cgroup
/ dev/sda1 190m 135m 41m 77% / boot
/ dev/mapper/cl-var 8.4G 710m 7.3G 9% / var
/ dev/mapper/cl-home 497M 66M 432M 14% / home
Tmpfs 150M 0 150m 0% / run/user/0
/ dev/drbd0 93M 1.6m 85m 2% / database
[root@chy02 ~] # cd / mnt/
[root@chy02 mnt] # ls
~ 111 112 1.19 12.19 222 333 444 bbb
The data are all here, and the high availability has been basically completed as mentioned above, but there is a problem that has not yet been solved, that is, if the master node is powered off or shut down directly, it will lead to abnormal master / slave switching. I don't know if other partners have a good way to discuss with me and look forward to a good one. **
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.