NFS 设置

server

centos

1
2
3
4
5
# install
sudo yum install -y nfs-utils
# 开机启动
sudo systemctl start rpcbind
sudo systemctl start nfs

防火墙需要打开 rpc-bind 和 nfs 的服务

1
2
3
4
5
6
7
8
$ sudo firewall-cmd --zone=public --permanent --add-service=rpc-bind
success
$ sudo firewall-cmd --zone=public --permanent --add-service=mountd
success
$ sudo firewall-cmd --zone=public --permanent --add-service=nfs
success
$ sudo firewall-cmd --reload
success

配置共享目录
服务启动之后,我们在服务端配置一个共享目录

1
2
sudo mkdir /data
sudo chmod 755 /data

根据这个目录,相应配置导出目录

1
2
3
sudo vi /etc/exports
# 添加以下配置
/data/ 192.168.0.0/24(rw,sync,no_root_squash,no_all_squash)

  1. /data: 共享目录位置。
  2. 192.168.0.0/24: 客户端 IP 范围,* 代表所有,即没有限制。
  3. rw: 权限设置,可读可写。
  4. sync: 同步共享目录。
  5. no_root_squash: 可以使用 root 授权。
  6. no_all_squash: 可以使用普通用户授权。

重启服务

1
2
3
sudo systemctl restart nfs
# nfs 是否开启成功
expoerfs

检查本地共享目录

1
2
3
$ showmount -e localhost
Export list for localhost:
/sound 172.17.4.0/24

client

raspberry

1
2
3
4
5
6
7
8
9
10
11
12
# 安装 nfs 
sudo apt-get install nfs-utils -y
# 挂载
sudo mount -t nfs ip:/path /localpath
# 配置自动挂载
sudo vim /etc/fstab
# /etc/fstab 最后一行追加
172.17.4.100:/sound /sound nfs rw
# 修改 fstab 重新加载 systemctl
sudo systemctl daemon-reload
# 查看一下
mount