如何在CentOS 7上使用Pacemaker配置NFS服务器群集
如何在CentOS 7上使用Pacemaker配置NFS服务器群集
由Pradeep Kumar ·发布 2018年3月5日 · 更新 2019年4月12日
NFS(网络文件系统)是通过网络提供文件的最广泛的服务器。使用NFS服务器,我们可以在网络上共享文件夹,并且允许客户端或系统访问这些共享文件夹并可以在其应用程序中使用它们。在生产环境中,我们应该配置高可用性的nfs服务器以排除单点故障。
在本文中,我们将讨论如何在CentOS 7或RHEL 7上使用起搏器配置nfs服务器高可用性群集(主动-被动)
以下是我在本文中使用的实验详细信息,
- NFS服务器1(nfs1.example.com)– 192.168.1.40 –最低CentOS 7 / RHEL 7
- NFS服务器2(nfs2.example.com)– 192.168.1.50 –最低CentOS 7 / RHEL 7
- NFS服务器VIP – 192.168.1.51
- 启用防火墙
- 启用SELinux
请参考以下步骤在CentOS 7 / RHEL 7上配置NFS服务器主动-被动群集
步骤:1在两个nfs服务器上设置主机名并更新/ etc / hosts文件
登录两个nfs服务器,并使用hostnamectl命令将主机名分别设置为“ nfs1.example.com”和“ nfs2.example.com”,示例如下所示。
~]# hostnamectl set-hostname "nfs1.example.com"
~]# exec bash
更新两个nfs服务器上的/ etc / hosts文件,
192.168.1.40 nfs1.example.com
192.168.1.50 nfs2.example.com
步骤:2更新两个nfs服务器并安装pc软件包
使用以下“ yum update”命令在两个nfs服务器上应用所有更新,然后重新启动一次。
~]# yum update && reboot
在两个nfs服务器上安装pc和fence-agent软件包,
[[email protected] ~]# yum install -y pcs fence-agents-all
[[email protected] ~]# yum install -y pcs fence-agents-all
一旦安装了pc和fencing代理程序的软件包,然后从两个nfs服务器的OS防火墙中允许与pcs相关的端口,
~]# firewall-cmd --permanent --add-service=high-availability
~]# firewall-cmd --reload
现在,使用下面的命令在两个nfs节点上启动并启用pcsd服务,
~]# systemctl enable pcsd
~]# systemctl start pcsd
步骤:3验证nfs节点并形成集群
将密码设置为hacluster用户,pcsd服务将使用该用户来认证集群节点,因此,我们首先在两个节点上将密码设置为hacluster user,
[[email protected] ~]# echo "enter_password" | passwd --stdin hacluster
[[email protected] ~]# echo "enter_password" | passwd --stdin hacluster
现在对集群节点进行身份验证,在本例中,将在nfs1.example.com上对nfs2.example.com进行身份验证,在“ nfs1”上运行以下pcs cluster命令
[[email protected] ~]# pcs cluster auth nfs1.example.com nfs2.example.com
Username: hacluster
Password:
nfs1.example.com: Authorized
nfs2.example.com: Authorized
[[email protected] ~]#
现在是时候形成一个名为“ nfs_cluster ” 的集群并将两个nfs节点添加到其中了。从任何nfs节点运行以下“ pcs cluster setup ”命令,
[[email protected] ~]# pcs cluster setup --start --name nfs_cluster nfs1.example.com nfs2.example.com
在两个节点上都启用pcs群集服务,以便节点在重新启动后将自动加入群集。从nfs节点之一执行以下命令,
[[email protected] ~]# pcs cluster enable --all
nfs1.example.com: Cluster Enabled
nfs2.example.com: Cluster Enabled
[[email protected] ~]#
步骤:4为每个群集节点定义Fencing设备。
防护是群集中最重要的部分,如果任何节点出现故障,则防护设备将从该群集中删除该节点。在Pacemaker中,使用Stonith(在头上射击另一个节点)资源定义围栏。
在本教程中,我们将使用大小为1 GB(/ dev / sdc)的共享磁盘作为防护设备。首先让我们找出/ dev / sdc磁碟的ID
[[email protected] ~]# ls -l /dev/disk/by-id/
记下磁盘/ dev / sdc的ID,因为我们将在“ pcs stonith ”命令中使用它。
现在从任一节点的“ pcs stonith”命令下运行以创建隔离设备(disk_fencing)
[[email protected] ~]# pcs stonith create disk_fencing fence_scsi pcmk_host_list="nfs1.example.com nfs2.example.com" pcmk_monitor_action="metadata" pcmk_reboot_action="off" devices="/dev/disk/by-id/wwn-0x6001405e49919dad5824dc2af5fb3ca0" meta provides="unfencing"
[[email protected] ~]#
使用以下命令验证stonith的状态,
[[email protected] ~]# pcs stonith show
disk_fencing (stonith:fence_scsi): Started nfs1.example.com
[[email protected] ~]#
运行“ pcs status ”命令查看集群状态
[[email protected] ~]# pcs status
Cluster name: nfs_cluster
Stack: corosync
Current DC: nfs2.example.com (version 1.1.16-12.el7_4.7-94ff4df) - partition with quorum
Last updated: Sun Mar 4 03:18:47 2018
Last change: Sun Mar 4 03:16:09 2018 by root via cibadmin on nfs1.example.com
2 nodes configured
1 resource configured
Online: [ nfs1.example.com nfs2.example.com ]
Full list of resources:
disk_fencing (stonith:fence_scsi): Started nfs1.example.com
Daemon Status:
corosync: active/enabled
pacemaker: active/enabled
pcsd: active/enabled
[[email protected] ~]#
注意:如果群集节点是虚拟机并托管在VMware上,则可以使用“ fence_vmware_soap ”防护代理。要将“ fence_vmware_soap”配置为防护代理,请参考以下逻辑步骤:
1)验证您的群集节点是否可以访问VMware虚拟机管理程序或Vcenter
# fence_vmware_soap -a <vCenter_IP_address> -l <user_name> -p <password> --ssl -z -v -o list |egrep "(nfs1.example.com|nfs2.example.com)"
or
# fence_vmware_soap -a <vCenter_IP_address> -l <user_name> -p <password> --ssl -z -o list |egrep "(nfs1.example.com|nfs2.example.com)"
如果能够在输出中看到VM名称,那就很好,否则,您需要检查为什么群集节点无法建立esxi或vcenter连接。
2)使用以下命令定义围栏设备,
# pcs stonith create vmware_fence fence_vmware_soap pcmk_host_map="node1:nfs1.example.com;node2:nfs2.example.com" ipaddr=<vCenter_IP_address> ssl=1 login=<user_name> passwd=<password>
3)使用以下命令检查stonith状态,
# pcs stonith show
步骤:5安装nfs并格式化nfs共享磁盘
在两个nfs服务器上安装“ nfs-utils”软件包
[[email protected] ~]# yum install nfs-utils -y
[[email protected] ~]# yum install nfs-utils -y
在两个节点上停止并禁用本地“ nfs-lock ”服务,因为该服务将由心脏起搏器控制
[[email protected] ~]# systemctl stop nfs-lock && systemctl disable nfs-lock
[[email protected] ~]# systemctl stop nfs-lock && systemctl disable nfs-lock
假设我们在两个群集节点之间有一个大小为10 GB的共享磁盘“ / dev / sdb”,在其上创建分区并将其格式化为xfs文件系统
[[email protected] ~]# fdisk /dev/sdb
在两个节点上运行partprobe命令,然后重新引导一次。
~]# partprobe
现在将“ / dev / sdb1”格式化为xfs文件系统
[[email protected] ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=655296 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=2621184, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]#
在两个节点上为此文件系统创建安装点,
[[email protected] ~]# mkdir /nfsshare
[[email protected] ~]# mkdir /nfsshare
步骤:6在群集节点上配置所有必需的NFS资源
以下是必需的NFS资源:
- 文件系统资源
- nfsserver资源
- exportfs资源
- IPaddr2浮动IP地址资源
对于文件系统资源,我们需要在群集节点之间共享存储,已经在上述步骤中在共享磁盘(/ dev / sdb1)上创建了分区,因此我们将使用该分区。使用以下“ pcs resource create ”命令从任何节点定义文件系统资源,
[[email protected] ~]# pcs resource create nfsshare Filesystem device=/dev/sdb1 directory=/nfsshare fstype=xfs --group nfsgrp
[[email protected] ~]#
在上面的命令中,我们将NFS文件系统定义为“ nfsgrp ”组下的“ nfsshare ”。现在,所有nfs资源将在nfsgrp组下创建。
使用以下命令创建名称为“ nfsd ”的nfsserver资源,
[[email protected] ~]# pcs resource create nfsd nfsserver nfs_shared_infodir=/nfsshare/nfsinfo --group nfsgrp
[[email protected] ~]#
创建名为“ nfsroot ”的exportfs资源
[[email protected] ~]# pcs resource create nfsroot exportfs clientspec="192.168.1.0/24" options=rw,sync,no_root_squash directory=/nfsshare fsid=0 --group nfsgrp
[[email protected] ~]#
在上面的命令中,clientspec指示允许的客户端可以访问nfsshare
使用以下命令创建NFS IPaddr2资源,
[[email protected] ~]# pcs resource create nfsip IPaddr2 ip=192.168.1.51 cidr_netmask=24 --group nfsgrp
[[email protected] ~]#
现在使用pcs状态查看和验证集群
[[email protected] ~]# pcs status
使用完NFS资源后,请允许两台nfs服务器在OS防火墙中使用nfs服务器端口,
~]# firewall-cmd --permanent --add-service=nfs
~]# firewall-cmd --permanent --add-service=mountd
~]# firewall-cmd --permanent --add-service=rpc-bind
~]# firewall-cmd --reload
步骤:7尝试在客户端上挂载NFS共享
现在尝试使用mount命令挂载nfs共享,示例如下所示
[[email protected] ~]# mkdir /mnt/nfsshare
[[email protected] ~]# mount 192.168.1.51:/ /mnt/nfsshare/
[[email protected] ~]# df -Th /mnt/nfsshare
Filesystem Type Size Used Avail Use% Mounted on
192.168.1.51:/ nfs4 10G 32M 10G 1% /mnt/nfsshare
[[email protected] ~]#
[[email protected] ~]# cd /mnt/nfsshare/
[[email protected] nfsshare]# ls
nfsinfo
[[email protected] nfsshare]#
对于群集测试,请在任何节点上停止群集服务,然后查看nfsshare是否可访问。假设我要停止“ nfs1.example.com”上的群集服务
[[email protected] ~]# pcs cluster stop
Stopping Cluster (pacemaker)...
Stopping Cluster (corosync)...
[[email protected] ~]#
现在转到客户端计算机,看看是否仍然可以访问nfsshare。就我而言,我仍然能够访问它并能够在其上创建文件。
[[email protected] nfsshare]# touch test
[[email protected] nfsshare]#
现在,使用以下命令在“ nfs1.example.com”上启用群集服务,
这就是本文的全部内容,它确认我们已使用心脏起搏器成功配置了NFS主动-被动群集。请在下面的评论部分中分享您的反馈和评论。