操作系统:
[root@server-120 ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
[root@server-120 ~]# uname -r
3.10.0-1127.8.2.el7.x86_64
nfs服务端配置:
[root@server-120 ~]# yum install -y nfs-utils ==>>yum安装nfs
[root@server-120 ~]# rpm -qa|grep nfs ==>>检查rpm包
nfs-utils-1.3.0-0.66.el7.x86_64
[root@server-120 ~]# mkdir /public ==>>创建共享目录
[root@server-120 ~]# cp /etc/passwd /etc/shadow /public/ ==>>放入测试数据
[root@server-120 ~]# ls /public/
passwd shadow
[root@server-120 ~]# vim /etc/exports ==>>编辑nfs的配置文件/etc/exports
[root@server-120 ~]# cat /etc/exports
/public *(ro)
---------------------------------------------------------------------------------
/etc/exports的文件配置:
-------------------------------------
共享的文件加路径 客户机地址(权限)
/public *(ro)
-------------------------------------
---------------------------------------------------------------------------------
[root@server-120 ~]# systemctl restart nfs-server ==>>重启nfs服务
nfs客户端配置:
[root@Desktop ~]# mkdir /mnt/nsd ==>>创建共享目录
[root@Desktop ~]# ls /mnt/nsd
[root@Desktop ~]# mount 10.0.0.120:/public /mnt/nsd/ ==>>将服务端的共享目录挂载到客户端的共享目录(10.0.0.120为服务端IP,/public为服务端共享目录)
[root@Desktop ~]# cd /mnt/nsd/
[root@Desktop nsd]# ls ==>>查看测试数据
passwd shadow
[root@Desktop nsd]# df -h ==>>查看挂载信息
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 27G 9.4G 18G 35% /
devtmpfs 1.2G 0 1.2G 0% /dev
tmpfs 1.2G 2.7M 1.2G 1% /dev/shm
tmpfs 1.2G 11M 1.2G 1% /run
tmpfs 1.2G 0 1.2G 0% /sys/fs/cgroup
/dev/sda1 1014M 224M 791M 23% /boot
tmpfs 229M 4.0K 229M 1% /run/user/42
tmpfs 229M 24K 229M 1% /run/user/1000
/dev/sr0 4.2G 4.2G 0 100% /run/media/admin/CentOS 7 x86_64
10.0.0.120:/public 27G 9.5G 18G 36% /mnt/nsd ==>>这是挂载成功
[root@Desktop nsd]# vim /etc/fstab ==>>设置开机自动挂载
[root@Desktop nsd]# cat /etc/fstab ==>>在文件中添加以下内容
10.0.0.120:/public /mnt/nsd nfs defaults,_netdev 0 0
--------------------------------------------------------------------------------
注意:_netdev:声明网络设备。开机挂载时,首先启动所有的网络服务,然后在挂载本设备。
来源:oschina
链接:https://my.oschina.net/u/4258525/blog/4302548