NFS安装分为服务端和客户端,服务端和客户端都需要安装RPC和NFS服务,centos5之前RPC服务对应的安装包为portmap,centos6之后RPC服务对应软件包rpcbind,NFS服务对应软件包为nfs-utils。
安装操作步骤如下:
【服务端lab236】
1、查看系统版本
[[email protected] ~]# cat /etc/centos-release
CentOS Linux release 7.4.1708 (Core)2、查看是否已经安装RPC和NFS
[[email protected] ~]# rpm -qa |grep rpcbind
[[email protected] ~]# rpm -qa |grep nfs-utils3、安装RPC和NFS
[[email protected] ~]# 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 完毕!注意:出现上述结果,表示安装成功4、启动RPC和NFS服务
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# systemctl start rpcbind.service5、设置开机启动
[[email protected] ~]# systemctl enable rpcbind.service
[[email protected] ~]# systemctl enable nfs6、检查RPC和NFS服务是否启动
[[email protected] ~]# systemctl status rpcbind
● rpcbind.service - RPC bind serviceLoaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)Active: active (running) since 一 2020-11-02 20:14:59 CST; 2min 28s agoMain PID: 20833 (rpcbind)CGroup: /system.slice/rpcbind.service└─20833 /sbin/rpcbind -w11月 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.[[email protected] ~]# systemctl status nfs● nfs-server.service - NFS server and servicesLoaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)Drop-In: /run/systemd/generator/nfs-server.service.d└─order-with-mounts.confActive: active (exited) since 四 2020-10-29 20:56:49 CST; 3 days agoMain PID: 98208 (code=exited, status=0/SUCCESS)CGroup: /system.slice/nfs-server.serviceWarning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
7、创建挂载目录
[[email protected] ~]# mkdir -p /nfs/dir #目录根据自己需求自行创建
8、配置NFS服务对应的exports文件
配置之前先介绍一下配置文件常用参数,此处很重要!!!参数的作用是针对挂载目录的安全权限
ro:只读rw:读写sync:数据缓存实时同步硬盘中async:数据先写入缓存,有必要时在写入磁盘all_squash:远程访问用户自动映射成默认用户或者用户组,默认是nfsnobodyno_all_squash:远程用户访问不自动映射成默认用户或者用户组root_squash:将root用户映射成默认的用户或者用户组no_root_squash:不将root用户映射成默认用户或者用户组anonuid=num:将远程用户映射成指定的用户,此处指定用户uidanongid=num:将远程用户组映射成指定用户组,此处指定用户组gid此时编辑/etc/exports[[email protected] ~]# vim /etc/exports#config start/nfs/dir 192.168.80.0/24(rw,sync,all_squash)#end第一字段:/nfs/dir服务端挂载目录第二字段:指定远程访问网段以及对应挂载目录访问操作权限9、重新加载NFS配置文件
[[email protected] ~]# exportfs -rv
exporting 192.168.80.0/24:/nfs/direxportfs命令参数介绍-r:重新加载NFS配置文件-v:显示NFS配置-a:将配置文件中所有的配置发布出来-u:不发布配置10、查看服务端NFS挂载情况
[[email protected] ~]# showmount -e localhost
Export list for localhost:/nfs/dir 192.168.80.0/2411、改变挂载目录属主和属组为默认用户、用户组
[[email protected] ~]# chown -R nfsnobody.nfsnobody /nfs/dir/
12、创建测试文件
[[email protected] ~]# touch /nfs/dir/test.txt
【客户端lab235】
1、安装RPC和NFS
[[email protected] ~]# yum -y install rpcbind nfs-utils
2、启动RPC和NFS服务,并设置开机启动
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl enable rpcbind[[email protected] ~]# systemctl start nfs[[email protected] ~]# systemctl enable nfs3、创建挂载服务端目录
[[email protected] ~]# mkdir /nfsclient
4、测试查看NFS服务端挂载配置情况
[[email protected] ~]# showmount -e 192.168.80.236
Export list for 192.168.80.236:/nfs/dir 192.168.80.0/245、挂载服务端目录
[[email protected] ~]# mount -t nfs 192.168.80.236:/nfs/dir /nfsclinet/
6、检查测试挂载目录工作是否正常
[[email protected] ~]# ls /nfsclinet/
test.txt #可以看到服务端创建的测试文件[[email protected] nfsclinet]# touch client.txt #在客户端挂载目录创建文件成功!总结:至此NFS安装全部完成!!!
精彩评论