debian9.6搭建nfs服务器(nfs-kernel-server)

1,安装

guoyanzhang@bogon:~$ sudo apt-get install nfs-kernel-server

2,修改配置

guoyanzhang@bogon:~$ sudo cat /etc/exports 
[sudo] guoyanzhang 的密码:
# /etc/exports: the access control list for filesystems which may be exported
#		to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
 /home/guoyanzhang/mynfs 192.168.43.200(rw,sync,no_root_squash)

 /home/guoyanzhang/mynfs是我主机上的文件夹,是nfs服务器的根目录;

192.168.43.200是我客户端的ip,这里是我树莓派的ip;

rw,读写权限,sync,数据同步写入内存和硬盘,no_root_squash,NFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。

3,检查配置是否有错

guoyanzhang@bogon:~$ source /etc/exports 
bash: /etc/exports:行11: 未预期的符号 `(' 附近有语法错误
bash: /etc/exports:行11: `/home/guoyanzhang/mynfs 192.168.43.200(rw,sysc,no_root_squash)'

 4,启动服务

guoyanzhang@bogon:~$ sudo /etc/init.d/nfs-kernel-server restart
[ ok ] Restarting nfs-kernel-server (via systemctl): nfs-kernel-server.service.

5,客户端挂载

pi@raspberrypi:~ $ su -
Password: 
root@raspberrypi:~# mount -n -o nolock 192.168.43.64:/home/guoyanzhang/mynfs /home/pi/pipe/

我这边普通用户挂载不了,只能是root,io192.168.43.64是我主机的ip。

6,检查是否挂载上了

root@raspberrypi:~# df -h
Filesystem                             Size  Used Avail Use% Mounted on
/dev/root                               15G  2.8G   12G  20% /
devtmpfs                               460M     0  460M   0% /dev
tmpfs                                  464M     0  464M   0% /dev/shm
tmpfs                                  464M   13M  452M   3% /run
tmpfs                                  5.0M  4.0K  5.0M   1% /run/lock
tmpfs                                  464M     0  464M   0% /sys/fs/cgroup
/dev/mmcblk0p1                          44M   23M   22M  51% /boot
tmpfs                                   93M     0   93M   0% /run/user/1000
192.168.43.64:/home/guoyanzhang/mynfs  342G   39G  286G  12% /home/pi/pipe

7,测试是否可以共享文件

扫描二维码关注公众号,回复: 4943883 查看本文章

客户端写:

root@raspberrypi:/home/pi/pipe# touch pi
root@raspberrypi:/home/pi/pipe# ls
aaa.txt  ddd.txt  pi  test.txt

服务器端查看:

guoyanzhang@bogon:~/mynfs$ ls
aaa.txt  ddd.txt  pi  test.txt

服务器端写:

guoyanzhang@bogon:~/mynfs$ touch debian
guoyanzhang@bogon:~/mynfs$ ls
aaa.txt  ddd.txt  debian  pi  test.txt

客户端查看:

root@raspberrypi:/home/pi/pipe# ls
aaa.txt  ddd.txt  debian  pi  test.txt

参考1:https://blog.csdn.net/cp1300/article/details/8262908

参考2:https://blog.csdn.net/u013451404/article/details/77103871

猜你喜欢

转载自blog.csdn.net/weixin_39465823/article/details/86500840