Centos 7.2搭建NFS集群
使用到的软件列表
名字 | 说明 |
---|---|
DRBD | 基于网络的RAID1实现 |
NFS | 网络文件系统 |
pacemaker | 一个群集资源管理器 |
crmsh | pacemaker cli |
pcs | packmaker web ui + cli |
corosync | 集群成员之间通信管理软件 |
环境准备
host | ip | vip | os | lvm device | drbd device | nfs directory |
---|---|---|---|---|---|---|
node1 | 10.2.6.41 | 10.2.6.40 | Cetnos7.2 | /dev/nfs/work | drbr0 | /home/nfs |
node2 | 10.2.6.42 | 10.2.6.40 | Cetnos7.2 | /dev/nfs/work | drbd0 | /home/nfs |
时间同步
1
2
3[root@node1 .ssh]# sudo ntp timeserver
[root@node2 .ssh]# sudo ntp timeserverhosts配置
1
2
3
4
5
6
7
8
9[root@node1 .ssh]# sudo hostnamectl set-hostname node1
[root@node1 .ssh]# sudo vim /etc/hosts
node1 10.2.6.41
node2 10.2.6.42
[root@node2 .ssh]# sudo hostnamectl set-hostname node2
[root@node2 .ssh]# sudo vim /etc/hosts
node1 10.2.6.41
node2 10.2.6.42免密登录配置
1
2
3
4
5
6
7
8
9
10
11
12
13生成密钥对
[root@node1 .ssh]# sudo ssh-keygen
公钥写入authorized_keys
[root@node1 .ssh]# sudo scp /root/.ssh/id_rsa.pub root@node2:/home
生成密钥对
[root@node2 .ssh]# sudo ssh-keygen
公钥写入authorized_keys
[root@node2 .ssh]# sudo scp /root/.ssh/id_rsa.pub root@node1:/home
[root@node1 .ssh]# sudo cat /home/id_rsa.pub >> /root/.ssh/authorized_keys
[root@node2 .ssh]# sudo cat /home/id_rsa.pub >> /root/.ssh/authorized_keys关闭防火墙
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17[root@node1 .ssh]# sudo systemctl stop firewalld
[root@node1 .ssh]# sudo systemctl disable firewalld
[root@node2 .ssh]# sudo systemctl stop firewalld
[root@node2 .ssh]# sudo systemctl disable firewalld
```
5. 关闭selinux
```shell
[root@node1 .ssh]# sudo vim /etc/selinux/config
SELINUX=disabled
[root@node1 .ssh]# sudo reboot now
[root@node2 .ssh]# sudo vim /etc/selinux/config
SELINUX=disabled
[root@node2 .ssh]# sudo reboot now
环境搭建
创建lvm
1 | 新建分区/dev/sdb1 |
安装配置DRBD
无特殊说明以下操作均在两个节点都操作
添加ELRepo仓库
1
2rpm --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)安装DRBD
1
2
3
4yum install drbd90-utils kmod-drbd90
禁止drbd开机启动,由pacemaker托管
systemctl disable drbd检查drbd内核模块
1
2
3
4
5
6
7lsmod | grep drbd
添加到内核
modprobe drbd
启动加载内核模块
echo drbd > /etc/modules-load.d/drbd.conf配置/etc/drbd.d/drbd0.res
1
2
3
4
5
6
7
8
9
10
11resource drbd0 {
disk /dev/nfs/work;
device /dev/drbd0;
meta-disk internal;
on node1 {
address 10.2.6.41:7790;
}
on node2 {
address 10.2.6.42:7790;
}
}创建元数据
1
drbdadm create-md drbd0
启动设备
1
drbdadm up drbd0
保证状态同步
1
drbdadm -- --clear-bitmap new-current-uuid drbd0/0
主节点node1上配置
1
2drbdadm primary drbd0
mkfs.xfs /dev/drbd0创建挂载点
1
mkdir /home/nfs/work
备节点node2配置
1
drbdadm secondary drbd0
安装pcs、pacemaker、corosync
安装
1
yum install pacemaker pcs resource-agents
设置hacluster用户密码
1
passwd hacluster
创建集群
1
2
3
4
5
6
7
8
9pcs cluster auth node1 node2 -u hacluster -p password --force
pcs cluster setup --force --name nfs_cluster node1 node2
pcs cluster start --all
pcs property set no-quorum-policy=ignore
pcs property set stonith-enabled=false
pcs cluster enable --all
pcs status安装crmsh
github下载安装包CRMSH
安装
1
2
3
4
5
6
7
8
9tar zxf ***.tar
cd crmsh
./autogen.sh
./configure
make
make install
python setup.py install安装nfs
1 | yum install nfs-utils rpcbind |
使用CRM管理配置pacemaker nfs集群
- 配置DRBD资源
1 | 进入crm控制台 |
- 设置nfs使用的文件系统资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21进入crm控制台
crm configure
添加文件系统
primitive p_fs_drbd0 ocf:heartbeat:Filesystem \
params device=/dev/drbd0 directory=/home/nfs fstype=xfs \
options=noatime,nodiratime \
op start interval="0" timeout="60s" \
op stop interval="0" timeout="60s" \
op monitor interval="20" timeout="40s"
添加依赖资源启动顺序
order o_drbd_r0-before-fs_drbd0 \
inf: ms_drbd_r0:promote p_fs_drbd0:start
托管服务配置
colocation c_fs_drbd0-with_drbd-r0 \
inf: p_fs_drbd0 ms_drbd_r0:Master
验证
verify
提交
commit
退出
exit - 设置nfs服务资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20进入crm控制台
crm configure
添加nfs服务
primitive p_nfsserver ocf:heartbeat:nfsserver \
params nfs_shared_infodir=/home/nfs/nfs_shared_infodir nfs_ip=10.2.6.40 \
op start interval=0s timeout=40s \
op stop interval=0s timeout=20s \
op monitor interval=10s timeout=20s
添加依赖资源启动顺序
order o_fs_drbd0-before-nfsserver \
inf: p_fs_drbd0 p_nfsserver
托管服务配置
colocation c_nfsserver-with-fs_drbd0 \
inf: p_nfsserver p_fs_drbd0
验证
verify
提交
commit
退出
exit - 设置nfs导出目录配置资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23mkdir -p /home/nfs/exports/iso
chown nfsnobody:nfsnobody /home/nfs/exports/iso
进入crm控制台
crm configure
添加nfs服务
primitive p_exportfs_dir1 ocf:heartbeat:exportfs \
params clientspec=* directory=/home/nfs/exports/iso fsid=1 \
unlock_on_stop=1 options=rw,sync \
op start interval=0s timeout=40s \
op stop interval=0s timeout=120s \
op monitor interval=10s timeout=20s
添加依赖资源启动顺序
order o_nfsserver-before-exportfs-dir1 \
inf: p_nfsserver p_exportfs_dir1
托管服务配置
colocation c_exportfs-with-nfsserver \
inf: p_exportfs_dir1 p_nfsserver
验证
verify
提交
commit
退出
exit - 设置虚拟IP资源
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20进入crm控制台
crm configure
添加VIP
primitive p_virtip_dir1 ocf:heartbeat:IPaddr2 \
params ip=10.2.6.40 cidr_netmask=16 nic=ens160 \
op monitor interval=20s timeout=20s \
op start interval=0s timeout=20s \
op stop interval=0s timeout=20s
添加依赖资源启动顺序
order o_exportfs_dir1-before-p_virtip_dir1 \
inf: p_exportfs_dir1 p_virtip_dir1
托管服务配置
colocation c_virtip_dir1-with-exportfs-dir1 \
inf: p_virtip_dir1 p_exportfs_dir1
验证
verify
提交
commit
退出
exit集群验证
pcs WEB UI https://10.2.6.41:2224
在客户端设备上验证
1 | 查看nfs挂载目录 |
引用
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 编程私厨!