一、NFS介绍
1.NFS简介
NFS:网络文件系统,由Sun公司开发,通过网络,NFS支持在不同的文件系统之间共享文件.用户不必关心计算机的型号,是由Linux、unix及类似操作系统之间使用的互联网标准协议,可作为他们的本地网络文件系统。
2.NFS特点
①节约使用的磁盘空间:客户端经常使用的数据可以集中存放在一台机器上,并使用NFS发布,那么网络内部所有计算机可以通过网络访问,不必单独存储.
②节约硬件资源:NFS还可以共享软驱,CDROM和ZIP等的存储设备,减少整个网络上的可移动设备的数量.
③用户主目录设定
对于特殊用户,如管理员等,为了管理的需要,可能会经常登录到网络中所有的计算机,若每个客户端,均保存这个用户的主目录很繁琐,而且不能保证数据的一致性.实际上,经过NFS服务的设定,然后在客户端指定这个用户的主目录位置,并自动挂载,就可以在任何计算机上使用用户主目录的文件.
二、环境介绍
操作系统为RHEL8.0
服务端:control ————192.168.200.150
客户端:node1————192.168.200.135
三、服务端配置
1.创建共享目录
[root@control ~]# mkdir -p /share/data
[root@control ~]# ll -ld /share/data/
drwxr-xr-x 2 root root 6 Jul 15 21:31 /share/data/
2.检查NFS包是否安装
root@control ~]# yum list installed |grep nfs
libnfsidmap.x86_64 1:2.3.3-14.el8 @anaconda
nfs-utils.x86_64 1:2.3.3-14.el8 @anaconda
sssd-nfs-idmap.x86_64 2.0.0-43.el8 @anaconda
3.安装nfs相关包
yum install nfs-utils rpcbind -y
4.编辑配置文件
[root@control ~]# vim /etc/exports
[root@control ~]# cat /etc/exports
/share/data 192.168.200.0/24(rw)
5.重启服务且放行防火墙
[root@control ~]# systemctl restart nfs-server
[root@control ~]# firewall-cmd --permanent --add-service=mountd
success
[root@control ~]# firewall-cmd --permanent --add-service=nfs
success
[root@control ~]# firewall-cmd --permanent --add-service=rpc-bind
success
[root@control ~]# firewall-cmd --reload
success
[root@control ~]#
四、客户端配置
1.检查服务端共享目录是否存在
[root@control ~]# showmount -e 192.168.200.150
Export list for 192.168.200.150:
/share/data 192.168.200.0/24
2.安装自动挂载程序
[root@node1 ~]# yum -y install autofs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
AppStream 3.1 MB/s | 3.2 kB 00:00
BaseOS 2.7 MB/s | 2.7 kB 00:00
ansiable 0.0 B/s | 0 B 00:00
Zabbix 330 B/s | 2.9 kB 00:09
Zabbix 493 kB/s | 152 kB 00:00
Failed to synchronize cache for repo 'ansiable', ignoring this repo.
Dependencies resolved.
===============================================================================================================================================
Package Arch Version Repository Size
===============================================================================================================================================
Installing:
autofs x86_64 1:5.1.4-29.el8 BaseOS 755 k
Transaction Summary
===============================================================================================================================================
Install 1 Package
Total size: 755 k
Installed size: 3.5 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : autofs-1:5.1.4-29.el8.x86_64 1/1
Running scriptlet: autofs-1:5.1.4-29.el8.x86_64 1/1
Verifying : autofs-1:5.1.4-29.el8.x86_64 1/1
Installed products updated.
Installed:
autofs-1:5.1.4-29.el8.x86_64
Complete!
2.启动服务
[root@node1 ~]# systemctl enable --now autofs
Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.
3.编辑配置文件
[root@node1 ~]# grep -E -v '^#|^$' /etc/auto.master
/misc /etc/auto.misc
/share /etc/auto.nfs
/net -hosts
+dir:/etc/auto.master.d
+auto.master
[root@node1 ~]# vim /etc/auto.nfs
[root@node1 ~]# cat /etc/auto.nfs
dpt -rw 192.168.200.150:/share/data
[root@node1 ~]#
五、检查测试
[root@node1 ~]# cd /share
[root@node1 share]# cd dpt
[root@node1 dpt]#
[root@node1 dpt]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 970M 0 970M 0% /dev
tmpfs 984M 0 984M 0% /dev/shm
tmpfs 984M 22M 962M 3% /run
tmpfs 984M 0 984M 0% /sys/fs/cgroup
/dev/nvme0n1p3 18G 4.6G 13G 27% /
/dev/nvme0n1p1 495M 140M 356M 29% /boot
//192.168.200.150/share 13G 8.5G 4.1G 68% /media
tmpfs 197M 4.0K 197M 1% /run/user/0
/dev/sr0 6.7G 6.7G 0 100% /mnt/cdrom
192.168.200.150:/share/data 13G 8.5G 4.1G 68% /share/dpt