linux学习使用

NFS 使用总结

2024-05-16  本文已影响0人  ___TheOne___

1. NFS(network file system) 网络文件系统

2. 原理

NFS Server 分享目录与 Client 挂载目录

3. 优缺点

优点:

4. 常用命令

4.1 NFS 服务端

  1. 启动、停止、重启 NFS服务
systemctl start nfs-server
systemctl stop nfs-server
systemctl restart nfs-server
  1. 查看 NFS 服务状态
[root@localhost goods]# systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
  Drop-In: /run/systemd/generator/nfs-server.service.d
           └─order-with-mounts.conf
   Active: active (exited) since Mon 2023-03-06 01:00:22 EST; 1 years 2 months ago
 Main PID: 40432 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/nfs-server.service

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
  1. 查看 当前连接的NFS客户端
# showmount -e <NFS服务器地址>
# 说明:10.46.22.26:/mnt/tenghui 挂载到了 6台 客户端上。
[root@localhost goods]# showmount -e 10.46.22.26
Export list for 10.46.22.26:
/mnt/tenghui 10.46.22.33,10.46.22.32,10.46.22.31,10.46.22.30,10.46.22.29,10.46.22.28,10.46.22.27

4.2 NFS 客户端

  1. 挂载NFS
# 10.0.0.217上的/html/作为挂载点,挂载在本地目录/usr/local/nginx/html上
mount -t nfs -o vers=3,nolock 10.0.0.217:/html/ /usr/local/nginx/html
  1. 卸载NFS
umount  /usr/local/nginx/html
  1. 查看 NFS 挂载信息
# mount | grep nfs
[root@localhost goods]# mount | grep nfs
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime)
10.46.22.26:/mnt/tenghui on /mnt/tenghui type nfs4 (rw,relatime,vers=4.1,rsize=1048576,wsize=1048576,namlen=255,hard,
proto=tcp,timeo=600,retrans=2,sec=sys,
clientaddr=10.46.22.33,local_lock=none,
addr=10.46.22.26)

说明:
10.46.22.26:/mnt/tenghui:
NFS 服务器的 IP 地址是 10.46.22.26。
NFS 服务器上导出的路径是 /mnt/tenghui。

/mnt/tenghui:
这是本地挂载点,表示将远程 NFS 服务器上的 /mnt/tenghui 挂载到本地的 /mnt/tenghui 目录。

type nfs4:
使用 NFS 版本 4。
rw:
读写权限(read-write)。

relatime:
文件访问时间的挂载选项(relative atime),提高性能,同时保留了文件访问时间的某些语义。

vers=4.1:
使用 NFS 协议版本 4.1。

rsize=1048576,wsize=1048576:
读和写的块大小均为 1048576 字节(1MB),提高了传输性能。

namlen=255:
文件名最大长度为 255 字节。

hard:
硬挂载(hard mount),意味着如果 NFS 服务器不可用,I/O 操作会重试,而不会立即失败。

proto=tcp:
使用 TCP 协议进行传输。

timeo=600:
超时时间为 600 * 0.1 秒(即 60 秒)。

retrans=2:
重传次数为 2。

sec=sys:
使用系统默认的 UNIX 用户身份验证。

clientaddr=10.46.22.33:
客户端的 IP 地址是 10.46.22.33。

local_lock=none:
本地锁选项为无。

addr=10.46.22.26:
NFS 服务器的 IP 地址是 10.46.22.26(与开始部分一致)。
上一篇 下一篇

猜你喜欢

热点阅读