Linux系统之NFS共享配置教程

举报
江湖有缘 发表于 2022/12/05 13:12:11 2022/12/05
【摘要】 Linux系统之NFS共享配置教程

一、检查系统版本

[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]# 

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。