NFS实战指南:两台机器模拟nfs挂载
NFS(Network File System)是一种允许网络中不同计算机系统共享文件的协议。它允许客户端通过网络透明地读写服务器上的文件,就像访问本地文件一样。NFS基于RPC(Remote Procedure Call)协议工作,RPC负责将NFS的功能映射到对应的端口号,以便客户端可以连接到正确的端口进行数据传输。FS服务器监听2049端口,但也可能随机使用小于1024的端口,这些端口通过RPC服务进行注册和管理。分别通过两台机器实现nfs挂载
服务端:192.168.150.10
客户端:192.168.150.11
nfs服务端
第一步: 下载nfs-utils,rpcbind
yum install nfs-utils rpcbind -y
创建文件
touch /nfs-test/test.txt
echo dsfsd >> /nfs-test/test.txt
chmod -R 741 /nfs-test/
注意用户和用户组设置,默认是root:root,如果客户端挂载该文件夹可能会显示权限不够
chown -R nfsnobody:nfsnobody /nfs-test/
修改配置文件进行挂载授权
[root@mari ~]# cat /etc/exports
/nfs-test *(insecure,rw,sync,no_root_squash)****
insecure 允许客户端在大于1024的端口访问
sync是指数据同时写入磁盘和内存,在高并发的场景不用使用
no_root_squash 使root用户不被映射为匿名用户
查看本地共享了哪些文件夹
[root@mari ~]# showmount -e 127.0.0.1
Export list for 127.0.0.1:
/nfs-test *
[root@mari ~]# cat /var/lib/nfs/etab
/nfs-test*(rw,sync,wdelay,hide,nocrossmnt,insecure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,insecure,root_squash,no_all_squash)
用本机测试挂载情况
mount -t nfs 127.0.0.1:/nfs-test /mnt
断开挂载
umount /mnt
nfs 客户端
yum install nfs-utils rpcbind -y
客户端需要访问服务端的数据,是通过自己的rpc工具访问服务端的rpc工具。因此,同样需要下载rpcbind
查看网络文件夹
[root@localhost ~]# showmount -e 192.168.150.10
Export list for 192.168.150.10:
/nfs-test *
挂载
[root@localhost ~]# mkdir /test2
[root@localhost ~]# mount -t nfs 192.168.150.10:/nfs-test /test2
[root@localhost ~]# mount -l | tail -1
192.168.150.10:/nfs-test on /test2 type nfs4 (rw,relatime,vers=4.1,rsize=524288,wsize=524288,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.150.11,local_lock=none,addr=192.168.150.10)
nfs自动挂载
在客户端添加:
vim /etc/fstab
添加
192.168.150.10:/nfs-test /test2 nfs defaults 0 0
注意:
当前在共享目录中,后者正在使用共享目录中的文件时,无法进行umount操作
如果本地目录有数据,挂载到网络的共享目录时,将只显示网络文件夹中的数据,本地不显示
注意添加no_root_squash,默认的是root_squash挂载后可能会显示权限不足
原文地址:https://blog.csdn.net/sozee910/article/details/142937094
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!