Linux下的NFS搭建配置

简介: Linux下的NFS搭建配置

一、NFS介绍

1.NFS简介

NFS:网络文件系统,由Sun公司开发,通过网络,NFS支持在不同的文件系统之间共享文件.用户不必关心计算机的型号,是由Linux、unix及类似操作系统之间使用的互联网标准协议,可作为他们的本地网络文件系统。

2.NFS特点

①节约使用的磁盘空间:客户端经常使用的数据可以集中存放在一台机器上,并使用NFS发布,那么网络内部所有计算机可以通过网络访问,不必单独存储.
②节约硬件资源:NFS还可以共享软驱,CDROM和ZIP等的存储设备,减少整个网络上的可移动设备的数量.
③用户主目录设定
对于特殊用户,如管理员等,为了管理的需要,可能会经常登录到网络中所有的计算机,若每个客户端,均保存这个用户的主目录很繁琐,而且不能保证数据的一致性.实际上,经过NFS服务的设定,然后在客户端指定这个用户的主目录位置,并自动挂载,就可以在任何计算机上使用用户主目录的文件.

二、环境介绍

操作系统为RHEL8.0
服务端:control ————192.168.200.150
客户端:node1————192.168.200.135

三、服务端配置

1.创建共享目录

[root@control ~]# mkdir -p /share/data
[root@control ~]# ll -ld /share/data/
drwxr-xr-x 2 root root 6 Jul 15 21:31 /share/data/

2.检查NFS包是否安装

root@control ~]# yum list installed |grep nfs
libnfsidmap.x86_64                               1:2.3.3-14.el8                                       @anaconda    
nfs-utils.x86_64                                 1:2.3.3-14.el8                                       @anaconda    
sssd-nfs-idmap.x86_64                            2.0.0-43.el8                                         @anaconda 

3.安装nfs相关包

 yum install nfs-utils rpcbind -y

4.编辑配置文件

[root@control ~]# vim /etc/exports
[root@control ~]# cat /etc/exports
/share/data 192.168.200.0/24(rw) 

5.重启服务且放行防火墙

[root@control ~]# systemctl restart nfs-server
[root@control ~]# firewall-cmd --permanent --add-service=mountd 
success
[root@control ~]# firewall-cmd --permanent --add-service=nfs
success
[root@control ~]# firewall-cmd --permanent --add-service=rpc-bind 
success
[root@control ~]# firewall-cmd --reload 
success
[root@control ~]#

四、客户端配置

1.检查服务端共享目录是否存在

[root@control ~]# showmount -e 192.168.200.150
Export list for 192.168.200.150:
/share/data 192.168.200.0/24

2.安装自动挂载程序

[root@node1 ~]# yum -y install autofs
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
Repository AppStream is listed more than once in the configuration
Repository BaseOS is listed more than once in the configuration
AppStream                                                                                                      3.1 MB/s | 3.2 kB     00:00    
BaseOS                                                                                                         2.7 MB/s | 2.7 kB     00:00    
ansiable                                                                                                       0.0  B/s |   0  B     00:00    
Zabbix                                                                                                         330  B/s | 2.9 kB     00:09    
Zabbix                                                                                                         493 kB/s | 152 kB     00:00    
Failed to synchronize cache for repo 'ansiable', ignoring this repo.
Dependencies resolved.
===============================================================================================================================================
 Package                         Arch                            Version                                 Repository                       Size
===============================================================================================================================================
Installing:
 autofs                          x86_64                          1:5.1.4-29.el8                          BaseOS                          755 k

Transaction Summary
===============================================================================================================================================
Install  1 Package

Total size: 755 k
Installed size: 3.5 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                       1/1 
  Installing       : autofs-1:5.1.4-29.el8.x86_64                                                                                          1/1 
  Running scriptlet: autofs-1:5.1.4-29.el8.x86_64                                                                                          1/1 
  Verifying        : autofs-1:5.1.4-29.el8.x86_64                                                                                          1/1 
Installed products updated.

Installed:
  autofs-1:5.1.4-29.el8.x86_64                                                                                                                 

Complete!

2.启动服务

[root@node1 ~]# systemctl enable --now autofs
Created symlink /etc/systemd/system/multi-user.target.wants/autofs.service → /usr/lib/systemd/system/autofs.service.

3.编辑配置文件

[root@node1 ~]# grep -E -v '^#|^$' /etc/auto.master
/misc    /etc/auto.misc
/share /etc/auto.nfs
/net    -hosts
+dir:/etc/auto.master.d
+auto.master
[root@node1 ~]# vim /etc/auto.nfs
[root@node1 ~]# cat /etc/auto.nfs 
dpt -rw 192.168.200.150:/share/data
[root@node1 ~]# 

五、检查测试

[root@node1 ~]# cd /share
[root@node1 share]# cd dpt
[root@node1 dpt]# 
[root@node1 dpt]# df -h
Filesystem                   Size  Used Avail Use% Mounted on
devtmpfs                     970M     0  970M   0% /dev
tmpfs                        984M     0  984M   0% /dev/shm
tmpfs                        984M   22M  962M   3% /run
tmpfs                        984M     0  984M   0% /sys/fs/cgroup
/dev/nvme0n1p3                18G  4.6G   13G  27% /
/dev/nvme0n1p1               495M  140M  356M  29% /boot
//192.168.200.150/share       13G  8.5G  4.1G  68% /media
tmpfs                        197M  4.0K  197M   1% /run/user/0
/dev/sr0                     6.7G  6.7G     0 100% /mnt/cdrom
192.168.200.150:/share/data   13G  8.5G  4.1G  68% /share/dpt
相关实践学习
CentOS 8迁移Anolis OS 8
Anolis OS 8在做出差异性开发同时,在生态上和依赖管理上保持跟CentOS 8.x兼容,本文为您介绍如何通过AOMS迁移工具实现CentOS 8.x到Anolis OS 8的迁移。
相关文章
|
9天前
|
Linux Shell
问题记录:解决Linux登录故障,/etc/passwd配置受损该怎么操作
修复/etc/passwd文件是解决Linux登录故障的重要步骤。通过进入单用户模式、挂载文件系统、恢复或手动修复/etc/passwd文件,可以有效解决该问题。保持定期备份系统配置文件是预防此类问题的最佳实践。
37 13
|
8天前
|
Linux Shell
问题记录:解决Linux登录故障,/etc/passwd配置受损该怎么操作
修复/etc/passwd文件是解决Linux登录故障的重要步骤。通过进入单用户模式、挂载文件系统、恢复或手动修复/etc/passwd文件,可以有效解决该问题。保持定期备份系统配置文件是预防此类问题的最佳实践。
25 2
|
2月前
|
Ubuntu Unix Linux
Linux网络文件系统NFS:配置与管理指南
NFS 是 Linux 系统中常用的网络文件系统协议,通过配置和管理 NFS,可以实现跨网络的文件共享。本文详细介绍了 NFS 的安装、配置、管理和常见问题的解决方法,希望对您的工作有所帮助。通过正确配置和优化 NFS,可以显著提高文件共享的效率和安全性。
274 7
|
3月前
|
数据库连接 Linux Shell
Linux下ODBC与 南大通用GBase 8s数据库的无缝连接配置指南
本文详细介绍在Linux系统下配置GBase 8s数据库ODBC的过程,涵盖环境变量设置、ODBC配置文件编辑及连接测试等步骤。首先配置数据库环境变量如GBASEDBTDIR、PATH等,接着修改odbcinst.ini和odbc.ini文件,指定驱动路径、数据库名称等信息,最后通过catalog.c工具或isql命令验证ODBC连接是否成功。
|
5月前
|
网络协议 安全 Linux
如何配置Linux端的ftp?
如何配置Linux端的ftp?
188 64
|
3月前
|
缓存 资源调度 安全
深入探索Linux操作系统的心脏——内核配置与优化####
本文作为一篇技术性深度解析文章,旨在引领读者踏上一场揭秘Linux内核配置与优化的奇妙之旅。不同于传统的摘要概述,本文将以实战为导向,直接跳入核心内容,探讨如何通过精细调整内核参数来提升系统性能、增强安全性及实现资源高效利用。从基础概念到高级技巧,逐步揭示那些隐藏在命令行背后的强大功能,为系统管理员和高级用户打开一扇通往极致性能与定制化体验的大门。 --- ###
111 9
|
3月前
|
存储 安全 数据管理
如何在 Rocky Linux 8 上安装和配置 Elasticsearch
本文详细介绍了在 Rocky Linux 8 上安装和配置 Elasticsearch 的步骤,包括添加仓库、安装 Elasticsearch、配置文件修改、设置内存和文件描述符、启动和验证 Elasticsearch,以及常见问题的解决方法。通过这些步骤,你可以快速搭建起这个强大的分布式搜索和分析引擎。
116 5
|
4月前
|
Java Linux 网络安全
NIFI在Linux服务区上的部署配置过程是什么?
【10月更文挑战第21天】NIFI在Linux服务区上的部署配置过程是什么?
142 2
|
4月前
|
Ubuntu Linux 编译器
Linux/Ubuntu下使用VS Code配置C/C++项目环境调用OpenCV
通过以上步骤,您已经成功在Ubuntu系统下的VS Code中配置了C/C++项目环境,并能够调用OpenCV库进行开发。请确保每一步都按照您的系统实际情况进行适当调整。
1058 3
|
4月前
|
监控 安全 网络协议
快速配置Linux云服务器
【10月更文挑战第3天】快速配置Linux云服务器