关于nfs的搭建

网友投稿 602 2022-05-29

nfs服务端

1、挂载我们需要分享的文件

例如:

[root@localhost /]# mkdir -t /nfs/default

[root@localhost /]#mount /dev/vdb /nfs/default/

[root@localhost /]#ll /nfs/code/

total 16

drwx------ 2 root root 16384 Oct 10 16:00 lost+found

[root@localhost /]#

[root@database1 /]# df -Th

Filesystem     Type      Size  Used Avail Use% Mounted on

devtmpfs       devtmpfs  1.9G     0  1.9G   0% /dev

tmpfs          tmpfs     1.9G     0  1.9G   0% /dev/shm

关于nfs的搭建

tmpfs          tmpfs     1.9G  8.6M  1.9G   1% /run

tmpfs          tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup

/dev/vda1      ext4       40G  2.2G   36G   6% /

tmpfs          tmpfs     379M     0  379M   0% /run/user/0

/dev/vdb       ext4      9.8G   37M  9.2G   1% /nfs/default

[root@localhost /]#touch yy.txt     ##创建一个txt文件查看是否具有读写权限

[root@localhost /]# ll

total 16

drwx------ 2 root root 16384 Oct 10 16:00 lost+found

rw-r--r-- 1 root root     0 Oct 10 16:10 yy.txt

[root@localhost /]#yum install nfs-utils rpcbind -y     #安装nfs-utils rpcbind

[root@localhost /]#systemctl restart rpcbind.service

[root@localhost /]#systemctl status rpcbind.service       #重启 并查看状态

[root@localhost /]#lsof -i :111 # netstat -lntup|grep rpcbind    #查看服务端口

[root@localhost /]# rpcinfo -p localhost

[root@localhost /]#systemctl start nfs.service

[root@localhost /]#systemctl start nfs.service

[root@localhost /]#systemctl enable rpcbind.service

[root@localhost /]#systemctl status nfs.service

[root@localhost /]#rpcinfo -p localhost

[root@localhost /]#ps -ef|egrep "rpc|nfs"

[root@localhost /]#systemctl enable rpcbind && systemctl enable nfs 2>&1      ##设置开机并自启

[root@localhost /]#cat /etc/exports

/nfs/default 192.168.0.107/16(rw,sync)     ##IP为nfs客户端

权限解读:

ro:默认选项,以只读的方式共享。

rw:以读写的方式共享。

root_squash:将客户端使用的是root用户时,则映射到NFS服务器的用户为NFS的匿名用户(nfsnobody)。

no_root_squash:将客户端使用的是root用户时,则映射到FNS服务器的用户依然为root用户。

all_squash:默认选项,将所有访问NFS服务器的客户端的用户都映射为匿名用户,不管客户端使用的是什么用户。

anonuid:设置映射到本地的匿名用户的UID

anongid:设置映射到本地的匿名用户的GID

sync:默认选项,保持数据同步,数据同步写入到内存和硬盘。

async:异步,先将数据写入到内存,在将数据写入到硬盘。

secure:NFS客户端必须使用NFS保留端口(通常是1024以下的端口),默认选项。

insecure:允许NFS客户端不使用NFS保留端口(通常是1024以上的端口)。

配置示例: 1、最简单,UID一一对应即可。 vim /etc/exports /mount/www 10.1.8.0/24(rw) ##共享/mount/www目录 给10.1.8.0网段机器。并且是读写的 ==================== useradd USER_NAME ##在NFS服务器上建立用户,和客户端建立的用户UID一样(必须) useradd USER_NAME ##在客户端机器上建立用户,和NFS服务器上建立的用户UID一样(必须) chown USER_NAME /mount/www ##NFS服务器上的共享目录改好 ==================== 如果还需要第二个用户,则再在客户端和NFS服务端机器上配对建立UID一样的用户。同时在NFS服务端对共享目录使用"setfacl -m u:USER_NAME2:rwx"增加第二个用户的权限即可。

参考:https://blog.csdn.net/donghaixiaolongwang/article/details/79230220

[root@localhost /]#service nfs reload

[root@localhost /]#chown nfsnobody.nfsnobody /nfs/default/

[root@localhost /]#exportfs -rv

[root@localhost /]#showmount -e localhost

[root@localhost /]#service nfs reload

Redirecting to /bin/systemctl reload nfs.service

[root@localhost /]#exportfs -rv

exporting 192.168.0.107/16:/nfs/code

[root@localhost /]#showmount -e localhost

Export list for localhost:

/nfs/code 192.168.0.107/16

nfs客户端

[root@localhost /]#mount -t nfs 172.16.0.41:/nfs/default /mnt/

[root@localhost /]#df -Th

Filesystem            Type      Size  Used Avail Use% Mounted on

devtmpfs              devtmpfs  1.9G     0  1.9G   0% /dev

tmpfs                 tmpfs     1.9G     0  1.9G   0% /dev/shm

tmpfs                 tmpfs     1.9G  8.6M  1.9G   1% /run

tmpfs                 tmpfs     1.9G     0  1.9G   0% /sys/fs/cgroup

/dev/vda1             ext4       40G  2.3G   35G   7% /

tmpfs                 tmpfs     379M     0  379M   0% /run/user/0

172.16.0.41:/nfs/code nfs4      9.8G   36M  9.2G   1% /mnt

参考1:https://blog.csdn.net/hdyebd/article/details/84547969

参考2: https://bbs.huaweicloud.com/blogs/244540

数据复制服务 DRS

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:海思移植opencv+车辆检测
下一篇:1024节使用应用魔方做个航天飞船控制台大屏丨【玩转应用魔方】
相关文章