添加NFS(Centos7)

发布时间 2023-08-15 15:32:46作者: hello罗

在Rancher中,我们需要映射磁盘值docker中,因此我们需要将磁盘路径挂载到docker内,但由于有多个服务器,我们需要指定存储某一台服务器内,这时候我们需要共享文件夹,来访问响应文件。因此我们这边引入了NFS

1.环境准备

  1.1 准备2台服务器

    A:172.16.169.220 作为服务器

    B:172.16.169.221 作为客户端

2.在A服务端机器安装nfs-utils和rpcbind包,nfs-utils:提供了NFS服务器程序和对应的管理工具 rpcbind:获取nfs服务器端的端口等信息

yum install -y nfs-utils rpcbind

3.启动rpcbind检查是否启动了rpcbind服务并监听111端口

systemctl start rpcbind
netstat -tunlp | grep 111

4.创建/data/nfsdata目录

mkdir -p /data/nfsdata 

5.配置NFS服务的配置文件,参数配置:vi /etc/exports

/data/nfsdata *(rw,sync,no_root_squash)

 6.启动nfs服务

systemctl start nfs

7.设置开机启动

systemctl enable rpcbind.service
systemctl enable nfs.service

8.在B客户端机器安装nfs-utils包

yum -y install nfs-utils

9.设置开机启动

systemctl enable rpcbind.service    #客户端不用启动nfs-server,但是要用到nfs-server的一个命令showmount

10.挂载

mkdir /nfs
mount
-t nfs 172.16.169.220:/data/nfsdata /nfs #挂在文件系统 showmount -e 172.16.169.220 #查看是否挂载上