目录
1 NFS介绍
1.1 NFS架构概述
1.2 组成部分
1.3 工作流程
1.4 总结
2 NFS部署
2.1 server(服务端)配置详细方法
2.2 client(客户端)配置详细方法
NFS架构主要由三部分组成:NFS服务器、客户端和传输协议。
这些组件共同工作,实现文件在网络中的共享和访问。
/etc/exports
,在此文件中可以定义NFS系统的输出目录(即共享目录)、访问权限和允许访问的主机等参数。NFS架构通过NFS服务器、客户端和传输协议(主要是TCP/IP和RPC)的紧密协作,实现了文件在网络中的高效共享和访问。这种架构不仅提高了数据访问的灵活性和便捷性,还通过RPC协议确保了数据传输的可靠性和安全性。在实际应用中,NFS广泛应用于Unix/Linux系统之间的文件共享,特别是在需要高性能文件访问的场景中。
[root@rehel9 ~]# cat /etc/yum.repos.d/rhel9.repo [rhel9_AppStream] name=AppStream baseurl=file:///opt/iso/AppStream gpgcheck=1 gpgkey=file:///opt/iso/RPM-GPG-KEY-redhat-release [rhel9_BaseOS] name=BaseOS baseurl=file:///opt/iso/BaseOS gpgcheck=1 gpgkey=file:///opt/iso/RPM-GPG-KEY-redhat-release [root@rehel9 ~]# ls /opt/iso/ AppStream BaseOS RPM-GPG-KEY-redhat-beta RPM-GPG-KEY-redhat-release
[root@rehel9 ~]# dnf clean all && dnf makecache 正在更新 Subscription Management 软件仓库。 12 文件已删除 AppStream 239 MB/s | 5.8 MB 00:00 BaseOS 227 MB/s | 1.7 MB 00:00 元数据缓存已建立。
[root@rehel9 ~]# dnf search nfs 正在更新 Subscription Management 软件仓库。 上次元数据过期检查:0:02:34 前,执行于 2024年07月01日 星期一 15时26分58秒。 ===================================================== 名称 和 概况 匹配:nfs ====================================================== libnfsidmap.i686 : NFSv4 User and Group ID Mapping Library libnfsidmap.x86_64 : NFSv4 User and Group ID Mapping Library libstoragemgmt-nfs-plugin.x86_64 : Files for NFS local filesystem support for libstoragemgmt nfs-utils.x86_64 : NFS utilities and supporting clients and daemons for the kernel NFS server nfs-utils-coreos.x86_64 : Minimal NFS utilities for supporting clients nfs4-acl-tools.x86_64 : The nfs4 ACL tools pcp-pmda-nfsclient.x86_64 : Performance Co-Pilot (PCP) metrics for NFS Clients sssd-nfs-idmap.x86_64 : SSSD plug-in for NFSv4 rpc.idmapd ========================================================= 名称 匹配:nfs ========================================================== texlive-mfnfss.noarch : Packages to typeset oldgerman and pandora fonts in LaTeX texlive-psnfss.noarch : Font support for common PostScript fonts
[root@rehel9 ~]# dnf install nfs-utils.x86_64 -y [root@rehel9 ~]# rpm -qa | grep nfs libnfsidmap-2.5.4-10.el9.x86_64 nfs-utils-2.5.4-10.el9.x86_64 sssd-nfs-idmap-2.6.2-2.el9.x86_64
[root@rehel9 ~]# cat >> /etc/exports << EOF > /media *(rw) > /rehel 192.168.210.0/24(rw) > EOF [root@rehel9 ~]# chmod 777 /media/ [root@rehel9 ~]# chmod 777 /rehel/
[root@rehel9 ~]# systemctl list-unit-files | grep nfs proc-fs-nfsd.mount static - var-lib-nfs-rpc_pipefs.mount static - nfs-blkmap.service disabled disabled nfs-idmapd.service static - nfs-mountd.service static - nfs-server.service disabled disabled nfs-utils.service static - nfsdcld.service static - nfs-client.target enabled disabled [root@rehel9 ~]# systemctl enable nfs-server.service --now Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service. [root@rehel9 ~]# systemctl list-unit-files | grep nfs proc-fs-nfsd.mount static - var-lib-nfs-rpc_pipefs.mount static - nfs-blkmap.service disabled disabled nfs-idmapd.service static - nfs-mountd.service static - nfs-server.service enabled disabled nfs-utils.service static - nfsdcld.service static - nfs-client.target enabled disabled
[root@rehel9 ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens160 sources: services: cockpit dhcpv6-client ssh ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@rehel9 ~]# rpcinfo -p | grep nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 3 tcp 2049 nfs_acl [root@rehel9 ~]# firewall-cmd --permanent --add-service=nfs success [root@rehel9 ~]# firewall-cmd --permanent --add-port=2049/tcp success [root@rehel9 ~]# firewall-cmd --permanent --add-source=192.168.210.0/24 success [root@rehel9 ~]# firewall-cmd --reload success [root@rehel9 ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens160 sources: 192.168.210.0/24 services: cockpit dhcpv6-client nfs ssh ports: 2049/tcp protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@rehel9 ~]# setenforce 0 [root@rehel9 ~]# getenforce Permissive
[root@locahost ~]# dnf update -y [root@locahost ~]# yum install nfs-utils.x86_64 -y [root@locahost ~]# rpm -qa | grep nfs libnfsidmap-2.5.4-25.el9.x86_64 nfs-utils-2.5.4-25.el9.x86_64 sssd-nfs-idmap-2.9.4-6.el9_4.x86_64
[root@locahost ~]# systemctl list-unit-files --type=service | grep nfs nfs-blkmap.service disabled disabled nfs-idmapd.service static - nfs-mountd.service static - nfs-server.service disabled disabled nfs-utils.service static - nfsdcld.service static - [root@locahost ~]# systemctl enable nfs-server.service --now Created symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service → /usr/lib/systemd/system/nfs-server.service. [root@locahost ~]# systemctl list-unit-files --type=service | grep nfs nfs-blkmap.service disabled disabled nfs-idmapd.service static - nfs-mountd.service static - nfs-server.service enabled disabled nfs-utils.service static - nfsdcld.service static -
[root@locahost ~]# rpcinfo -p | grep nfs 100003 3 tcp 2049 nfs 100003 4 tcp 2049 nfs 100227 3 tcp 2049 nfs_acl [root@locahost ~]# firewall-cmd --permanent --add-service=nfs success [root@locahost ~]# firewall-cmd --permanent --add-port=2049/tcp success [root@locahost ~]# firewall-cmd --permanent --add-source=192.168.210.0/24 success [root@locahost ~]# firewall-cmd --reload success [root@locahost ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens160 sources: 192.168.210.0/24 services: cockpit dhcpv6-client nfs ssh ports: 2049/tcp protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
[root@locahost ~]# mount 192.168.210.129:/media /mnt [root@locahost ~]# mount 192.168.210.129:/rehel /media
[root@locahost ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 3.8G 0 3.8G 0% /dev tmpfs tmpfs 3.8G 0 3.8G 0% /dev/shm tmpfs tmpfs 1.5G 9.7M 1.5G 1% /run /dev/sda4 xfs 96G 13G 83G 14% / /dev/sda2 xfs 495M 238M 258M 48% /boot /dev/sda1 vfat 200M 7.0M 193M 4% /boot/efi tmpfs tmpfs 766M 104K 766M 1% /run/user/0 192.168.210.134:/rhome/alice nfs4 96G 13G 83G 14% /home/alice
#cliten(客户端) [root@locahost ~]# mkdir /{mnt/txt,media/txt} [root@locahost ~]# touch /{mnt/txt/abc_1.txt,media/txt/abc_2.txt} [root@locahost ~]# ls /{mnt/txt/,media/txt} /media/txt: abc_2.txt /mnt/txt/: abc_1.txt #service(服务端) [root@rehel9 ~]# ls /{rehel,media} /media: txt /rehel: txt