2019-05-22
环境
1.IP
NFS服务端
172.16.1.31
web客户端
172.16.1.7
2.运用到的服务
(客户端服务端一起安装)
nfs
rpcbind
查看服务包是否安装
[root 21:04 @ nfs01 ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.3.0-0.61.el7.x86_64
rpcbind-0.2.0-47.el7.x86_64
[root 21:04 @ nfs01 ~]#
没有安装请安装(安装命令)
yum install -y nfs-utils rpcbind
NFS服务端
环境搭建
1.创建共享目录/upload
[root 21:13 @ nfs01 /]# mkdir /upload
2.共享目录授权给nfsnobody
[root 21:18 @ nfs01 /]# chown nfsnobody.nfsnobody /upload
3.编辑nfs配置文件/etc/exports
[root 21:20 @ nfs01 /]# vim /etc/exports
/upload 172.16.1.0/24(rw,all_squash)
------------------------------------------------------
必须先启动rpc服务,再启动nfs服务
原因:nfs服务需要向rpc服务注册端口
------------------------------------------------------
4.启动rpc服务
[root 21:22 @ nfs01 /]# systemctl start rpcbind
5.查看rpc服务
[root 21:24 @ nfs01 /]# rpcinfo -p
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
6.启动nfs服务
[root 21:25 @ nfs01 /]# systemctl start nfs
7.再看rpc服务
[root 21:27 @ nfs01 /]# rpcinfo -p
program vers proto port service
100000 4 tcp 111 portmapper
100000 3 tcp 111 portmapper
100000 2 tcp 111 portmapper
100000 4 udp 111 portmapper
100000 3 udp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 53002 status
100024 1 tcp 43715 status
100005 1 udp 20048 mountd
100005 1 tcp 20048 mountd
100005 2 udp 20048 mountd
100005 2 tcp 20048 mountd
100005 3 udp 20048 mountd
100005 3 tcp 20048 mountd
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100227 3 tcp 2049 nfs_acl
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100227 3 udp 2049 nfs_acl
100021 1 udp 53472 nlockmgr
100021 3 udp 53472 nlockmgr
100021 4 udp 53472 nlockmgr
100021 1 tcp 36640 nlockmgr
100021 3 tcp 36640 nlockmgr
100021 4 tcp 36640 nlockmgr
web客户端
环境搭建
1.创建目录作为共享目录挂载点
[root 21:34 @ web01 ~]# mkdir /data
2.查看服务端可挂载的目录信息
[root 21:34 @ web01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/upload 172.16.1.0/24
3.启动nfs服务
[root 21:36 @ web01 ~]# systemctl start nfs
4.把服务端共享目录挂载到本地准备的挂载点/data
[root 21:35 @ web01 ~]# mount -t nfs 172.16.1.31:/upload /data
5.查看挂载信息
[root 21:38 @ web01 ~]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 20G 1.7G 18G 9% /
devtmpfs devtmpfs 980M 0 980M 0% /dev
tmpfs tmpfs 991M 0 991M 0% /dev/shm
tmpfs tmpfs 991M 9.6M 981M 1% /run
tmpfs tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 xfs 197M 105M 93M 54% /boot
tmpfs tmpfs 199M 0 199M 0% /run/user/0
172.16.1.31:/upload nfs4 20G 1.8G 18G 10% /data
[root 21:38 @ web01 ~]#
验证
验证 1:
添加:
----------------------------------------------
服务端
[root 21:41 @ nfs01 /upload]# touch {1..5}.txt
[root 21:41 @ nfs01 /upload]# ls
1.txt 2.txt 3.txt 4.txt 5.txt
客户端
[root 21:42 @ web01 /data]# ls
1.txt 2.txt 3.txt 4.txt 5.txt
[root 21:42 @ web01 /data]#
-----
客户端
[root 21:42 @ web01 /data]# touch {6..10}.txt
[root 21:42 @ web01 /data]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
[root 21:43 @ web01 /data]#
服务端
[root 21:43 @ nfs01 /upload]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
[root 21:43 @ nfs01 /upload]#
验证 2:
删除:
-------------------------------------------------------------
客户端
[root 21:43 @ web01 /data]# ls
10.txt 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt
[root 21:44 @ web01 /data]# rm -rf {1..5}.txt
[root 21:44 @ web01 /data]# ls
10.txt 6.txt 7.txt 8.txt 9.txt
[root 21:45 @ web01 /data]#
服务端
[root 21:45 @ nfs01 /upload]# ls
10.txt 6.txt 7.txt 8.txt 9.txt
[root 21:45 @ nfs01 /upload]#
-----
服务端
[root 21:45 @ nfs01 /upload]# ls
10.txt 6.txt 7.txt 8.txt 9.txt
[root 21:46 @ nfs01 /upload]# rm -rf {6..10}.txt
[root 21:46 @ nfs01 /upload]# ls
[root 21:46 @ nfs01 /upload]#
客户端
[root 21:47 @ web01 /data]# ls
[root 21:47 @ web01 /data]#
卸载
[root 21:48 @ web01 /data]# umount /data
umount.nfs4: /data: device is busy
[root 21:48 @ web01 /data]#
错误原因:
因为正在这个目录中,导致进程占用,系统繁忙
[root 21:48 @ web01 /data]# cd
先退出目录
[root 21:48 @ web01 ~]# umount /data
[root 21:48 @ web01 ~]# df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 21G 1.8G 19G 9% /
devtmpfs devtmpfs 499M 0 499M 0% /dev
tmpfs tmpfs 510M 0 510M 0% /dev/shm
tmpfs tmpfs 510M 8.1M 502M 2% /run
tmpfs tmpfs 510M 0 510M 0% /sys/fs/cgroup
/dev/sda1 xfs 207M 110M 97M 54% /boot
tmpfs tmpfs 102M 0 102M 0% /run/user/0