關于 Linux中NFS的一些筆記

      網友投稿 933 2025-03-31

      寫在前面

      學習K8s的Volumes相關,遇到NFS掛載,所以總結一下

      這里主要是實戰,理論很少。

      為了方便,部分地方使用了ansible,只用了shell模塊,不影響閱讀

      親近的人是不應該分開太久的。沒見面的時候朝思暮想,可一旦見到,是否雙方都會無可奈何地感覺到這條鴻溝呢?雖然可怕,但這也許更接近事實。——中島敦《山月記》

      NFS

      NFS(Network File System, 網絡文件系統),用來為客戶機提供共享使用的文件夾;

      將NFS服務器分享的目錄,掛載到本地機器當中,本地NFS的客戶端應用可以讀寫位于遠端NFS服務器上的文件,在客戶端端看起來,就像訪問本地文件一樣。

      關于 Linux中NFS的一些筆記

      NFS本身的服務并沒有提供數據傳遞的協議,而是通過使用

      RPC(遠程過程調用 Remote Procedure Call)來實現

      當NFS啟動后,會隨機的使用一些端口,NFS就會向RPC去注冊這些端口。RPC就會記錄下這些端口,RPC會開啟111端口。通過client端和sever端端口的連接來進行數據的傳輸。在啟動nfs之前,首先要確保rpc服務啟動。但是本質上還使用的TCP協議

      使用NFS網絡文件系統提供的共享目錄存儲數據時,我們需要在系統中部署一個NFSServer

      服務端

      下載服務需要的包,設置開機自啟

      ┌──[root@vms81.liruilongs.github.io]-[~] #軟件包:nfs-utils └─$yum -y install nfs-utils.x86_64 ┌──[root@vms81.liruilongs.github.io]-[~] #系統服務:nfs-server └─$systemctl enable nfs-server.service --now

      創建網絡共享文件夾,寫入測試信息

      ┌──[root@vms81.liruilongs.github.io]-[~] └─$mkdir -p /liruilong ┌──[root@vms81.liruilongs.github.io]-[/liruilong] └─$cd /liruilong/;echo `date` > liruilong.txt ┌──[root@vms81.liruilongs.github.io]-[/liruilong] └─$cd /liruilong/;cat liruilong.txt 2021年 11月 27日 星期六 21:57:10 CST

      exports配置文件解析 (服務端)

      語法: 文件夾路徑 客戶機地址(權限) 客戶機地址(權限)…

      PS1:

      /public 192.168.4.0/24

      ┌──[root@vms81.liruilongs.github.io]-[/liruilong] └─$cat /etc/exports ┌──[root@vms81.liruilongs.github.io]-[/liruilong] #任意主機可以訪問 (ro)只讀的方式 └─$echo "/liruilong *(rw,sync,no_root_squash)" > /etc/exports

      刷新配置exportfs -arv

      ┌──[root@vms81.liruilongs.github.io]-[/liruilong] └─$exportfs -arv exporting *:/liruilong ┌──[root@vms81.liruilongs.github.io]-[/liruilong] └─$showmount -e #查看當前機器服務列表 Export list for vms81.liruilongs.github.io: /liruilong * ┌──[root@vms81.liruilongs.github.io]-[/liruilong] └─$

      客戶端

      這里為了方便,使用了ansible

      然后我們需要在所有的使用節點安裝nfs-utils,然后掛載

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible node -m shell -a "yum -y install nfs-utils" ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible node -m shell -a "systemctl enable nfs-server.service --now"

      nfs共享文件測試:查看指定機器的共享文件列表:showmount -e vms81.liruilongs.github.io

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] #查看指定機器的共享文件列表 └─$ansible node -m shell -a "showmount -e vms81.liruilongs.github.io" 192.168.26.83 | CHANGED | rc=0 >> Export list for vms81.liruilongs.github.io: /liruilong * 192.168.26.82 | CHANGED | rc=0 >> Export list for vms81.liruilongs.github.io: /liruilong * ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$

      掛載方式

      手動掛載

      掛載測試,這里我們通過手動的方式掛載

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible node -m shell -a "mount vms81.liruilongs.github.io:/liruilong /mnt" 192.168.26.82 | CHANGED | rc=0 >> 192.168.26.83 | CHANGED | rc=0 >> ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible node -m shell -a "cd /mnt/;ls" 192.168.26.83 | CHANGED | rc=0 >> liruilong.txt 192.168.26.82 | CHANGED | rc=0 >> liruilong.txt

      查看掛載信息

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible node -m shell -a "df -h | grep liruilong" 192.168.26.82 | CHANGED | rc=0 >> vms81.liruilongs.github.io:/liruilong 150G 8.3G 142G 6% /mnt 192.168.26.83 | CHANGED | rc=0 >> vms81.liruilongs.github.io:/liruilong 150G 8.3G 142G 6% /mnt

      取消掛載

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible node -m shell -a "umount /mnt"

      當然,掛載方式還可以使用開機自動掛載,觸發掛載的方式

      開機自動掛載

      掛載機器環境準備

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "yum -y install nfs-utils" ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "systemctl enable nfs-utils --now" ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "showmount -e 192.168.26.81" 192.168.26.100 | CHANGED | rc=0 >> Export list for 192.168.26.81: /vdisk * /tmp * /liruilong *

      配置 etc/fstab

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "echo '192.168.26.81:/liruilong /mnt/nfsmount nfs defaults,_ netdev 0 0' >> /etc/fstab" 192.168.26.100 | CHANGED | rc=0 >> ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "cat /etc/fstab | grep liruilong" 192.168.26.100 | CHANGED | rc=0 >> 192.168.26.81:/liruilong /mnt/nfsmount nfs defaults,_netdev 0 0

      刷新配置:測試

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a " mkdir /mnt/nfsmount" ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a " mount -a" ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a " ls -l /mnt/nfsmount" 192.168.26.100 | CHANGED | rc=0 >> 總用量 4 -rw-r--r-- 1 root root 43 11月 27 21:57 liruilong.txt ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ll /liruilong/ 總用量 4 -rw-r--r-- 1 root root 43 11月 27 21:57 liruilong.txt

      觸發掛載

      由 autofs 服務提供的 “按需訪問” 機制,只要訪問掛載點,就會觸發響應,自動掛載指定設備;閑置超過時限(默認5分鐘)后,會自動卸載

      安裝需要的軟件包

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "yum -y install autofs" ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "systemctl enable autofs --now" 192.168.26.100 | CHANGED | rc=0 >> Created symlink from /etc/systemd/system/multi-user.target.wants/autofs.service to /usr/lib/systemd/system/autofs.service.

      查看配置文件位置

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "rpm -qc autofs" [WARNING]: Consider using the yum, dnf or zypper module rather than running 'rpm'. If you need to use command because yum, dnf or zypper is insufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of this message. 192.168.26.100 | CHANGED | rc=0 >> /etc/auto.master /etc/auto.misc /etc/auto.net /etc/auto.smb /etc/autofs.conf /etc/autofs_ldap_auth.conf /etc/sysconfig/autofs /usr/lib/systemd/system/autofs.service ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$

      配置文件編輯

      配置自動掛載需要修改兩個配置文件,一個/etc/auto.master

      /etc/auto.master這個配置文件為主配置文件,配置當前機器掛載的目錄的配置文件

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "echo '/liruilong /etc/auto.misc' >> /etc/auto.master" 192.168.26.100 | CHANGED | rc=0 >>

      這個配置文件為掛載目錄掛載的遠程目錄配置文件的掛載

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "echo 'sy -fstype=nfs 192.168.26.81:/liruilong ' >>/etc/auto.misc" 192.168.26.100 | CHANGED | rc=0 >>

      重啟服務

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "systemctl restart autofs" 192.168.26.100 | CHANGED | rc=0 >>

      觸發掛載,查看

      ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ls /liruilong/ liruilong.txt mGAX.23 work ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "ls /liruilong/sy" 192.168.26.100 | CHANGED | rc=0 >> liruilong.txt mGAX.23 work ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$ansible 192.168.26.100 -m shell -a "df -ah | grep liruilong" 192.168.26.100 | CHANGED | rc=0 >> 192.168.26.81:/liruilong 150G 8.5G 142G 6% /mnt/nfsmount /etc/auto.misc 0 0 0 - /liruilong 192.168.26.81:/liruilong 150G 8.5G 142G 6% /liruilong/sy ┌──[root@vms81.liruilongs.github.io]-[~/ansible] └─$

      Linux

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。

      上一篇:Word中題注功能的使用方法(word題注作用)
      下一篇:如何將excel表中的隱藏身份證號碼顯示出來(excel表格隱藏身份證)
      相關文章
      亚洲国产成人久久精品影视| 亚洲人成网站观看在线播放| 国产AV无码专区亚洲A∨毛片| 亚洲精品和日本精品| 亚洲av无码专区首页| 亚洲AV永久无码精品一福利 | 亚洲精品无码久久久久久| 亚洲欧美国产国产综合一区 | 亚洲AV日韩AV永久无码下载| 亚洲国产精彩中文乱码AV| 亚洲国产成人片在线观看无码 | 亚洲国产成人片在线观看无码| 亚洲AV无码精品无码麻豆| 亚洲av无码片在线播放| 亚洲精品在线观看视频| 中文字幕亚洲综合精品一区| 亚洲日产2021三区在线 | 亚洲字幕在线观看| 亚洲资源最新版在线观看| 精品亚洲456在线播放| 亚洲AV无码一区二区三区牲色| AV激情亚洲男人的天堂国语| 亚洲精品成人片在线观看| 中文字幕第13亚洲另类| 亚洲精品乱码久久久久久自慰| 久久久久久久久亚洲| 亚洲精品亚洲人成在线麻豆| 亚洲av一本岛在线播放| 亚洲精品无码高潮喷水A片软| 国产精品亚洲а∨天堂2021| 亚洲中久无码不卡永久在线观看| 亚洲中文字幕无码中文字在线| 亚洲av女电影网| 亚洲图片校园春色| 亚洲精品无码久久久久APP | 亚洲熟伦熟女新五十路熟妇| 久久夜色精品国产亚洲| 久久综合亚洲色一区二区三区| 亚洲精品第一国产综合野| 亚洲AV无码成人精品区日韩| 国产av无码专区亚洲国产精品|