国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

NFS服務器簡介、在Linux上搭建NFS服務器和客戶端,使用autofs進行NFS客戶端自動掛載和卸載詳解

這篇具有很好參考價值的文章主要介紹了NFS服務器簡介、在Linux上搭建NFS服務器和客戶端,使用autofs進行NFS客戶端自動掛載和卸載詳解。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

目錄

一.NFS服務器簡介

1.含義簡介:

2.工作原理簡介:

3.RPC服務與NFS服務配合使用

二.NFS配置文件參數命令介紹

1.主配置文件/etc/exports

2.日志文件/var/lib/nfs/

3.showmount命令

三.主配置文件/etc/exports掛載寫法

1.配置nfs服務端和客戶端

2.windows客戶端掛載測試

3.權限介紹

(1)rw/ro,服務器目錄的共享權限是可讀寫/只讀,但起決定作用的還是該目錄的rwx權限

(2)sync/async,sync指數據會同步寫入到內存與硬盤中,async則指數據會先暫存于內存當中,不直接寫入硬盤

(3)no_root_squash/root_squash,若客戶端在共享目錄里創(chuàng)建的文件的所屬者和所屬組是root用戶和root組,那么查看顯示文件的屬主和屬組時有兩種情況:

(4)all_squash/no_all_squash

(5)anonuid=,anongid=

四.在客戶端配置auto自動掛載和卸載

1.安裝autofs

2.auto建立客戶端數據文件/etc/auto.master時配置參數(可以省略)

3.配置自動掛載/卸載過程


?

一.NFS服務器簡介

1.含義簡介:

NFS,網絡文件系統(tǒng),是FreeBSD支持的文件系統(tǒng)之一,允許網絡中的不同的計算機、不同的操作系統(tǒng)之間通過TCP/IP網絡共享資源。

2.工作原理簡介:

本地NFS客戶端應用可以讀寫位于遠端NFS服務器(網絡)上的文件,NFS服務器可以讓計算機將網絡中的NFS服務器共享的目錄掛載到本地端的文件系統(tǒng)中,而在本地端的系統(tǒng)中看來,那個遠程主機的目錄類似于自己本地文件系統(tǒng)的一個磁盤分區(qū)。

3.RPC服務與NFS服務配合使用

?NFS的功能很多,每啟動一個功能就會啟用一些端口來傳輸數據,所以NFS的功能對應的端口并不固定,而是隨機取用一些未被使用的小于1024的端口用于傳輸。需要借助RPC(遠程過程調用)解決客戶端連接服務器(端口)的問題。當啟動NFS時會隨機選取幾個端口號,并主動向RPC注冊,此時RPC知道每個NFS功能所對應的端口號,RPC將端口號下發(fā)給客戶端,使得客戶端可以連接到正確的端口上去。RPC采用固定端口號Port?111來監(jiān)聽客戶端需求并向客戶端下發(fā)正確的端口號。

?注意:RPC要在啟動NFS之前啟動才能實現NFS向RPC注冊,如果重啟RPC服務,NFS原來注冊的數據會清楚,那么它管理的所有服務都需要重新啟動重新注冊。

二.NFS配置文件參數命令介紹

1.主配置文件/etc/exports

主配置文件如果不存在需要手動創(chuàng)建

編輯了主配置文件不需要重新啟動服務,使用exportfs (-r)命令進行(全部)加載配置文件即可(同步更新/etc/exports,/var/lib/nfs/xtab)

exportfs其他選項:

-a? ? 全部掛載或卸載/etc/exports中的內容
-u? ? 卸載單一目錄,可以和-a一起使用為卸載所有/etc/exports文件中的目錄
-v? ? 將詳細的信息輸出到屏幕上

2.日志文件/var/lib/nfs/

etab和xtab比較重要,etab主要記錄NFS共享出來的目錄的完整權限設置值,xtab主要記錄以往鏈接到這個NFS服務器的相關客戶端數據。

[root@sulibao ~]# ll /var/lib/nfs/
total 0
-rw-r--r--   1 root    root     0 Oct 14  2021 etab
-rw-r--r--   1 root    root     0 Jan 20 11:17 export-lock
drwx------   2 root    root    25 Jan 20 11:17 nfsdcltrack
-rw-r--r--   1 root    root     0 Oct 14  2021 rmtab
dr-xr-xr-x  11 root    root     0 Dec 31 17:46 rpc_pipefs
drwx------.  4 rpcuser rpcuser 43 Jan 20 11:17 statd
-rw-r--r--   1 rpcuser rpcuser  0 Oct 14  2021 state
drwxr-xr-x.  2 root    root     6 Oct 14  2021 v4recovery
-rw-r--r--   1 root    root     0 Oct 14  2021 xtab

3.showmount命令

查看NFS共享出來的目錄資源

showmount -e 主機名/ip表示顯示NFS服務器的導出列表

三.主配置文件/etc/exports掛載寫法

1.配置nfs服務端和客戶端

如下是在Linux上創(chuàng)建服務端,并以Linux作為客戶端進行測試

(1)準備兩臺虛擬機,關閉SElinux和防火墻,保證網絡可用,有yum源,虛擬機1作為服務器端,虛擬機2作為客戶端。

兩臺虛擬機都下載rpcbindnfs-utils

[root@sulibao ~]# yum install -y rpcbind
[root@sulibao ~]# yum install -y nfs-utils

(2)通過“共享目錄? 主機名/IP/網段(權限)”編寫配置進行掛載,權限可以為多個,寫在括號里面以逗號隔開

服務器端寫主配置文件

[root@sulibao ~]# vim /etc/exports
/nfsdir 192.168.2.0/24(rw)

注意:這里經常出現問題, (權限)與前面的字段之間多大了空格,此時權限不會生效!

(3)服務器端創(chuàng)建共享目錄和文件并寫入內容

[root@sulibao ~]# mkdir /nfsdir
[root@sulibao ~]# cd /nfsdir/
[root@sulibao nfsdir]# touch aaa.txt
[root@sulibao nfsdir]# vim aaa.txt 
nfs-server

(4)先開啟rpcbind服務再開啟nfs-server服務

[root@sulibao nfsdir]# systemctl restart rpcbind
[root@sulibao nfsdir]# systemctl restart nfs-server

(5)在服務器端和客戶端分別進行測試是否能夠連接到共享目錄

服務器端

[root@sulibao nfsdir]# showmount -e 192.168.2.160
Export list for 192.168.2.160
/nfsdir 192.168.2.0/24
[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root root 11 Jan 20 11:44 aaa.txt

客戶端

[root@sulibao ~]# showmount -e 192.168.2.160
Export list for 192.168.2.160:
/nfsdir 192.168.2.0/24

(6)在客戶端進行測試是否能夠實現掛載

在客戶端創(chuàng)建一個掛載目錄,使用“mount 服務器IP:共享目錄? 掛載目錄”進行掛載

[root@sulibao ~]# mkdir /mountdir
[root@sulibao ~]# mount 192.168.2.160:/nfsdir /mountdir/
[root@sulibao ~]# mount                //通過mount可以查看有沒有掛載記錄
192.168.2.160:/nfsdir on /mountdir type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.2.170,local_lock=none,addr=192.168.2.160)
[root@sulibao ~]# df -h             也可以通過df -h查看目錄掛載情況
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               5.1G     0  5.1G   0% /dev
tmpfs                  5.1G     0  5.1G   0% /dev/shm
tmpfs                  5.1G  9.8M  5.1G   1% /run
tmpfs                  5.1G     0  5.1G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   35G  5.2G   30G  15% /
/dev/nvme0n1p1        1014M  257M  758M  26% /boot
tmpfs                  1.1G   36K  1.1G   1% /run/user/0
/dev/sr0                11G   11G     0 100% /media/cdrom
192.168.2.160:/nfsdir   35G  5.1G   30G  15% /mountdir

在客戶端也能查看到在服務器端上寫的內容

[root@sulibao ~]# cd /mountdir/
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root root 11 Jan 20 11:44 aaa.txt
[root@sulibao mountdir]# cat aaa.txt 
nfs-server

(7)注意:

這里主配置文件里設置的權限是可讀可寫但實際上其他用戶共享這個目錄時并不能新建或編輯文件

[root@sulibao mountdir]# touch bbb.txt
touch: cannot touch 'bbb.txt': Read-only file system

nfs客戶端,Linux,服務器,linux,運維,centos,NFS

?需要在服務器端更改共享目錄權限,如若沒生效可以選擇試試重啟nfs-server

[root@sulibao nfsdir]# chmod 777 /nfsdir/
[root@sulibao nfsdir]# systemctl restart nfs-server.service

在客戶端就可以修改共享目錄內文件或者新建文件了

[root@sulibao mountdir]# touch bbb.txt
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
[root@sulibao mountdir]# vim aaa.txt?

nfs客戶端,Linux,服務器,linux,運維,centos,NFS

2.windows客戶端掛載測試

(1)這里以一個新例子做介紹

[root@localhost ~]# showmount -e    #160主機上搭建了nfs服務端
Export list for localhost.localdomain:
/root/data *

(2)到windows上進行掛載,方法1

到控制面板開啟NFS客戶端和管理工具功能

nfs客戶端,Linux,服務器,linux,運維,centos,NFS

nfs客戶端,Linux,服務器,linux,運維,centos,NFS?右鍵此電腦,點擊映射網絡驅動器

nfs客戶端,Linux,服務器,linux,運維,centos,NFS

如下書寫

nfs客戶端,Linux,服務器,linux,運維,centos,NFS?等待連接完成即可

nfs客戶端,Linux,服務器,linux,運維,centos,NFS

?nfs客戶端,Linux,服務器,linux,運維,centos,NFS

(3)方法2

開啟NFS客戶端和管理工具后直接在cmd內進行掛載

C:\Users\24107>mount 192.168.2.160:/root/data Z:
Z: 現已成功連接到 192.168.2.160:/root/data

命令已成功完成。

?nfs客戶端,Linux,服務器,linux,運維,centos,NFS

?(4)如上通過驅動器映射和命令行的掛載若需要卸載,建議都使用命令行進行卸載

C:\Users\24107>umount Z:

正在斷開連接            Z:      \\192.168.2.160\root\data
命令已成功完成。

3.權限介紹

(1)rw/ro,服務器目錄的共享權限是可讀寫/只讀,但起決定作用的還是該目錄的rwx權限

(2)sync/async,sync指數據會同步寫入到內存與硬盤中,async則指數據會先暫存于內存當中,不直接寫入硬盤

(3)no_root_squash/root_squash,若客戶端在共享目錄里創(chuàng)建的文件的所屬者和所屬組是root用戶和root組,那么查看顯示文件的屬主和屬組時有兩種情況:

  • no_root_squash指將root屬主和組映射為root屬主和組(默認的)

服務器端修改主配置文件/etc/exports,重新加載配置文件并測試

[root@sulibao nfsdir]# vim /etc/exports
/nfsdir 192.168.2.0/24(rw,no_root_squash)
[root@sulibao nfsdir]# exportfs -r
[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt

客戶端測試

[root@sulibao mountdir]# touch ccc.txt
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
  • root_squash指將root屬主和組映射為匿名用戶和組(默認的)

?服務器端修改主配置文件/etc/exports,重新加載主配置文件并測試

[root@sulibao nfsdir]# vim /etc/exports
/nfsdir 192.168.2.0/24(rw,root_squash)
[root@sulibao nfsdir]# exportfs -r
[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:05 ddd.txt

?客戶端測試

[root@sulibao mountdir]# touch ddd.txt
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt

(4)all_squash/no_all_squash

(1)all_squash客戶端普通用戶創(chuàng)建文件時,會將文件的用戶和組映射為匿名用戶和匿名組

服務器端修改朱培志文件,重新加載配置文件并測試

[root@sulibao nfsdir]# vim /etc/exports
/nfsdir 192.168.2.0/24(rw,no_root_squash,all_squash)
[root@sulibao nfsdir]# exportfs -r
[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root      root       0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nfsnobody nfsnobody  0 Jan 20 15:40 ggg.txt

客戶端普通用戶下測試

[root@sulibao mountdir]# su - xiaosu
[xiaosu@sulibao ~]$ cd /mountdir/
[xiaosu@sulibao mountdir]$ ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
[xiaosu@sulibao mountdir]$ touch ggg.txt
[xiaosu@sulibao mountdir]$ ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nobody nobody  0 Jan 20 15:40 ggg.txt

(2)no_all_squash客戶端普通用戶創(chuàng)建的文件的UID和GID是多少服務器端就映射為UID和GID對應的用戶

服務器端修改主配置,重新加載配置文件

[root@sulibao nfsdir]# vim /etc/exports
/nfsdir 192.168.2.0/24(rw,no_root_squash,no_all_squash)
[root@sulibao nfsdir]# exportfs -r
[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root      root       0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nfsnobody nfsnobody  0 Jan 20 15:40 ggg.txt

客戶端普通用戶下對應服務器端進行測試,這里普通用戶的UID和GID是1000,那么服務器上就會映射出服務器上UID和GID為1000的用戶或者UID和GID值

[root@sulibao mountdir]# su - xiaosu
[xiaosu@sulibao ~]$ cd /mountdir/
[xiaosu@sulibao mountdir]$ ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nobody nobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:41 hhh.txt
[xiaosu@sulibao mountdir]$ touch iii.txt
[xiaosu@sulibao mountdir]$ ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nobody nobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 xiaosu xiaosu  0 Jan 20 15:42 iii.txt
[xiaosu@sulibao mountdir]$ cat /etc/passwd |grep xiaosu
xiaosu:x:1000:1000:xiaosu:/home/xiaosu:/bin/bash
 
//客戶端普通用戶xiaosu的UID和GID為1000

[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root      root       0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nfsnobody nfsnobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1 root      root       0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 sulibao   sulibao    0 Jan 20 15:42 iii.txt
[root@sulibao nfsdir]# cat /etc/passwd | grep 1000
sulibao:x:1000:1000:sulibao:/home/sulibao:/bin/bash

//服務器端上UID=GID=1000匹配的是普通用戶sulibao,就映射sulibao

[root@sulibao mountdir]# useradd -u 6666 susu
[root@sulibao mountdir]# cat /etc/passwd | grep 6666
susu:x:6666:6666::/home/susu:/bin/bash
[root@sulibao mountdir]# chown susu:susu hhh.txt 
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nobody nobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1 susu   susu    0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 xiaosu xiaosu  0 Jan 20 15:42 iii.txt

//客戶端普通用戶susu的UID和GID為6666,將hhh.txt屬主和組改為susu

[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root      root       0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nfsnobody nfsnobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1      6666      6666  0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 sulibao   sulibao    0 Jan 20 15:42 iii.txt

//服務器端沒有與UID=GID=6666的用戶和組,就直接映射UID和GID

(5)anonuid=,anongid=

文件的用戶和組映射為指定的UID和GID或相匹配的用戶,若不指定默認為65534(nfsnobody)

服務器端修改主修改配置文件并重新加載配置文件

[root@sulibao nfsdir]# vim /etc/exports
/nfsdir 192.168.2.0/24(rw,no_root_squash,all_squash,anonuid=5555,anongid=5555)
[root@sulibao nfsdir]# exportfs -r
[root@sulibao nfsdir]# useradd -u 5555 slb

客戶端測試,客戶端沒有此UID和GID的用戶就會顯示UID和GID值,有就顯示值相匹配的用戶

[root@sulibao mountdir]# touch qqq.txt
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nobody nobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1 susu   susu    0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 xiaosu xiaosu  0 Jan 20 15:42 iii.txt
-rw-r--r-- 1   5555   5555  0 Jan 20 16:06 qqq.txt
//客戶端上沒有
[root@sulibao nfsdir]# ll
total 4
-rw-r--r-- 1 root      root      11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root      root       0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root      root       0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nfsnobody nfsnobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nfsnobody nfsnobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1      6666      6666  0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 sulibao   sulibao    0 Jan 20 15:42 iii.txt
-rw-r--r-- 1 slb       slb        0 Jan 20 16:06 qqq.txt
//服務器端上剛創(chuàng)建了slb用戶,UID和GID相匹配,映射slb用戶

四.在客戶端配置auto自動掛載和卸載

auto自動掛載主要是用來實現當客戶端有掛載需求時才進行掛載,基于上文的服務器虛擬機和客戶端虛擬機進行演示

1.安裝autofs

[root@sulibao nfsdir]# yum install -y autofs

2.auto的配置文件介紹

(1)/etc/auto.master

用于auto掛載的設置,auto掛載信息的映射關系

格式:客戶端掛載目錄? ?(參數)? 掛載auto配置文件的目錄

# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/misc   /etc/auto.misc               //表示/misc的掛載信息在/etc/auto.misc中
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
+dir:/etc/auto.master.d
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
+auto.master

(2)/etc/autofs.conf

autofs服務的配置,主要關注timeout,表示切除目錄后多少時間自動解除掛載

timeout = 300   //默認是300秒

(3)/etc/auto.misc

auto掛載的信息

# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage

cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom

掛載目錄         掛載選項                         :掛載設備

# the following entries are samples to pique your imagination
#linux          -ro,soft,intr           ftp.example.org:/pub/linux
#boot           -fstype=ext2            :/dev/hda1
#floppy         -fstype=auto            :/dev/fd0
#floppy         -fstype=ext2            :/dev/fd0
#e2floppy       -fstype=ext2            :/dev/fd0
#jaz            -fstype=ext2            :/dev/sdc1
#removable      -fstype=ext2            :/dev/hdd

2.auto建立客戶端數據文件/etc/auto.master時配置參數(可以省略)

參數 實現功能
fg/bg

fg表示掛載行為在前臺執(zhí)行,bg表示掛載行為在后臺執(zhí)行。前臺執(zhí)行,則mount會持續(xù)嘗試掛載,直到成功或超時為止。后臺執(zhí)行,mount會在后臺持續(xù)多次進行mount,不會影響到前臺的程序運行。

soft/hard

hard表示當兩者之間的任何一臺主機脫機,則RPC會持續(xù)地呼叫,直到對方恢復連接為止。如果是soft的話,那RPC會在超時后重復呼叫,非持續(xù)呼叫

intr

當使用hard方式掛載時,若加上intr這個參數,則當RPC持續(xù)呼叫時,該次的呼叫是可以被中斷的

rsize/wsize

讀出(rsize)與寫入(wsize)的區(qū)塊大小,設置值可以影響客戶端與服務器端傳輸數據的緩沖記憶容量

3.配置自動掛載/卸載過程

服務器端不動,autofs主要配置在客戶端

(1)安裝好autofs后編輯配置文件/etc/auto.master

找到/misc ? /etc/auto.misc這一行,在其后或前寫一行,指定/etc/auto.nfs的自動掛載信息在/nfscli下

[root@sulibao ~]# vim /etc/auto.master
/nfscli ?/etc/auto.nfs
/misc ? /etc/auto.misc

//nfscli不需要手動創(chuàng)建,稍后重啟autofs服務會自動創(chuàng)建

(2)編輯新建剛才指定的文件/etc/auto.nfs

指定客戶端掛載地址和服務器端共享目錄地址

[root@sulibao ~]# vim /etc/auto.nfs
mountdir 192.168.2.160:/nfsdir

(3)重啟autofs服務,查看/nfscli目錄是否自動創(chuàng)建

[root@sulibao ~]# systemctl restart autofs.service 
[root@sulibao ~]# ls -ld /nfscli
drwxr-xr-x 2 root root 0 Jan 20 17:49 /nfscli

(4)觸發(fā)自動掛載(切入客戶端掛載目錄mountdir即觸發(fā)

切入前先使用mount命令查看掛載記錄方便查看是否生效(如果上文配置的臨時掛載仍處于掛載狀態(tài),可以使用“umount -lf 目錄”取消掛載)

[root@sulibao ~]# mount | tail -5
/dev/sr0 on /media/cdrom type iso9660 (ro,relatime,nojoliet,check=s,map=n,blocksize=2048,uid=0,gid=0,dmode=500,fmode=400)
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
/etc/auto.nfs on /nfscli type autofs (rw,relatime,fd=5,pgrp=48620,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=243315)
/etc/auto.misc on /misc type autofs (rw,relatime,fd=11,pgrp=48620,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=241423)
-hosts on /net type autofs (rw,relatime,fd=17,pgrp=48620,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=243320)

切入目錄/nfscli,此時查看該目錄內并沒有內容,但是仍然可以進入客戶端掛載目錄mountdir,進入可以查看到服務器端共享目錄內容,通過mount查看,自動掛載成功

[root@sulibao ~]# cd /nfscli
[root@sulibao nfscli]# ll
total 0
[root@sulibao nfscli]# cd mountdir
[root@sulibao mountdir]# ll
total 4
-rw-r--r-- 1 root   root   11 Jan 20 14:56 aaa.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 14:56 bbb.txt
-rw-r--r-- 1 root   root    0 Jan 20 14:58 ccc.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:05 ddd.txt
-rw-r--r-- 1 root   root    0 Jan 20 15:09 eee.txt
-rw-r--r-- 1 nobody nobody  0 Jan 20 15:37 fff.txt
-rw-rw-r-- 1 nobody nobody  0 Jan 20 15:40 ggg.txt
-rw-r--r-- 1   6666   6666  0 Jan 20 15:41 hhh.txt
-rw-rw-r-- 1 xiaosu xiaosu  0 Jan 20 15:42 iii.txt
-rw-r--r-- 1   5555   5555  0 Jan 20 16:06 qqq.txt

[root@sulibao mountdir]# mount | tail -5
nfsd on /proc/fs/nfsd type nfsd (rw,relatime)
/etc/auto.nfs on /nfscli type autofs (rw,relatime,fd=5,pgrp=48620,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=243315)
/etc/auto.misc on /misc type autofs (rw,relatime,fd=11,pgrp=48620,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=241423)
-hosts on /net type autofs (rw,relatime,fd=17,pgrp=48620,timeout=300,minproto=5,maxproto=5,indirect,pipe_ino=243320)
192.168.2.160:/nfsdir on /nfscli/mountdir type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.2.170,local_lock=none,addr=192.168.2.160)

(5)設置自動取消掛載

編輯/etc/autofs.conf,方便測試將timeout時間改短一點

[root@sulibao mountdir]# vim /etc/autofs.conf 
# Define default options for autofs.
#
[ autofs ]
#
# master_map_name - default map name for the master map.
#
#master_map_name = auto.master
#
# timeout - set the default mount timeout in secons. The internal
#           program default is 10 minutes, but the default installed
#           configuration overrides this and sets the timeout to 5
#           minutes to be consistent with earlier autofs releases.
#
timeout = 10

[root@sulibao mountdir]# systemctl restart autofs.service 
[root@sulibao mountdir]# cd /nfscli/mountdir/     //重啟測試能夠自動掛載
[root@sulibao mountdir]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               5.1G     0  5.1G   0% /dev
tmpfs                  5.1G     0  5.1G   0% /dev/shm
tmpfs                  5.1G  9.8M  5.1G   1% /run
tmpfs                  5.1G     0  5.1G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   35G  5.2G   30G  15% /
/dev/nvme0n1p1        1014M  257M  758M  26% /boot
tmpfs                  1.1G   36K  1.1G   1% /run/user/0
/dev/sr0                11G   11G     0 100% /media/cdrom
192.168.2.160:/nfsdir   35G  5.1G   30G  15% /nfscli/mountdir

切出掛載目錄觸發(fā)取消掛載再等10秒再查看掛載情況

[root@sulibao mountdir]# cd
[root@sulibao ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               5.1G     0  5.1G   0% /dev
tmpfs                  5.1G     0  5.1G   0% /dev/shm
tmpfs                  5.1G  9.8M  5.1G   1% /run
tmpfs                  5.1G     0  5.1G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   35G  5.2G   30G  15% /
/dev/nvme0n1p1        1014M  257M  758M  26% /boot
tmpfs                  1.1G   36K  1.1G   1% /run/user/0
/dev/sr0                11G   11G     0 100% /media/cdrom

//取消掛載成功

?文章來源地址http://www.zghlxwxcb.cn/news/detail-761471.html

到了這里,關于NFS服務器簡介、在Linux上搭建NFS服務器和客戶端,使用autofs進行NFS客戶端自動掛載和卸載詳解的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!

本文來自互聯(lián)網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。如若轉載,請注明出處: 如若內容造成侵權/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經查實,立即刪除!

領支付寶紅包贊助服務器費用

相關文章

  • NFS客戶端掛載nfs服務器共享目錄時的報錯及解決辦法:mount.nfs: access denied by server while mounting

    客戶端掛載nfs共享目錄時的報錯信息:mount.nfs: access denied by server while mounting 192.168.41.191:/nfsfile NFS服務器 1、我原來nfs配置文件exports里面的內容如下 2、重啟rpcbind和nfs-server服務;查看了一下nfs-server服務,上面顯示“Active: active (exited) \\\",意思是“活動:活動(已退出)”,這是

    2024年02月05日
    瀏覽(22)
  • 用C語言搭建TCP服務器/客戶端

    用C語言搭建TCP服務器/客戶端

    1.TCP流程圖 2.TCP編程 服務器 客戶端 ????????以上就是用c語言搭建的tcp服務器和客戶端,IP地址的地方可以根據自己本機的IP地址去修改(在命令提示符中可以使用ifconfig命令查看本機IP地址),端口號用的是6666,也可自己修改,但是IP地址和端口號服務器和客戶端必須一至。

    2024年02月09日
    瀏覽(25)
  • Nginx HTTP/3服務器-客戶端環(huán)境搭建

    一、 NGINX 服務器介紹: NGINX是一個高性能的開源Web服務器,也可用作反向代理服務器、負載均衡器和HTTP緩存。它由俄羅斯的程序員Igor Sysoev創(chuàng)建,并于2004年首次公開發(fā)布。NGINX的設計重點是高性能、高并發(fā)和低內存消耗,使其成為了現代Web架構中的關鍵組件之一。 NGINX的一些

    2024年03月11日
    瀏覽(28)
  • 20230904 QT客戶端服務器搭建聊天室

    20230904 QT客戶端服務器搭建聊天室

    Ser Cli

    2024年02月09日
    瀏覽(18)
  • QT實現TCP通信(服務器與客戶端搭建)

    QT實現TCP通信(服務器與客戶端搭建)

    創(chuàng)建一個QTcpServer類對象,該類對象就是一個服務器 調用listen函數將該對象設置為被動監(jiān)聽狀態(tài),監(jiān)聽時,可以監(jiān)聽指定的ip地址,也可以監(jiān)聽所有主機地址,可以通過指定端口號,也可以讓服務器自動選擇 當有客戶端發(fā)來連接請求時,該服務器會自動發(fā)射一個newConnection信號

    2024年02月09日
    瀏覽(27)
  • 【Android】MQTT入門——服務器部署與客戶端搭建

    【Android】MQTT入門——服務器部署與客戶端搭建

    MQTT(Message Queuing Telemetry Transport) 是一種基于發(fā)布/訂閱模式的輕量級消息傳輸協(xié)議,專門針對低帶寬、和不穩(wěn)定網絡環(huán)境的物聯(lián)網應用而設計,它可以用極少的代碼為互聯(lián)網設備提供實時可靠的消息服務。 MQTT 協(xié)議主要用于物聯(lián)網和移動設備等資源有限的場景中,其中包括

    2024年02月04日
    瀏覽(33)
  • 簡單FTP客戶端軟件開發(fā)——搭建FTP服務器

    簡單FTP客戶端軟件開發(fā)——搭建FTP服務器

    計網課程設計的要求是: 1) 該FTP客戶端程序具有以下基本功能: 2) 開發(fā)美觀易用的圖形界面 FTP使用客戶服務器方式,因為開發(fā)的是客戶端,所以需要一個FTP服務器,客戶端進行連接訪問,進行文件操作。 前面我們已經安裝好了Linux虛擬機,在Linux搭建FTP服務器原參考博客

    2024年02月03日
    瀏覽(30)
  • 用Python搭建非常簡易的TCP客戶端和服務器

    用Python搭建非常簡易的TCP客戶端和服務器

    以下屬于Python Socket網絡編程的基礎,單純?yōu)榱藴y試學習 只要運行就會將內容發(fā)送至服務器 只要運行就會開始監(jiān)聽客戶端請求 我們先運行TCP服務器(打開cmd,使用netstat命令可查看對應端口),然后運行TCP客戶端,結果如下: 服務端: 客戶端: 過幾天寫一篇用 C語言 搭建TCP服務

    2024年02月16日
    瀏覽(28)
  • mqtt服務器搭建與qt下的mqtt客戶端實現

    mqtt服務器搭建與qt下的mqtt客戶端實現

    ??MQTT(Message Queuing Telemetry Transport,消息隊列遙測傳輸協(xié)議),是一個基于客戶端-服務器的消息發(fā)布/訂閱傳輸協(xié)議。MQTT協(xié)議是輕量、簡單、開放和易于實現的,這些特點使它適用范圍非常廣泛。在很多情況下,包括受限的環(huán)境中,如:機器與機器(M2M)通信和物聯(lián)網(Io

    2024年02月06日
    瀏覽(26)
  • ESP8266 ArduinoIDE 搭建web服務器與客戶端開發(fā)

    ESP8266 ArduinoIDE 搭建web服務器與客戶端開發(fā)

    ? 此模式中,esp8266 會連接到指定 wifi 進行工作。 ? ?wifi 連接成功,esp8266 通過串口返回當前局域網 IP 此模式中,esp8266 會開啟一個指定名稱和密碼的熱點進行工作。 ? ? ?在這里改寫了根目錄,他會向客戶端發(fā)送一個按鈕的頁面,點擊即向 \\\"/LED\\\" 路由下發(fā)送 POST 請求。 由于

    2024年02月04日
    瀏覽(22)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包