NFS安装与配置

  • Post author:
  • Post category:NFS
  • Page Views 474 阅读

1.安装

服务端客户端都需安装,客户端无需启动nfs服务,但是需要启动rpc服务。

RPC:Romote Procedure Call

作用:NFS服务端需要向RPC服务注册通信端口,NFS客户端通过RPC服务获取NFS通信端口进行数据交互。

[root@Ansible ~]# yum install nfs-utils rpcbind -y   
[root@Ansible ~]# systemctl start rpcbind
[root@Ansible ~]# systemctl enable rpcbind
[root@Ansible ~]# systemctl start nfs                #启动nfs服务器之前需先启动rpc服务,否则nfs端口可能无法成功注册。
[root@Ansible ~]# systemctl enable nfs
[root@Ansible ~]# rpcinfo -p localhost #查看RPC服务端口注册情况。

2.配置NFS共享目录

配置文件/etc/exports

[root@Ansible ~]# echo "/nfsdata 192.168.244.0/24(rw,sync)" > /etc/exports
[root@Ansible ~]# mkdir -p /nfsdata
[root@Ansible ~]# chown -R nfsnobody.nfsnobody /nfsdata
[root@Ansible ~]# systemctl reload nfs #修改nfs配置文件无需重启服务,平滑加载即可。
[root@Ansible ~]# cat /var/lib/nfs/etab #查看nfs配置文件参数,包括默认加载的参数。
/nfsdata 192.168.244.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash...)
[root@Ansible ~]# showmount -e localhost #查看本地挂载情况。
Export list for localhost:
/nfsdata 192.168.244.0/24

3.挂载NFS目录

[root@Ansible ~]# mkdir -p /nfsdata/nfs01        #创建可挂载子目录
[root@Ansible ~]# ssh 192.168.244.157
Last login: Sun Mar 1 21:39:14 2020 from 192.168.244.1
[root@k8s-node-1 ~]# showmount -e 192.168.244.156 #查看nfs服务器可挂载目录
Export list for 192.168.244.156:
/nfsdata 192.168.244.0/24
[root@k8s-node-1 ~]# mount -t nfs 192.168.244.156:/nfsdata/nfs01 /mnt
[root@k8s-node-1 ~]# df -h |grep mnt
192.168.244.156:/nfsdata/nfs01 38G 1.4G 37G 4% /mnt
[root@k8s-node-1 ~]# touch /mnt/d.txt #验证结果
[root@k8s-node-1 ~]# ll /mnt/
-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 1 22:03 d.txt
[root@k8s-node-1 ~]# logout
Connection to 192.168.244.157 closed.
[root@Ansible ~]# ll /nfsdata/nfs01/
-rw-r--r--. 1 nfsnobody nfsnobody 0 Mar 1 22:03 d.txt
[root@k8s-node-1 ~]# cat /etc/fstab |grep nfs #设置开机自动挂载
192.168.244.156:/nfsdata/nfs01 /mnt nfs defaults,intr 0 0

intr挂载参数作用:
指定intr参数,当nfs server宕机时,nfs客户端会在超时后中断连接请求;否则会导致系统假死或者无法重启。
或者使用umount -lf强制取消挂载。


「 文章如果对你有帮助,请点个赞哦^^ 」 

1+