一、服务器端配置:
1、安装软件,开启服务、检查rpc端口注册信息:
1.1 需要先安装nfs、rpc服务
[root@nfs01 /]# yum install nfs-utils rpcbind -y
[root@nfs01 /]# rpm -qa nfs-utils rpcbind
nfs-utils-1.3.0-0.61.el7.x86_64
rpcbind-0.2.0-47.el7.x86_64
1.2 开启rpc服务,检查rpc服务是否开启,并检查服务注册信息:
1.2.1 开启rpc服务:
[root@nfs01 ~]# systemctl start rpcbind
1.2.2 检查rpc服务是否开启:
[root@nfs01 ~]# systemctl status rpcbind
● rpcbind.service - RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2019-05-23 20:34:11 CST; 9min ago
Process: 6308 ExecStart=/sbin/rpcbind -w $RPCBIND_ARGS (code=exited, status=0/SUCCESS)
Main PID: 6311 (rpcbind)
CGroup: /system.slice/rpcbind.service
└─6311 /sbin/rpcbind -w
May 23 20:34:08 nfs01 systemd[1]: Starting RPC bind service...
May 23 20:34:11 nfs01 systemd[1]: Started RPC bind service.
1.2.3 检查rpc服务端口注册信息:
[root@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
检查发现rpc服务端口并未有端口信息,这是因为nfs服务没有启动,接下来启动nfs服务。
1.3 开启nfs服务,然后检查nfs服务是否开启和rpc服务端口注册情况:
1.3.1 开启nfs服务:
[root@nfs01 ~]# systemctl start nfs
1.3.2 检查rpc服务是否开启:
[root@nfs01 ~]# systemctl status nfs
● nfs-server.service - NFS server and services
Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
Drop-In: /run/systemd/generator/nfs-server.service.d
└─order-with-mounts.conf
Active: active (exited) since Thu 2019-05-23 20:46:44 CST; 42s ago
Process: 7589 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl restart gssproxy ; fi (code=exited, status=0/SUCCESS)
Process: 7575 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
Process: 7574 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
Main PID: 7575 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/nfs-server.service
May 23 20:46:44 nfs01 systemd[1]: Starting NFS server and services...
May 23 20:46:44 nfs01 systemd[1]: Started NFS server and services.
1.3.3 检查rpc服务端口注册信息:
[root@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 49955 status
100024 1 tcp 40714 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 46645 nlockmgr
100021 3 udp 46645 nlockmgr
100021 4 udp 46645 nlockmgr
100021 1 tcp 37152 nlockmgr
100021 3 tcp 37152 nlockmgr
100021 4 tcp 37152 nlockmgr
2、 创建共享目录,并修改成nfsnobody用户主和用户组,检查共享目录的情况:
[root@nfs01 ~]# mkdir -p /data
[root@nfs01 ~]# chown nfsnobody.nfsnobody /data
[root@nfs01 ~]# ll -d /data
drwxr-xr-x 2 nfsnobody nfsnobody 19 May 23 17:33 /data
3、配置/etc/exports文件并重启,并且检查可挂载的目录:
[root@nfs01 ~]# vim /etc/exports
/data 172.16.1.0/24(rw,sync)
[root@nfs01 ~]# systemctl reload nfs
[root@nfs01 ~]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
4、写入开机自启动:
[root@nfs01 ~]# vim /etc/fstab
systemctl start rpcbind
systemctl start nfs
二、客户端配置:
1、查看nfs共享目录:
[root@web01 /]# showmount -e 172.16.1.31
Export list for 172.16.1.31:
/data 172.16.1.0/24
2、创建video目录:
[root@web01 /]# mkdir -p /video
3、把共享的目录挂载到本机:
[root@web01 /]# mount -t nfs 172.16.1.31:/data /video
4、查看挂载信息:
[root@web01 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 1.7G 18G 9% /
devtmpfs 980M 0 980M 0% /dev
tmpfs 991M 0 991M 0% /dev/shm
tmpfs 991M 9.6M 981M 1% /run
tmpfs 991M 0 991M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 199M 0 199M 0% /run/user/0
172.16.1.31:/data 20G 1.7G 18G 9% /video
5、查看共享目录的详细情况:
[root@web01 /]# ll /video
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 May 23 17:33 1.txt
6、加入到开机自启动:
[root@web01 /]# vim /etc/rc.local
mount -t nfs 172.16.1.31:/data /video
网友评论