创建两个配置好yum源和不同网卡的虚拟机
服务节点(server):192.168.223.20
客户机节点(client):192.168.223.30

1.重命名

[root@localhost ~]# hostnamectl set-hostname nfs-server [root@localhost ~]# hostnamectl Static hostname: nfs-server Icon name: computer-vm Chassis: vm Machine ID: ac7e881816ac4b5da4214409baa5af86 Boot ID: 58207fe001a34173bcf5462bf18fc8dd Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.el7.x86_64 Architecture: x86-64 [root@localhost ~]# bash [root@localhost ~]# hostnamectl set-hostname nfs-client [root@localhost ~]# hostnamectl Static hostname: nfs-client Icon name: computer-vm Chassis: vm Machine ID: ac7e881816ac4b5da4214409baa5af86 Boot ID: ecfe926d3ded48d4bceb5340d9880d24 Virtualization: vmware Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1160.el7.x86_64 Architecture: x86-64 [root@localhost ~]# bash

2.安装NFS服务

[root@nfs-server ~]# yum -y install nfs-utils rpcbind [root@nfs-client ~]# yum -y install nfs-utils rpcbind

3.创建一个用于共享的目录

  1. 编辑配置NFC的配置文件

[root@nfs-server ~]# mkdir /mnt/test [root@nfs-server ~]# vi /etc/exports [root@nfs-server ~]# cat /etc/exports /mnt/test 192.168.223.0/24(rw,no_root_squash,no_all_squash,sync,anonuid=501,anongid=501) [root@nfs-server ~]# exportfs -r

4.服务端启动NFS服务

查看可挂载目录

[root@nfs-server ~]# systemctl start rpcbind [root@nfs-server ~]# systemctl start nfs [root@nfs-server ~]# showmount -e 192.168.200.10 Export list for 192.168.200.10: /mnt/test 192.168.223.20/24 //此处目录应为第三步创建的目录

5.关闭防火墙

[root@nfs-client ~]# setenforce 0 [root@nfs-client ~]# systemctl stop firewalld [root@nfs-server ~]# systemctl stop firewalld

6.在client节点进行NFS共享目录的挂载

查看挂载情况

[root@nfs-client ~]# mount -t nfs 192.168.223.20:/mnt/test /mnt/ [root@nfs-client ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 18G 878M 17G 5% / devtmpfs 903M 0 903M 0% /dev tmpfs 913M 0 913M 0% /dev/shm tmpfs 913M 8.6M 904M 1% /run tmpfs 913M 0 913M 0% /sys/fs/cgroup /dev/sda1 497M 125M 373M 25% /boot tmpfs 183M 0 183M 0% /run/user/0 /dev/sr0 4.1G 4.1G 0 100% /opt/centos 192.168.200.10:/mnt/test 5.8G 20M 5.5G 1% /mnt

7.在client下创建一个abc.txt并在server下验证

[root@nfs-client ~]# cd /mnt/ [root@nfs-client mnt]# ll total 0 [root@nfs-client mnt]# touch abc.txt [root@nfs-server ~]# cd /mnt/test/ [root@nfs-server test]# ll total 0 -rw-r—r—. 1 root root 0 Oct 30 07:18 abc.txt