文件服务器 nfs

简介:

NAS之NFS

=====================================================================================

一、NFS服务器

1. 软件包 nfs-utils
2. 端口 2049/tcp
3. 配置文件 /etc/exports

[root@station02 ~]# mkdir -p /share/dir1 /share/dir2
[root@station02 ~]# chmod 777 /share/dir2
[root@station02 ~]# touch /share/dir1/1
[root@station02 ~]# touch /share/dir2/2

[root@station02 ~]# vim /etc/exports

/share/dir1             192.168.0.0/24(ro,sync)
/share/dir2             *(rw,sync)

4. 启动
[root@station02 ~]# service portmap start   #守护进程
[root@station02 ~]# service nfs restart
关闭 NFS mountd:                                      [失败]
关闭 NFS 守护进程:                                      [失败]
关闭 NFS quotas:                                       [失败]
启动 NFS 服务:                                          [确定]
关掉 NFS 配额:                                          [确定]
启动 NFS 守护进程:                                      [确定]
启动 NFS mountd:                                      [确定]

[root@station02 ~]# chkconfig nfs on
[root@station02 ~]# exportfs -r//reload
[root@station02 ~]# exportfs -v//显示当前输出的所有共享
[root@station02 ~]# ps aux |grep nfs
root      4156  0.0  0.0      0     0 ?        S<   20:29   0:00 [nfsd4]
root      4158  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4159  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4160  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4161  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4162  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4163  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4164  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4165  0.0  0.0      0     0 ?        S    20:29   0:00 [nfsd]
root      4314  0.0  0.2   5128   676 pts/1    R+   21:20   0:00 grep nfs

[root@station02 ~]# netstat -tnlp | grep :2049
tcp        0      0 0.0.0.0:2049        0.0.0.0:*           LISTEN      -
[root@station02 ~]# netstat -an |grep 2049
tcp        0      0 0.0.0.0:2049        0.0.0.0:*                   LISTEN      
tcp        0      0 192.168.0.2:2049    192.168.0.120:927           ESTABLISHED 
udp        0      0 0.0.0.0:2049        0.0.0.0:*     

====================================================================================

二、NFS客户端

[root@station11 ~]# showmount -e 192.168.0.2
Export list for 192.168.0.2:
/share/dir2 *
/share/dir1 192.168.0.0/24

[root@station11 ~]# mkdir /mnt/dir1 /mnt/dir2
[root@station11 ~]# mount -t nfs 192.168.0.2:/share/dir1 /mnt/dir1
[root@station11 ~]# mount -t nfs 192.168.0.2:/share/dir2 /mnt/dir2
[root@station11 ~]# ls /mnt/dir1
1
[root@station11 ~]# ls /mnt/dir2
2

wKioL1M3xsCDUFN0AAC7rPYsUHc682.jpg==================================================================

探究nfs挂载时权限的验证方式

服务器端:
=======

[root@station02 ~]# useradd alice
[root@station02 ~]# mkdir /share/dir3
[root@station02 ~]# chown alice.alice /share/dir3
[root@station02 ~]# id alice
uid=500(alice) gid=500(alice) groups=500(alice)
[root@station02 ~]# 
[root@station02 ~]# vim /etc/exports 
/share/dir1             192.168.0.0/24(ro,sync)
/share/dir2             *(rw,sync)
/share/dir3             *(rw,sync)//目录对于其他人没有写权限

[root@station02 ~]# exportfs -r
[root@station02 ~]# exportfs -v
/share/dir1     192.168.0.0/24(ro,wdelay,root_squash,no_subtree_check,anonuid=65534,anongid=65534)
/share/dir2     <world>(rw,wdelay,root_squash,no_subtree_check,anonuid=65534,anongid=65534)
/share/dir3     <world>(rw,wdelay,root_squash,no_subtree_check,anonuid=65534,anongid=65534)

wKiom1M3x0aT8vwtAAFqS2VbxvQ406.jpg从客户端测试:
===========

   首先以root用户挂载
[root@station11 ~]# mkdir /mnt/dir3
[root@station11 ~]# mount 192.168.0.2:/share/dir3 /mnt/dir3
[root@station11 ~]# touch /mnt/dir3/file1
touch: 无法触碰 “/mnt/dir3/file1”: 权限不够
[root@station11 ~]# useradd jack
[root@station11 ~]# id jack
uid=500(jack) gid=500(jack) groups=500(jack)

   以jack用户访问(普通用户是不能使用mount命令挂载任何文件系统)
[root@station11 ~]# su - jack
[jack@station11 ~]$ touch /mnt/dir3/file1

====
分析:
====
1. 对比服务端和客户端文件属性
[root@station02 ~]# ll -dn /share/dir3//服务器端
drwxr-xr-x 2 500 500 4096 10-02 20:45 /share/dir3

[root@station11 ~]# ll -dn /mnt/dir3//客户端
drwxr-xr-x 2 500 500 4096 2012-10-02 /mnt/dir3

====
结果:
====
NFS权限是通过UID、GID映射的 
从客户端如果使用root访问,将默认映射为nfsnobody(服务端在共享时使用了root_squash,服务端共享时添加参数no_root_squash可以让目录拥有写权限)

如果希望两端的UID和GID能够一样
1. useradd tom -u 2000
2. 使用LDAP服务器提供统一的UID和GID

================================================================================

再谈客户端挂载:

方法一: 
[root@station11 ~]# mount 192.168.0.2:/share/dir1 /mnt/dir1  //临时

方法二:  
vim /etc/fstab

192.168.0.2:/share/dir1 /mnt/dir1               nfs     ro              0 0
192.168.0.2:/share/dir2 /mnt/dir2               nfs     rw              0 0

[root@station11 ~]# mount -a

wKiom1M3yF3RLMtfAADbl_dx9p0705.jpg方法三:
automount (进程autofs)自动挂载,按需挂载

[root@station11 ~]# mkdir /mnt/nfs//准备一个父挂载点,即监控目录
[root@station11 ~]# vim /etc/auto.master 
/mnt/nfs /etc/auto.nfs
[root@station11 ~]# vim /etc/auto.nfs 
dir1            -ro             192.168.0.2:/share/dir1
dir2            -rw             192.168.0.2:/share/dir2
[root@station11 ~]# service autofs restart














本文转自zhang25yun51CTO博客,原文链接: http://blog.51cto.com/1585654/1386900,如需转载请自行联系原作者



相关文章
|
1月前
|
存储 Linux 网络安全
Linux系统安装NFS服务器
NFS是一种网络文件系统,英文全称Network File System,通过NFS可以让不同的主机系统之间共享文件或目录。通过NFS,用户可以直接在本地NFS客户端读写NFS服务端上的文件,是非常好的共享存储工具。本篇文章将介绍如何在CentOS7上安装NFS服务器,包括服务端和客户端安装两部分。
88 0
|
1月前
|
存储 Linux 网络安全
借PVE8.0的Debian 12系统配置一下NFS服务器
借PVE8.0的Debian 12系统配置一下NFS服务器
|
1月前
|
存储 Linux 虚拟化
CentOS 7搭建NFS服务器
CentOS 7搭建NFS服务器
|
1月前
|
网络协议 Unix Linux
Centos下nfs+rpcbind实现服务器之间的文件共享
Centos下nfs+rpcbind实现服务器之间的文件共享
137 0
|
4天前
|
存储 负载均衡 网络协议
杨老师课堂之JavaWeb项目架构之NFS文件服务器
杨老师课堂之JavaWeb项目架构之NFS文件服务器
16 0
|
1月前
|
Unix
|
10月前
|
存储 网络协议 Linux
Linux/centos上如何配置管理NFS服务器?
Linux/centos上如何配置管理NFS服务器?
209 0
|
1月前
|
存储 安全 Linux
百度搜索:蓝易云【nfs服务器的描述,搭建和使用】
注意:在生产环境中,需要根据实际需求进行更严格的安全配置,例如使用ACL(访问控制列表)或防火墙规则来控制访问权限。
123 0
|
10月前
|
Ubuntu
百度搜索:蓝易云【Ubuntu最新版本(Ubuntu22.04LTS)安装nfs服务器】
NFS(Network File System)是一种允许不同计算机之间共享文件的网络文件系统。
167 0
|
10月前
|
域名解析 网络协议 Unix
NFS服务器详解
NFS服务器详解
1197 0