一、检查系统版本
[root@node ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
二、检查yum仓库
[root@node ~]# yum repolist all |grep enable
!base/7/x86_64 CentOS-7 - Base enabled: 10,072
!docker-ce-stable/7/x86_64 Docker CE Stable - x86_64 enabled: 183
!extras/7/x86_64 CentOS-7 - Extras enabled: 515
!mongodb-org/7 MongoDB Repository enabled: 187
!updates/7/x86_64 CentOS-7 - Updates enabled: 4,346
三、安装nfs包
[root@node ~]# yum install nfs-utils rpcbind -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
mongodb-org | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
mongodb-org/7/primary_db | 129 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.3.0-0.61.el7 will be updated
---> Package nfs-utils.x86_64 1:1.3.0-0.68.el7.2 will be an update
---> Package rpcbind.x86_64 0:0.2.0-47.el7 will be updated
---> Package rpcbind.x86_64 0:0.2.0-49.el7 will be an update
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================================
Updating:
nfs-utils x86_64 1:1.3.0-0.68.el7.2 updates 413 k
rpcbind x86_64 0.2.0-49.el7 base 60 k
Transaction Summary
===================================================================================================================================================
Upgrade 2 Packages
Total size: 473 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Updating : rpcbind-0.2.0-49.el7.x86_64 1/4
Updating : 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 2/4
Cleanup : 1:nfs-utils-1.3.0-0.61.el7.x86_64 3/4
Cleanup : rpcbind-0.2.0-47.el7.x86_64 4/4
Verifying : 1:nfs-utils-1.3.0-0.68.el7.2.x86_64 1/4
Verifying : rpcbind-0.2.0-49.el7.x86_64 2/4
Verifying : rpcbind-0.2.0-47.el7.x86_64 3/4
Verifying : 1:nfs-utils-1.3.0-0.61.el7.x86_64 4/4
Updated:
nfs-utils.x86_64 1:1.3.0-0.68.el7.2 rpcbind.x86_64 0:0.2.0-49.el7
Complete!
四、配置nfs共享
1.创建共享目录
mkdir -p /nfs/share && chmod 777 -R /nfs/share/
2.修改/etc/exports文件
[root@node ~]# cat /etc/exports
/nfs/share *(rw)
五、关闭防火墙和selinux
1.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
2.放行服务(不关闭防火墙情况)
firewall-cmd --permanent --add-service=mountd
firewall-cmd --permanent --add-service=nfs
firewall-cmd --permanent --add-service=rpc-bind
3.关闭selinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
setenforce 0
六、启动nfs服务
[root@node ~]# systemctl enable --now nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
七、检查nfs共享
[root@node ~]# exportfs -r
[root@node ~]# showmount -e 192.168.3.166
Export list for 192.168.3.166:
/nfs/share *
八、测试挂载nfs共享
1.创建挂载点
mkdir /axu
2.挂载nfs共享目录
mount 192.168.3.166:/nfs/share /axu/
3.查看磁盘挂载情况
[root@node ~]# df -h |grep axu
192.168.3.166:/nfs/share 106G 28G 79G 27% /axu
4.测试文件写入情况
[root@node ~]# cd /axu/
[root@node axu]# touch file1
[root@node axu]# ll
total 0
-rw-r--r-- 1 nfsnobody nfsnobody 0 Nov 4 11:07 file1
[root@node axu]#