NFS概念:
网络文件系统(NFS)是Unix系统和网络附加存储文件管理器常用的网络文件系统,允许多个客户端通过网络共享文件访问。它可用于
提供对共享二进制目录的访问,也可用于允许用户在同一工作组中从不同客户端访问其文件。
NFS的常规配置:
服务端:
[root@server ~]# cd /mnt/
[root@server mnt]# ls
file1 file2 file3 file4 file5
[root@server mnt]# yum install nfs-utils -y 安装服务
[root@server mnt]# systemctl start nfs 开启服务
[root@server mnt]# systemctl status nfs 查看状态
用于配置NFS服务程序配置文件的参数:
参数 | 作用 |
---|---|
ro | 只读 |
rw | 读写 |
root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的匿名用户 |
no_root_squash | 当NFS客户端以root管理员访问时,映射为NFS服务器的root管理员 |
all_squash | 无论NFS客户端使用什么帐号访问,均映射为NFS服务器的匿名用户 |
sync | 同时将数据写入到内存和硬盘中,保证不丢失数据 |
async | 优先将数据保存到内存,然后再写入硬盘。这样效率更高,但可能会丢失数据 |
[root@server mnt]# vim /etc/exports 编辑文件
[root@server mnt]# cat /etc/exports
/mnt *(sync,ro) 可远程传输只读
[root@server mnt]# exportfs -rv 刷新
exporting *:/mnt
客户端:
[root@client ~]# yum install nfs-utils -y 客户端安装服务
showmount命令查询NFS服务器的远程共享信息:
参数 | 作用 |
---|---|
-e | 显示NFS服务器的共享列表 |
-a | 显示本机挂载的文件资源的情况 |
-v | 显示版本号 |
[root@client ~]# showmount -e 172.25.254.221 显示nfs共享文件
Export list for 172.25.254.221:
/mnt *
[root@client ~]# mount 172.25.254.221:/mnt/ /mnt/
[root@client ~]# df
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 ~]# cd /mnt/
[root@client mnt]# rm -fr * 删除的时候为只读
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]# vim /etc/exports
/mnt *(sync,rw) 可远程传输可写
[root@server mnt]# exportfs -rv 刷新
exporting *:/mnt