当前位置:网站首页>如何使用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目录也会以同样的方式工作。
我发现在我的文件管理器中书签这些目录很有用,以便更快地访问。
边栏推荐
- leecode-268. 丢失的数字(异或的应用,找没有出现的数字,找只出现一次的数字)
- [Commons beanautils topic] 005- convertutils topic
- Please ask whether Oracle CDC does not support checkpointing. When the task is suspended and restarted during the real-time collection process, is the data changed
- QWaitCondition 的正确使用方法
- TypeNameExtractor could not be found
- QT notes - realize form adaptation
- 支持刘海屏
- 三层交换机配置MSTP协议详解【华为eNSP实验】
- [rust] what software should I use to develop rust? Recommended editors commonly used to support rust
- Summary of MySQL database combined with actual SQL optimization of the project
猜你喜欢

Everything about native crash

Leetcode:51. queen n

Summary of MySQL database combined with actual SQL optimization of the project

Miss waiting for a year! Baidu super chain digital publishing service is limited to 50% discount
![Error: [synth 8-439] module 'xxx' not found not found error solution](/img/47/bb03cc26e254332bf815c80bafb243.png)
Error: [synth 8-439] module 'xxx' not found not found error solution

突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战
![[rust] reference and borrowing, string slice type (& STR) - rust language foundation 12](/img/48/7a1777b735312f29d3a4016a14598c.png)
[rust] reference and borrowing, string slice type (& STR) - rust language foundation 12

基于ARM和FPGA的数字示波器设计——QMJ

高速成长的背后,华为云乌兰察布数据中心的绿色之道

Support liuhaiping
随机推荐
Design of digital oscilloscope based on arm and FPGA -- QMJ
[rust] what software should I use to develop rust? Recommended editors commonly used to support rust
Reserved instances & Savings Plans
Most after analyze table in PostgreSQL_ common_ Why is the elems field not filled in?
[rust] rust language foundation | you should quickly get an impression when learning a language
Buckle practice - 31 effective tic tac toe games
Do you regret learning it?
Buckle exercise - 32 divided into k equal subsets
Ah, I am uncle card space
Zhihuihuayun | cluster log dynamic collection scheme
Okaleido tiger NFT is about to log in to binance NFT platform
STM32 - Fundamentals of C language
Taishan Office Technology Lecture: layout difficulties of paragraph borders
Force deduction exercise - the sum of the kth smallest array in the 21 ordered matrix
TypeNameExtractor could not be found
Common shortcuts to VIM editor
Microsoft SQL Server database language and function usage (XII)
C Advanced - data storage
ThinkPHP realizes database backup
js图像转base64