Linux系统之NFS共享配置教程

简介: 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]# 
相关文章
|
Ubuntu Linux Anolis
Linux系统禁用swap
本文介绍了在新版本Linux系统(如Ubuntu 20.04+、CentOS Stream、openEuler等)中禁用swap的两种方法。传统通过注释/etc/fstab中swap行的方式已失效,现需使用systemd管理swap.target服务或在/etc/fstab中添加noauto参数实现禁用。方法1通过屏蔽swap.target适用于新版系统,方法2通过修改fstab挂载选项更通用,兼容所有系统。
1273 3
Linux系统禁用swap
|
Linux
Linux系统修改网卡名为eth0、eth1
在Linux系统中,可通过修改GRUB配置和创建Udev规则或使用systemd链接文件,将网卡名改为`eth0`、`eth1`等传统命名方式,适用于多种发行版并支持多网卡配置。
1858 3
|
Ubuntu Linux 网络安全
Linux系统初始化脚本
一款支持Rocky、CentOS、Ubuntu、Debian、openEuler等主流Linux发行版的系统初始化Shell脚本,涵盖网络配置、主机名设置、镜像源更换、安全加固等多项功能,适配单/双网卡环境,支持UEFI引导,提供多版本下载与持续更新。
1335 3
Linux系统初始化脚本
|
安全 Linux Shell
Linux系统提权方式全面总结:从基础到高级攻防技术
本文全面总结Linux系统提权技术,涵盖权限体系、配置错误、漏洞利用、密码攻击等方法,帮助安全研究人员掌握攻防技术,提升系统防护能力。
1424 1
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
1212 1
二、Linux文本处理与文件操作核心命令
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
952 137
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
1934 58
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
1870 2
|
Unix Linux 程序员
Linux文本搜索工具grep命令使用指南
以上就是对Linux环境下强大工具 `grep` 的基础到进阶功能介绍。它不仅能够执行简单文字查询任务还能够处理复杂文字处理任务,并且支持强大而灵活地正则表达规范来增加查询精度与效率。无论您是程序员、数据分析师还是系统管理员,在日常工作中熟练运用该命令都将极大提升您处理和分析数据效率。
1145 16