码迷,mamicode.com
首页 > 系统相关 > 详细

linux-NFS文件系统

时间:2017-12-12 10:31:14      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:nfs文件系统


NFS,网络文件系统。一个系统在网络上与他人共享目录和文件。通过使用NFS,用户和程序可以像访问本地

文件一样访问系统上的文件。
用途:共享文件
优点:节省磁盘空间
组成:一台服务器和一台或多台客户机


技术分享图片


(服务端)

[root@desktop ~]# yum install nfs-untils -y 安装服务
[root@desktop ~]# systemctl start nfs(共享) (不要重启服务,否则客户端会卡)

#注:端口111 ?
ss -antlupe | grep 111 查看111端口是否开放



加入以下三个服务

[root@desktop ~]# firewall-cmd --permanent --add-service=nfs

[root@desktop ~]# firewall-cmd --permanent --add-service=rpc-bind

[root@desktop ~]# firewall-cmd --permanent --add-service=mountd

记得:操作完,重新加载

[root@desktop ~]# firewall-cmd --reload
success


技术分享图片


以上都准备完成后,在服务端建立共享目录

[root@desktop ~]# mkdir /westos/nfs -p? 建立(共享)目录
[root@desktop ~]# vim /etc/exports? 编辑文件
[root@desktop ~]# cat /etc/exports
/westos/nfs? *(sync)? <----同步到客户端
[root@desktop ~]#
[root@desktop ~]# exportfs -rv 刷新
exporting *:/westos/nfs


技术分享图片


(客户端)

如下操作去发现服务器上的设备,及进行挂载

[root@client ~]# showmount -e 172.25.12.10 发现(服务器端)设备

Export list for 172.25.12.10:?? 看到10主机的设备
/westos/nfs *


技术分享图片


*)在客户端如下实现自动挂载、卸载

[root@client ~]# yum install autofs.x86_64 -y 安装服务 (自动挂在,卸载)

[root@client ~]# systemctl start autofs 开启服务(会自动生成/net目录

[root@client ~]# ls -ld /net? 查看权限
drwxr-xr-x 2 root root 0 Dec? 9 20:01 /net


[root@foundation19 ~]# rpm -qc autofs 可通这个命令查看配置文件


技术分享图片

[root@client nfs]# vim /etc/sysconfig/autofs? 编辑配置文件 (7.0)

注:vim /etc/autofs.conf?? 7.2 版本

技术分享图片

如上可更改挂载时间

[root@client nfs]# systemctl restart autofs.service? 重启服务

技术分享图片

如上图,若想改变挂载点位置,可如下操作。


*)cd /westos/(linux)/nfs 实现挂载在此目录下


(服务端)

[root@desktop ~]# vim /etc/exports? 编辑此文件
[root@desktop ~]# exportfs -rv
exporting *:/westos/linux/nfs
exportfs: Failed to stat /westos/linux/nfs: No such file or directory
[root@desktop ~]# mkdir -p /westos/linux/nfs 建立现在需要挂载的目录
[root@desktop ~]# exportfs -rv 刷新
exporting *:/westos/linux/nfs
[root@desktop ~]# rm -fr /westos/nfs 删除之前的


(客户端)

[root@client nfs]# vim /etc/auto.master? 编辑配置文件(最终挂在点的上层目录

技术分享图片



[root@client nfs]# vim /etc/auto.nfs 在指定的文件中写入挂载信息


技术分享图片


[root@client nfs]# systemctl restart autofs.service 重启服务


测试:

技术分享图片

[root@client nfs]# mount? 查看挂载信息


技术分享图片


*)使客户主机可写


(服务端)

[root@desktop ~]# vim /etc/exports? 编辑文件
[root@desktop ~]# cat /etc/exports (2‘)
/westos/nfs? *(sync,rw)? 加入权限rw
[root@desktop ~]# exportfs -rv? 刷新
exporting *:/westos/nfs

[root@desktop ~]# cd /westos/nfs/ 切到此目录
[root@desktop nfs]# ls -ld /westos/nfs/
drwxr-xr-x 2 root root 6 Dec? 9 07:45 /westos/nfs/ 其他人没有写的权限
[root@desktop nfs]# chmod 777 /westos/nfs/? 给权限
[root@desktop nfs]# ls -ld /westos/nfs/
drwxrwxrwx 2 root root 6 Dec? 9 07:45 /westos/nfs/ 其他人有写的权限


技术分享图片


技术分享图片


*)指定身份创建文件

[root@desktop nfs]# vim /etc/exports

[root@desktop nfs]# exportfs -rv
exporting *:/westos/nfs
[root@desktop nfs]# cat /etc/exports
/westos/nfs? *(sync,rw,anonuid=1001,anongid=1001) 指定身份创建文件
表示客户端新建文件属于指定组和用户

技术分享图片


若上面指定的id与用户一直,则所建立文件属于该用户。

技术分享图片

*)超户身份写入

[root@desktop nfs]# vim /etc/exports


技术分享图片[root@desktop nfs]# exportfs -rv
exporting *:/westos/nfs
[root@desktop nfs]# cat /etc/exports
/westos/nfs? *(sync,rw,anonuid=1001,anongid=1001,no_root_squash)? 超户身份(不做转换)表示客户端以ROOT用户身份使用设备新建文件,文件属于root

技术分享图片



linux-NFS文件系统

标签:nfs文件系统

原文地址:http://blog.51cto.com/13362895/2049608

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!