当前位置:网站首页>如何使用autofs挂载NFS共享
如何使用autofs挂载NFS共享
2022-07-24 12:35:00 【星哥玩云】
大多数Linux文件系统都是在引导时挂载的,并且在系统运行时仍然挂载。在fstab文件中配置的任何远程文件系统也是如此。但是,有时您可能希望只在需求上挂载远程文件系统—例如,通过减少网络带宽使用来提高性能,或者出于安全原因隐藏或混淆某些目录。包autofs提供了这个特性。在本文中,我将描述如何启动和运行基本的自动加载配置。
首先,假设NFS服务器linux.linuxidc.com已经启动并运行。还假设这个服务器共享一个名为ourfiles的数据目录和两个用于linuxidc和Sarah的用户目录。
一些最佳实践将使事情更好地工作:在服务器上和任何客户端工作站上为用户使用相同的用户ID是一个好主意,因为他们有一个帐户。另外,您的工作站和服务器应该具有相同的域名。检查相关配置文件应予以确认。
[email protected]:~$ sudo getent passwd linuxidc sarah [sudo] password for alan: linuxidc:x:1020:1020:linuxidc,,,:/home/linuxidc:/bin/bash sarah:x:1021:1021:Sarah,,,:/home/sarah:/bin/bash
[email protected]:~$ sudo getent hosts 127.0.0.1 localhost 127.0.1.1 linuxidc.linuxidc.com linuxidc 10.10.1.5 linux.linuxidc.com tree
如您所见,客户机工作站和NFS服务器都配置在主机文件中。我假设一个基本的家庭或甚至小的办公室网络可能缺乏适当的内部域名服务(即。,DNS)。
安装包
您只需要安装两个包:NFS客户端函数的常用NFS包,以及提供automount函数的autofs包。
[email protected]:~$ sudo apt-get install nfs-common autofs
您可以验证autofs文件已被放置在etc目录:
[email protected]:~$ cd /etc; ll auto* -rw-r--r-- 1 root root 12596 Nov 19 2015 autofs.conf -rw-r--r-- 1 root root 857 Mar 10 2017 auto.master -rw-r--r-- 1 root root 708 Jul 6 2017 auto.misc -rwxr-xr-x 1 root root 1039 Nov 19 2015 auto.net* -rwxr-xr-x 1 root root 2191 Nov 19 2015 auto.smb* [email protected]:/etc$
配置autofs
现在您需要编辑其中几个文件,并添加文件auto.home。首先,向文件auto.master添加以下两行:
/mnt/tree /etc/auto.misc /home/tree /etc/auto.home
每一行都以NFS共享所在的目录开头。继续创建这些目录:
[email protected]:/etc$ sudo mkdir /mnt/tree /home/tree
第二步,在auto.misc文件中添加以下行:
ourfiles -fstype=nfs tree:/share/ourfiles
这一行指示autofs在auto中匹配的位置挂载ourfiles共享。用于auto.misc的主文件。如上所示,这些文件可以在目录/mnt/树/ourfiles中找到。
第三,创建文件自动。家与以下线:
* -fstype=nfs tree:/home/&
这一行指示autofs在auto中匹配的位置挂载用户共享。自动.home的主文件。在本例中,linuxidc和Sarah的文件将分别在目录/home/tree/linuxidc或/home/tree/sarah中可用。星号(称为通配符)使每个用户的共享在登录时自动挂载成为可能。& and也作为通配符在服务器端表示用户的目录。它们的主目录应该相应地映射到passwd文件中。如果您喜欢本地主目录,则不必这样做;相反,用户可以将其用作特定文件的简单远程存储。
最后,重新启动autofs守护进程,使其能够识别并加载这些配置文件更改。
[email protected]:/etc$ sudo service autofs restart
测试autofs
如果您更改到文件中列出的目录之一,则自动。掌握并运行ls命令,您不会立即看到任何东西。例如,将目录(cd)更改为/mnt/tree。首先,ls的输出不会显示任何内容,但是在运行cd ourfiles之后,ourfiles共享目录将自动挂载。cd命令也将被执行,您将被放置到新挂载的目录中。
[email protected]:~$ cd /mnt/tree [email protected]:/mnt/tree$ ls [email protected]:/mnt/tree$ cd ourfiles [email protected]:/mnt/tree/ourfiles$
为了进一步确认正在工作,mount命令将显示挂载共享的详细信息。
[email protected]:~$ mount tree:/mnt/share/ourfiles on /mnt/tree/ourfiles type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.10.1.22,local_lock=none,addr=10.10.1.5)
对于linuxidc和Sarah来说,/home/tree目录也会以同样的方式工作。
我发现在我的文件管理器中书签这些目录很有用,以便更快地访问。
边栏推荐
- Design of digital oscilloscope based on arm and FPGA -- QMJ
- Open source DNS software powerdns BIND9 mydns
- 02 linear structure 2 multiplication and addition of univariate polynomials (linked list solution)
- Correct use of qwaitcondition
- QT notes - sort a column specified by qtablewidget
- How to render millions of 2D objects smoothly with webgpu?
- Overview of MES system equipment management (medium)
- The biggest crisis for testers in the workplace is not at the age of 30, but being laid off in middle age
- 【功能测试】项目的测试——登录和发布文章功能
- Why has API strategy become a magic weapon for enterprises' digital transformation?
猜你喜欢

Examples of map search

三层交换机配置MSTP协议详解【华为eNSP实验】

QT based software framework design

TypeNameExtractor could not be found

【Rust】引用和借用,字符串切片 (slice) 类型 (&str)——Rust语言基础12

基于Kubernetes v1.24.0的集群搭建(三)

Qt Creator怎样更改默认构建目录
![[rust] Why do I suggest you learn rust | a preliminary study of rust](/img/33/a5e7d22e87502fa8582920cb34de9f.png)
[rust] Why do I suggest you learn rust | a preliminary study of rust
如何用WebGPU流畅渲染百万级2D物体?

Implementing deep learning framework from zero -- further exploration of the implementation of multilayer bidirectional RNN
随机推荐
Guys, do you need to configure anything to use rocksdb when using flinksql? Or do you need any jar packages
Unity rotation test
三层交换机配置MSTP协议详解【华为eNSP实验】
How to upload pictures from typora to CSDN
月薪 3万人民币是一种怎样的体验?做自媒体可以达到这种水平吗
ThinkPHP realizes database backup
VMware virtual machine and vSphere migrate to each other
Is there any entrepreneurship project suitable for one person in the early stage of 2W and 3W? Is it OK to be we media?
leetcode:51. N 皇后
一文看懂MES系统能实现企业哪些目标
How to find out the function calling process of complex code running as soon as possible
leecode-268. 丢失的数字(异或的应用,找没有出现的数字,找只出现一次的数字)
Installation and deployment of ansible
ASP. Net core deployment Manual: 1. Deployment Basics
Use of multithreading in QT
Open source DNS software powerdns BIND9 mydns
Skillfully using command line parameters in Delphi to realize the trigger function of dragging files onto program icons
QWaitCondition 的正确使用方法
How to render millions of 2D objects smoothly with webgpu?
I used annotations to configure the serialization of redis in one module project, and then introduced this module in another module. Why is this configuration