NFS概念:
网络文件系统(NFS)是Unix系统和网络附加存储文件管理器常用的网络文件系统,
允许多个客户端通过网络共享文件访问。它可用于提供对共享二进制目录的访问,
也可用于允许用户在同一工作组中从不同客户端访问其文件NFS协议有多个版本
:Linux支持版本4,版本3和版本2,而大多数系统管理员熟悉的是NFSv3。默认
情况下,该协议并不安全,但是更新的版本(如 NFSv4)提供了对更安全的身份验
证 , 甚至可以通过kerberos进行加密。
NFS的常规配置:
服务端:
[root@server ~]
[root@server mnt]
file1 file2 file3 file4 file5
[root@server mnt]
[root@server mnt]
[root@server mnt]
[root@server mnt]
[root@server mnt]
/mnt *(sync,ro) 可远程传输只读
[root@server mnt]
exporting *:/mnt
客户端:
[root@client ~]
[root@client ~]
Export list for 172.25.254.221:
/mnt *
[root@client ~]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3182744 7291156 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12756 472176 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
//172.25.254.221/DIR 10473900 3157836 7316064 31% /mnt
[root@client ~]
[root@client ~]
[root@client ~]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3182744 7291156 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12760 472172 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
172.25.254.221:/mnt 10473984 3157760 7316224 31% /mnt
[root@client ~]
[root@client mnt]
rm: cannot remove ‘file1’: Read-only file system
rm: cannot remove ‘file2’: Read-only file system
rm: cannot remove ‘file3’: Read-only file system
rm: cannot remove ‘file4’: Read-only file system
rm: cannot remove ‘file5’: Read-only file system
服务端设置可写:
[root@server mnt]
/mnt *(sync,rw) 可远程传输可写
[root@server mnt]
exporting *:/mnt
客户端进行测试:
虽然为可写但是服务端没有赋予权限不可删除,建立文件。
[root@client mnt]
[root@client ~]
[root@client ~]
[root@client ~]
[root@client mnt]
file1 file2 file3 file4 file5
[root@client mnt]
rm: cannot remove ‘file1’: Permission denied
rm: cannot remove ‘file2’: Permission denied
rm: cannot remove ‘file3’: Permission denied
rm: cannot remove ‘file4’: Permission denied
rm: cannot remove ‘file5’: Permission denied
服务端赋予权限:
[root@server mnt]
客户端测试建立文件会自动转换用户组:
[ ]
[ ]
[ ] ...
[ ]
[ ]
[ ]
------
------
------
------
------
------
------
服务端开启不转换用户组:
[root@server mnt]
[root@server mnt]
/mnt *(sync,rw,no_root_squash) 不转换用户身份,也即建立文件的用户和组直接为root
[root@server mnt]
exporting *:/mnt
客户端进行测试:
[ ]
[ ]
[ ] ...
[ ]
[ ]
[ ]
------
------
------
------
------
------
------
------
服务端默认用户组:
[root@server mnt]
/mnt *(sync,rw,anonuid=1000,anongid=1000)
[root@server mnt]
exporting *:/mnt
客户端进行测试:
[root@client mnt]
[root@client ~]
[root@client ~]
[root@client ~]
[root@client mnt]
[root@client mnt]
[root@client mnt]
total 0
-rw-r--r-- 1 student student 0 Jun 2 04:42 file1
服务端共享网段:
[root@server mnt]
[root@server mnt]
/mnt *(sync,rw,anonuid=1000,anongid=1000)
/westos 172.25.254.0/24(sync) 172.25.254.21(sync,rw)
[root@server mnt]
exporting 172.25.254.121:/westos
exporting 172.25.254.0/24:/westos
exporting *:/mnt
[root@server mnt]
客户端(此处为真机测试,写入的是真机IP)
[root@foundation84 ~]
[root@foundation84 ~]
[root@foundation84 mnt]
aa fil file file2 xfl
[root@foundation84 mnt]
touch: cannot touch ‘xyy’: Permission denied
[root@foundation84 mnt]
[root@foundation84 mnt]
total 0
-rw-r
-rw-r
-rw-r
-rw-r
-rw-r
-rw-r
autofs自动挂载服务:
autofs可自动挂载卸载文件系统,不会一直闲置占用后台:
在服务端:
[root@server ~]
[root@server ~]
在客户端:
[root@client ~]
[root@client ~]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3181552 7292348 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12756 472176 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
[root@client ~]
[root@client ~]
-bash: cd: /net: No such file or directory
[root@client ~]
[root@client ~]
[root@client net]
[root@client net]
[root@client 172.25.254.221]
/net/172.25.254.221
[root@client 172.25.254.221]
mnt westos
[root@client 172.25.254.221]
[root@client westos]
aa bb fil file file2 file3 xfl
[root@client westos]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187188 7286712 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12764 472168 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
172.25.254.221:/westos 10473984 3156480 7317504 31% /net/172.25.254.221/westos
[root@client westos]
[root@client ~]
/root
默认时间延迟:
[root@client ~]
TIMEOUT=5改为5秒,时间到了会自动卸载
[root@client ~]# systemctl restart autofs.service 重启服务
[root@client ~]# df挂载自动卸载
Filesystem 1K-blocks Used Available Use
/dev/vda1 10473900 3187208 7286692 31
devtmpfs 469344 0 469344 0
tmpfs 484932 80 484852 1
tmpfs 484932 12764 472168 3
tmpfs 484932 0 484932 0
/dev/mapper/vg0-vo 483670 2355 451824 1
设定nfs挂载目录:
[root@client ~]# df 查看挂载
Filesystem 1K-blocks Used Available Use
/dev/vda1 10473900 3187192 7286708 31
devtmpfs 469344 0 469344 0
tmpfs 484932 80 484852 1
tmpfs 484932 12768 472164 3
tmpfs 484932 0 484932 0
/dev/mapper/vg0-vo 483670 2355 451824 1
[root@client ~]# cd /net/172.25.254.221进入共享IP
[root@client 172.25.254.221]# ls
mnt westos
[root@client 172.25.254.221]# cd westos/ 进入共享目录
[root@client westos]# df 已经挂载成功,但是挂载点为默认
Filesystem 1K-blocks Used Available Use
/dev/vda1 10473900 3187192 7286708 31
devtmpfs 469344 0 469344 0
tmpfs 484932 80 484852 1
tmpfs 484932 12768 472164 3
tmpfs 484932 0 484932 0
/dev/mapper/vg0-vo 483670 2355 451824 1
172.25.254.221:/westos 10473984 3156480 7317504 31
[root@client westos]# cd 自动挂载卸载必须将路径切换出来
[root@client ~]# df 查看挂载消失
Filesystem 1K-blocks Used Available Use
/dev/vda1 10473900 3187192 7286708 31
devtmpfs 469344 0 469344 0
tmpfs 484932 80 484852 1
tmpfs 484932 12768 472164 3
tmpfs 484932 0 484932 0
/dev/mapper/vg0-vo 483670 2355 451824 1
[root@client ~]# vim /etc/auto.master 编辑主文件
主文件写入最终挂载点的上层目录:14 /nfs /etc/auto.westos
[root@client ~]
字策略文件内容:写入最终挂载点,挂载参数,真实的网络文件系统
[root@client ~]
westos -ro 172.25.254.221:/westos
[root@client ~]
[root@client ~]
[root@client nfs]
[root@client nfs]
[root@client westos]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187212 7286688 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12768 472164 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
172.25.254.221:/westos 10473984 3156480 7317504 31% /nfs/westos
[root@client westos]
[root@client westos]
[root@client westos]
westos -rw,vers=3 172.25.254.221:/westos
[root@client westos]
[root@client ~]
[root@client ~]
[root@client nfs]
[root@client westos]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 3187192 7286708 31% /
devtmpfs 469344 0 469344 0% /dev
tmpfs 484932 80 484852 1% /dev/shm
tmpfs 484932 12768 472164 3% /run
tmpfs 484932 0 484932 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2355 451824 1% /home
172.25.254.221:/westos 10473984 3156608 7317376 31% /nfs/westos
[root@client westos]
[root@client westos]