NFS安装分为服务端和客户端,服务端和客户端都需要安装RPC和NFS服务,centos5之前RPC服务对应的安装包为portmap,centos6之后RPC服务对应软件包rpcbind,NFS服务对应软件包为nfs-utils。
安装操作步骤如下:
[root@lab-236 ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)
[root@lab-236 ~]# rpm -qa |grep rpcbind
[root@lab-236 ~]# rpm -qa |grep nfs-utils
[root@lab-236 ~]# yum -y install rpcbind nfs-utils.x86_64
《此处省略过程》
已安装:
nfs-utils.x86_64 1:1.3.0-0.66.el7_8 rpcbind.x86_64 0:0.2.0-49.el7
作为依赖被安装:
quota.x86_64 1:4.01-19.el7
作为依赖被升级:
quota-nls.noarch 1:4.01-19.el7
完毕!
注意:出现上述结果,表示安装成功
[root@lab-236 ~]# systemctl start nfs
[root@lab-236 ~]# systemctl start rpcbind.service
[root@lab-236 ~]# systemctl enable rpcbind.service
[root@lab-236 ~]# systemctl enable nfs
[root@lab-236 ~]# systemctl status rpcbind
● rpcbind.service - RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2020-11-02 20:14:59 CST; 2min 28s ago
Main PID: 20833 (rpcbind)
CGroup: /system.slice/rpcbind.service
└─20833 /sbin/rpcbind -w
11月 02 20:14:59 lab-236.com systemd[1]: Starting RPC bind service...
11月 02 20:14:59 lab-236.com systemd[1]: Started RPC bind service.
[root@lab-236 ~]# systemctl status nfs
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
Drop-In: /run/systemd/generator/nfs-server.service.d
└─order-with-mounts.conf
Active: active (exited) since 四 2020-10-29 20:56:49 CST; 3 days ago
Main PID: 98208 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
[root@lab-236 ~]# mkdir -p /nfs/dir #目录根据自己需求自行创建
配置之前先介绍一下配置文件常用参数,此处很重要!!!参数的作用是针对挂载目录的安全权限
ro:只读
rw:读写
sync:数据缓存实时同步硬盘中
async:数据先写入缓存,有必要时在写入磁盘
all_squash:远程访问用户自动映射成默认用户或者用户组,默认是nfsnobody
no_all_squash:远程用户访问不自动映射成默认用户或者用户组
root_squash:将root用户映射成默认的用户或者用户组
no_root_squash:不将root用户映射成默认用户或者用户组
anonuid=num:将远程用户映射成指定的用户,此处指定用户uid
anongid=num:将远程用户组映射成指定用户组,此处指定用户组gid
此时编辑/etc/exports
[root@lab-236 ~]# vim /etc/exports
#config start
/nfs/dir 192.168.80.0/24(rw,sync,all_squash)
#end
第一字段:/nfs/dir服务端挂载目录
第二字段:指定远程访问网段以及对应挂载目录访问操作权限
[root@lab-236 ~]# exportfs -rv
exporting 192.168.80.0/24:/nfs/dir
exportfs命令参数介绍
-r:重新加载NFS配置文件
-v:显示NFS配置
-a:将配置文件中所有的配置发布出来
-u:不发布配置
[root@lab-236 ~]# showmount -e localhost
Export list for localhost:
/nfs/dir 192.168.80.0/24
[root@lab-236 ~]# chown -R nfsnobody.nfsnobody /nfs/dir/
[root@lab-236 ~]# touch /nfs/dir/test.txt
[root@lab-235 ~]# yum -y install rpcbind nfs-utils
[root@lab-235 ~]# systemctl start rpcbind
[root@lab-235 ~]# systemctl enable rpcbind
[root@lab-235 ~]# systemctl start nfs
[root@lab-235 ~]# systemctl enable nfs
[root@lab-236 ~]# mkdir /nfsclient
[root@lab-235 ~]# showmount -e 192.168.80.236
Export list for 192.168.80.236:
/nfs/dir 192.168.80.0/24
[root@lab-235 ~]# mount -t nfs 192.168.80.236:/nfs/dir /nfsclinet/
[root@lab-235 ~]# ls /nfsclinet/
test.txt #可以看到服务端创建的测试文件
[root@lab-235 nfsclinet]# touch client.txt #在客户端挂载目录创建文件成功!
总结:至此NFS安装全部完成!!!
原文:https://blog.51cto.com/6461704/2551946