首页 > 系统相关 >Linux系统之使用autofs自动挂载nfs共享

Linux系统之使用autofs自动挂载nfs共享

时间:2023-02-18 12:32:30浏览次数:40  
标签:00 x86 64 autofs Linux nfs el7

(Linux系统之使用autofs自动挂载nfs共享)

一、autofs介绍

Autofs 是一项可自动挂载相应文件系统的客户端服务,可用于nfs共享的自动挂载,无需手动mount挂载,方便日常使用。

二、检查本地系统环境

1.检查系统版本

[root@jeven ~]# 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"


2.检查系统内核版本

[root@jeven ~]# uname -r 
6.1.8-1.el7.elrepo.x86_64


三、部署nfs服务

1.检查系统nfs软件包

检查系统nfs软件包是否安装


[root@jeven ~]#  yum list installed |grep nfs
libnfsidmap.x86_64                      0.25-19.el7                    @anaconda
nfs-utils.x86_64                        1:1.3.0-0.61.el7               @anaconda
nfs4-acl-tools.x86_64                   0.3.3-19.el7                   @anaconda

2.安装nfs

[root@jeven ~]# yum install nfs-utils rpcbind -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * elrepo: mirrors.tuna.tsinghua.edu.cn
base                                                                                                                                         | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                             | 3.5 kB  00:00:00     
elrepo                                                                                                                                       | 3.0 kB  00:00:00     
epel                                                                                                                                         | 4.7 kB  00:00:00     
extras                                                                                                                                       | 2.9 kB  00:00:00     
updates                                                                                                                                      | 2.9 kB  00:00:00     
(1/3): docker-ce-stable/7/x86_64/primary_db                                                                                                  |  95 kB  00:00:00     
(2/3): epel/x86_64/updateinfo                                                                                                                | 1.0 MB  00:00:01     
(3/3): epel/x86_64/primary_db                                                                                                                | 7.0 MB  00:00:10     
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 download size: 473 k
Downloading packages:
No Presto metadata available for base
No Presto metadata available for updates
(1/2): rpcbind-0.2.0-49.el7.x86_64.rpm                                                                                                       |  60 kB  00:00:00     
(2/2): nfs-utils-1.3.0-0.68.el7.2.x86_64.rpm                                                                                                 | 413 kB  00:00:00     
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                               607 kB/s | 473 kB  00:00:00     
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!



3.创建共享目录

mkdir -p /nfs   #创建共享目录

4.编辑配置文件


echo "/nfs *(insecure,rw,sync,no_root_squash)" > /etc/exports

5.重启nfs相关服务

 systemctl enable --now rpcbind
 systemctl enable --now  nfs-server

6.查看nfs服务状态


[root@jeven ~]# systemctl status nfs-server
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enabled; vendor preset: disabled)
  Drop-In: /run/systemd/generator/nfs-server.service.d
           └─order-with-mounts.conf
   Active: active (exited) since Sat 2023-02-04 11:00:17 CST; 1min 1s ago
  Process: 63991 ExecStartPost=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ; fi (code=exited, status=0/SUCCESS)
  Process: 63969 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
  Process: 63967 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 63969 (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
   CGroup: /system.slice/nfs-server.service

Feb 04 11:00:15 jeven systemd[1]: Starting NFS server and services...
Feb 04 11:00:17 jeven systemd[1]: Started NFS server and services.

四、远程客户端测试nfs共享

[root@server001 ~]# showmount -e 192.168.3.166
Export list for 192.168.3.166:
/nfs *



五、配置autofs自动挂载

1.安装autofs软件包

[root@server001 ~]# yum -y install autofs
Loaded plugins: fastestmirror, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Determining fastest mirrors
base                                                                                                                                             | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                 | 3.5 kB  00:00:00     
extras                                                                                                                                           | 2.9 kB  00:00:00     
updates                                                                                                                                          | 2.9 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/primary_db                                                                                                      |  95 kB  00:00:00     
(2/2): updates/7/x86_64/primary_db                                                                                                               |  19 MB  00:00:22     
Resolving Dependencies
--> Running transaction check
---> Package autofs.x86_64 1:5.0.7-116.el7_9 will be installed
--> Processing Dependency: libhesiod.so.0()(64bit) for package: 1:autofs-5.0.7-116.el7_9.x86_64
--> Running transaction check
---> Package hesiod.x86_64 0:3.2.1-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package                              Arch                                 Version                                          Repository                             Size
========================================================================================================================================================================
Installing:
 autofs                               x86_64                               1:5.0.7-116.el7_9                                updates                               834 k
Installing for dependencies:
 hesiod                               x86_64                               3.2.1-3.el7                                      base                                   30 k

Transaction Summary
========================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 864 k
Installed size: 5.2 M
Downloading packages:
(1/2): hesiod-3.2.1-3.el7.x86_64.rpm                                                                                                             |  30 kB  00:00:00     
(2/2): autofs-5.0.7-116.el7_9.x86_64.rpm                                                                                                         | 834 kB  00:00:01     
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                   718 kB/s | 864 kB  00:00:01     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : hesiod-3.2.1-3.el7.x86_64                                                                                                                            1/2 
  Installing : 1:autofs-5.0.7-116.el7_9.x86_64                                                                                                                      2/2 
  Verifying  : hesiod-3.2.1-3.el7.x86_64                                                                                                                            1/2 
  Verifying  : 1:autofs-5.0.7-116.el7_9.x86_64                                                                                                                      2/2 

Installed:
  autofs.x86_64 1:5.0.7-116.el7_9                                                                                                                                       

Dependency Installed:
  hesiod.x86_64 0:3.2.1-3.el7                                                                                                                                           

Complete!




2.设置服务开机自启


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



3.配置autofs自动挂载

指定 zhangsan用户挂载的本地目录为/home/zhangsan,挂载用户家目录配置文件为/etc/auto.nfs

[root@server001 ~]# grep home /etc/auto.master
/home /etc/auto.nfs
[root@server001 ~]# cat  /etc/auto.nfs
zhangsan -fstype=nfs,rw 192.168.3.166:/nfs




4.重启autofs服务


[root@server001 ~]# systemctl restart autofs
[root@server001 ~]# 

六、测试客户端autofs自动挂载

1.进入/home/zhangsan目录

进入/home/zhangsan目录,autofs自动将/nfs共享目录挂载到本地/home/zhangsan目录。


[root@server001 ~]# cd /home/zhangsan
[root@server001 zhangsan]# df -h |grep zhangsan
192.168.3.166:/nfs       106G   49G   58G  47% /home/zhangsan


2.测试共享目录创建文件

  • 客户端写入文件
[root@server001 zhangsan]# touch aa.txt
[root@server001 zhangsan]# ls
aa.txt


  • nfs服务端查看文件
[root@jeven ~]# cd /nfs/
[root@jeven nfs]# ls
aa.txt


标签:00,x86,64,autofs,Linux,nfs,el7
From: https://blog.51cto.com/u_14664141/6065314

相关文章

  • Linux环境下常见软件安装
    一、克隆虚拟机1、准备一台你要克隆的虚拟机,保证时关闭状态。2、在vmware中选中你的虚拟机,右键,选择“管理”,在选择克隆3、在克隆源中,可以选择“当前状态”,如果有快照,可......
  • linux报错:-bash: telnet: 未找到命令
    如linux系统下遇到以下情况,是因为缺少该软件包使用命令:yuminstall 命令名称-y 安装即可。例:yuminstalltelnet-y ......
  • LINUX串口相关属性设置详解
     Linux下串口的设置命令 查看串口波特率等信息:stty-F/dev/ttyS0-a#ttyS0为要查看的串口 设置串口参数:stty-F/dev/ttyS0ispeed115200ospeed115200cs8......
  • 初识Linux(十七)------ 基础系统设置与备份策略
      新的CentOS7有针对不同的服务提供了相当大量的命令行设置模式,而过去那个setup似乎没用了。取而代之的是bash-complete提供了不少参数补全的设置工具,甚至包括网......
  • 局域网中linux和window共享文件方案——samba
    注明:曾经写过:局域网中如何为Ubuntu20.04和window10共享文件,本文可以视作为该篇的续篇。  ==========================================......
  • 在 Linux 中Docker上安装、启用 SQL Server 代理
     一、使用Docker运行SQLServerLinux容器映像https://learn.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-docker?view=sql-server-linux-ver15&piv......
  • Suse Linux 15 SP3 安装zabbix-agent 5.x
    zabbix官方文档:https://www.zabbix.com/cn/download?zabbix=5.0&os_distribution=suse_linux_enterprise_server&os_version=15&components=agent&db=&ws=1、安装zabbixr......
  • Linux03
    vim的使用编辑器大致分为两种:所见即所得:word、markdown命令编辑器:vim(VIImproved)、emacs使用效率:vim的安装sudoaptupdatesudoaptinstallvimvim的模式......
  • linux013之文件和目录的权限管理
    用户、组、文件目录的关系:简介:用户和组关联,组合文件目录关联,这样就实现了用户对文件的权限管理。首先来看一下,一个文件或目录的权限是怎么查看的,ls-l,如下,这个信息怎......
  • 实现阿里云ECS或其他Linux服务器之间的文件传输
    当需要在两个Linux服务器之间传输文件时,一般会有以下几种选择:基于Xftp:先把文件或文件夹从A服务器down到本地,然后再从本地up到B服务器;基于wget:在B服务器上直接利用wget工......