侧边栏壁纸
  • 累计撰写 99 篇文章
  • 累计创建 54 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

NFS 设置

FlyingEagle
2024-10-15 / 0 评论 / 0 点赞 / 229 阅读 / 2,834 字

服务端

apt install nfs-kernel-server

openwrt NFS安装服务端

opkg update && 
opkg install kmod-fs-nfs kmod-fs-nfs-common kmod-fs-nfs-v4 nfs-utils
opkg install kmod-fs-nfs kmod-fs-nfs-v3 nfs-utils kmod-fs-nfs-v4

服务端创建共享文件夹

mkdir /srv/nfs_share
chown nobody:nogroup /srv/nfs_share
chmod 777 /srv/nfs_share

编辑配置

nano /etc/exports

/srv/nfs_share <client_ip>(rw,sync,no_subtree_check,no_root_squash) #内网IP 192.168.2.0/24

分享NFS加载路径报"exportfs: /srv/share requires fsid= for NFS export" 错误,需增加fsid=1,配置文件修改为

/srv/nfs_share <client_ip>(rw,sync,no_subtree_check,no_root_squash,fsid=1)

echo直接写入

echo "/srv/nfs_share <client_ip>(rw,sync,no_subtree_check,no_root_squash) " >> /etc/exports

输出配置文件

exportfs -ra

重启服务端NFS服务

systemctl start nfs-kernel-server
systemctl enable nfs-kernel-server

openwrt 重启NFS服务

/etc/init.d/nfsd restart

防火墙设置

sudo ufw allow from <client_ip> to any port nfs
sudo ufw allow 2049/tcp
sudo ufw reload

客户端安装

apt install nfs-common

客户端挂载

mount -t nfs -o rw,nolock <serverip>:/srv/nfs_share /mnt

服务端检查挂载

 exportfs -v

开机自动挂载

nano /etc/fstab
<serverip>:/srv/nfs_share  /mnt  nfs  rw,nolock  0  0

服务端配置参数

Common Options for NFS in fstab:
defaults: Uses the default NFS mount options (rw, suid, dev, exec, auto, nouser, async).
rw: Allows both reading and writing.
sync: Ensures data is written to disk immediately, enhancing data integrity.
noatime: Prevents updating the access time on files, which can improve performance.
hard: Retries indefinitely if the NFS server becomes unreachable (default option).
soft: Causes the client to time out if the server doesn’t respond (use with caution).
timeo=n: Sets the timeout (in tenths of a second) for NFS requests. For example, timeo=30 sets a 3-second timeout.
vers=n: Specifies the NFS version (e.g., vers=4 for NFSv4).
nolock: Disables file locking, useful if the server doesn’t support locking.
Explanation of the Parameters:
rw: Mounts the NFS share with read/write permissions.

nolock: Disables file locking, which can be useful if the NFS server doesn’t support it or if there are compatibility issues.

soft: If the NFS server becomes unresponsive, this allows the client to fail rather than hanging indefinitely. If you need guaranteed access, use hard instead, which will keep retrying.

timeo=30: Sets the timeout value for NFS requests to 30 tenths of a second (3 seconds). You can adjust this value to control how long to wait for a response from the server before retrying.

retrans=3: Specifies the number of times to retry a request before reporting an error. Increasing this value can help with unstable connections.

_netdev: Ensures that the mount occurs only after the network is available, preventing issues during system boot.

Additional Options:

noatime: Disables updating access times on files, which can improve performance.
async: Allows asynchronous writes, which may improve performance but could risk data integrity during a crash.
wsize=65536 and rsize=65536: Sets the write and read buffer sizes. Larger sizes (up to 64 KB) can improve performance for transferring large files.
vers=3 or vers=4: Specifies the NFS version to use, like NFSv3 or NFSv4. Using a newer version (e.g., NFSv4) may provide better performance and security features.

0

评论区