Linux之NFS網路文件系統

来源:https://www.cnblogs.com/caicairui/archive/2018/02/17/8452261.html
-Advertisement-
Play Games

NFS(Network File System)即網路文件系統,是FreeBSD支持的文件系統中的一種,它允許網路中的電腦之間通過TCP/IP網路資源共用。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS伺服器上的文件,就像訪問本地文件一樣。 1、好處 (1)節省本地存儲空間, ...


  NFS(Network File System)即網路文件系統,是FreeBSD支持的文件系統中的一種,它允許網路中的電腦之間通過TCP/IP網路資源共用。在NFS的應用中,本地NFS的客戶端應用可以透明地讀寫位於遠端NFS伺服器上的文件,就像訪問本地文件一樣。

1、好處

(1)節省本地存儲空間,將常用的數據存放在一臺NFS伺服器上且可以通過網路訪問,那麼本地終端將可以減少自身存儲空間的使用。

(2)用戶不需要在網路中的每台電腦上都建有Home目錄,Home目錄可以放在NFS伺服器上且可以在網路上被訪問使用。

(3)一些存儲設備如軟碟機、CDROM和ZIP等都可以在網路上被別的機器使用。這可以減少整個網路上移動介質設備的數量。

2、組成

NFS體系至少有兩個主要部分:一臺NFS伺服器和若幹台客戶機,如圖所示

客戶機可以通過TCP/IP網路遠程訪問存放在NFS上的數據。

NFS實現是通過RPC服務來實現的

實現過程:

(1)NFS RPC的主要功能是記錄每個NFS功能所對應的埠號,並將信息傳遞給請求數據的NFS客戶端,從而實現數據的傳輸。

(2)NFS服務啟動時會隨機取用數個埠,並主動向RPC服務註冊取用的相關埠信息,RPC服務就知道每個埠對應的NFS功能了,然後RPC會用固定的埠(111)來監聽NFS客戶端的請求,將正確的NFS埠傳給NFS的客戶端

服務啟動順序:RPC--》NFS

3、伺服器端安裝,配置過程

(1)檢查是否安裝NFS RPC服務

[root@localhost ~]# rpm -qa nfs-utils rpcbind
[root@localhost ~]# yum install nfs-utils rpcbind -y
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                   | 3.7 kB     00:00     
extras                                                 | 3.4 kB     00:00     
extras/primary_db                                      |  30 kB     00:00     
updates                                                | 3.4 kB     00:00     
Resolving Dependencies
--> Running transaction check
---> Package nfs-utils.x86_64 1:1.2.3-75.el6_9 will be installed
--> Processing Dependency: nfs-utils-lib >= 1.1.0-3 for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libtirpc >= 0.2.1-11 for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: keyutils >= 1.4-4 for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: python-argparse for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libgssglue.so.1(libgssapi_CITI_2)(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libgssglue for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libevent for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libtirpc.so.1()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libnfsidmap.so.0()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libgssglue.so.1()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
--> Processing Dependency: libevent-1.4.so.2()(64bit) for package: 1:nfs-utils-1.2.3-75.el6_9.x86_64
---> Package rpcbind.x86_64 0:0.2.0-13.el6_9.1 will be installed
--> Running transaction check
---> Package keyutils.x86_64 0:1.4-5.el6 will be installed
---> Package libevent.x86_64 0:1.4.13-4.el6 will be installed
---> Package libgssglue.x86_64 0:0.1-11.el6 will be installed
---> Package libtirpc.x86_64 0:0.2.1-13.el6_9 will be installed
---> Package nfs-utils-lib.x86_64 0:1.1.5-13.el6 will be installed
---> Package python-argparse.noarch 0:1.2.1-2.1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================================
 Package              Arch        Version                  Repository    Size
==============================================================================
Installing:
 nfs-utils            x86_64      1:1.2.3-75.el6_9         updates      336 k
 rpcbind              x86_64      0.2.0-13.el6_9.1         updates       51 k
Installing for dependencies:
 keyutils             x86_64      1.4-5.el6                base          39 k
 libevent             x86_64      1.4.13-4.el6             base          66 k
 libgssglue           x86_64      0.1-11.el6               base          23 k
 libtirpc             x86_64      0.2.1-13.el6_9           updates       82 k
 nfs-utils-lib        x86_64      1.1.5-13.el6             base          71 k
 python-argparse      noarch      1.2.1-2.1.el6            base          48 k

Transaction Summary
==============================================================================
Install       8 Package(s)

Total download size: 716 k
Installed size: 2.0 M
Downloading Packages:
(1/8): keyutils-1.4-5.el6.x86_64.rpm                   |  39 kB     00:00     
(2/8): libevent-1.4.13-4.el6.x86_64.rpm                |  66 kB     00:00     
(3/8): libgssglue-0.1-11.el6.x86_64.rpm                |  23 kB     00:00     
(4/8): libtirpc-0.2.1-13.el6_9.x86_64.rpm              |  82 kB     00:00     
(5/8): nfs-utils-1.2.3-75.el6_9.x86_64.rpm             | 336 kB     00:00     
(6/8): nfs-utils-lib-1.1.5-13.el6.x86_64.rpm           |  71 kB     00:00     
(7/8): python-argparse-1.2.1-2.1.el6.noarch.rpm        |  48 kB     00:00     
(8/8): rpcbind-0.2.0-13.el6_9.1.x86_64.rpm             |  51 kB     00:00     
------------------------------------------------------------------------------
Total                                         1.1 MB/s | 716 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libgssglue-0.1-11.el6.x86_64                               1/8 
  Installing : libtirpc-0.2.1-13.el6_9.x86_64                             2/8 
  Installing : rpcbind-0.2.0-13.el6_9.1.x86_64                            3/8 
  Installing : python-argparse-1.2.1-2.1.el6.noarch                       4/8 
  Installing : libevent-1.4.13-4.el6.x86_64                               5/8 
  Installing : keyutils-1.4-5.el6.x86_64                                  6/8 
  Installing : nfs-utils-lib-1.1.5-13.el6.x86_64                          7/8 
  Installing : 1:nfs-utils-1.2.3-75.el6_9.x86_64                          8/8 
  Verifying  : rpcbind-0.2.0-13.el6_9.1.x86_64                            1/8 
  Verifying  : libtirpc-0.2.1-13.el6_9.x86_64                             2/8 
  Verifying  : keyutils-1.4-5.el6.x86_64                                  3/8 
  Verifying  : libevent-1.4.13-4.el6.x86_64                               4/8 
  Verifying  : nfs-utils-lib-1.1.5-13.el6.x86_64                          5/8 
  Verifying  : libgssglue-0.1-11.el6.x86_64                               6/8 
  Verifying  : 1:nfs-utils-1.2.3-75.el6_9.x86_64                          7/8 
  Verifying  : python-argparse-1.2.1-2.1.el6.noarch                       8/8 

Installed:
  nfs-utils.x86_64 1:1.2.3-75.el6_9     rpcbind.x86_64 0:0.2.0-13.el6_9.1    

Dependency Installed:
  keyutils.x86_64 0:1.4-5.el6          libevent.x86_64 0:1.4.13-4.el6         
  libgssglue.x86_64 0:0.1-11.el6       libtirpc.x86_64 0:0.2.1-13.el6_9       
  nfs-utils-lib.x86_64 0:1.1.5-13.el6  python-argparse.noarch 0:1.2.1-2.1.el6 

Complete!
[root@localhost ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64

(2)安裝完成後,啟動相關服務

[root@localhost ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@localhost ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind (pid  1958) is running...
[root@localhost ~]# /etc/init.d/nfs 
anaconda-ks.cfg     .bashrc             install.log.syslog
.bash_logout        .cshrc              .tcshrc
.bash_profile       install.log         
[root@localhost ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
[root@localhost ~]# rpcinfo -p localhost
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
[root@localhost ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
[root@localhost ~]# rpcinfo -p localhost
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100005    1   udp  53776  mountd
    100005    1   tcp  45705  mountd
    100005    2   udp  59195  mountd
    100005    2   tcp  37339  mountd
    100005    3   udp  51079  mountd
    100005    3   tcp  42701  mountd
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  55657  nlockmgr
    100021    3   udp  55657  nlockmgr
    100021    4   udp  55657  nlockmgr
    100021    1   tcp  56873  nlockmgr
    100021    3   tcp  56873  nlockmgr
    100021    4   tcp  56873  nlockmgr

讓RPC、NFS服務開機自啟,在實際生產環境中都會將配置放在/etc/rc.local下麵

[root@localhost ~]# vim /etc/rc.local 
[root@localhost ~]# cat /etc/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/etc/init.d/rpcbind start
/etc/init.d/nfs start

(3)配置服務端NFS配置文件/etc/exports

[root@localhost ~]# cat /etc/exports 
##nfs server created by cairui at 2018-2-17
/home/cairui 192.168.181.128(rw)
[root@localhost ~]# /etc/init.d/nfs 
anaconda-ks.cfg     .bashrc             install.log.syslog
.bash_logout        .cshrc              .tcshrc
.bash_profile       install.log         .viminfo
[root@localhost ~]# /etc/init.d/nfs reload
[root@localhost ~]# /etc/init.d/nfs restart
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Shutting down RPC idmapd:                                  [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

4、客戶端配置

[root@localhost ~]# rpm -qa | grep nfs
nfs-utils-lib-1.1.5-13.el6.x86_64
nfs-utils-1.2.3-75.el6_9.x86_64
[root@localhost ~]# rpm -qa | grep rpc
rpcbind-0.2.0-13.el6_9.1.x86_64
libtirpc-0.2.1-13.el6_9.x86_64
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[root@localhost ~]# /etc/init.d/rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@localhost ~]# /etc/init.d/rpcbind status
rpcbind (pid  1463) is running...
[root@localhost ~]# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
[root@localhost ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
[root@localhost ~]# showmount -e 192.168.181.129
Export list for 192.168.181.129:
/home/cairui 192.168.181.128
[root@localhost ~]# ping 192.168.181.129
PING 192.168.181.129 (192.168.181.129) 56(84) bytes of data.
64 bytes from 192.168.181.129: icmp_seq=1 ttl=64 time=0.348 ms
64 bytes from 192.168.181.129: icmp_seq=2 ttl=64 time=0.706 ms
64 bytes from 192.168.181.129: icmp_seq=3 ttl=64 time=0.512 ms
^C
--- 192.168.181.129 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2760ms
rtt min/avg/max/mdev = 0.348/0.522/0.706/0.146 ms
[root@localhost ~]# iptables -F
[root@localhost ~]# showmount -e 192.168.181.129
Export list for 192.168.181.129:
/home/cairui 192.168.181.128

客戶端進行NFS掛載

[root@localhost ~]# mount -t nfs 192.168.181.129:/home/cairui /mnt
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.4G   16G   9% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             190M   30M  150M  17% /boot
192.168.181.129:/home/cairui
                       18G  809M   16G   5% /mnt

5、測試

服務端

[root@localhost ~]# cd /home/cairui/
[root@localhost cairui]# touch 1.txt
[root@localhost cairui]# ls -ll /home/cairui/
total 0
-rw-r--r--. 1 root root 0 Feb 17 17:15 1.txt
[root@localhost cairui]# ls -ld /home/cairui/
drwx------. 2 cairui cairui 4096 Feb 17 17:15 /home/cairui/
[root@localhost cairui]# chmod 777 /home/cairui/
[root@localhost cairui]# ls -ld /home/cairui/
drwxrwxrwx. 2 cairui cairui 4096 Feb 17 17:15 /home/cairui/

 [root@localhost cairui]# mkdir nfs

客戶端

[root@localhost ~]# cd /mnt/
-bash: cd: /mnt/: Permission denied
[root@localhost ~]# ls -ll /mnt/
ls: cannot open directory /mnt/: Permission denied
[root@localhost ~]# cd /m
media/ mnt/   
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# ls
1.txt
[root@localhost mnt]# ls
1.txt  nfs
[root@localhost mnt]# 

八.啟動自動掛載nfs文件系統

格式:<server>:<remote/export>

      </local/directory> nfs <option> 0 0

#vim /etc/fstab

最後一行為後加的

保存退出,重啟系統


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 1.PreparedStatement對象 PreparedStatement對象繼承Statement對象,它比Statement對象更強大,使用起來更簡單 1. Statement對象編譯SQL語句時,如果SQL語句有變數,就需要使用分隔符來隔開,如果變數非常多,就會使SQL變得非常複雜。 Pr ...
  • 一、爬蟲之requests a、介紹:使用requests可以模擬瀏覽器的請求,比起之前用到的urllib,requests模塊的api更加便捷(本質就是封裝了urllib3) b、註意:requests發送請求是將網頁內容下載來以後,並不會執行js代碼,這需要我們自己分析目標站點然後發起新的req ...
  • 引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中國電腦學會(CCF)發起的"電腦職業資格認證"考試,針對電腦軟體開發、軟體測試、信息管理等領域的專業人士進行能力認證。認證對象是從事或將要從事IT領域專業技術與技術管理人 ...
  • 本篇先寫一些基礎 今天看到一個cas單點登錄的源碼,搞環境就廢了大半時間 《SSO CAS單點系列》 參考了這篇博客里的配置,終於可以運行了 然後。。。。。。。。。。 我發現看不懂源碼!!!,果然還是太菜了。 好了我們知道web項目是根據web.xml的servlet標簽來實例化的, 看了下他的項目 ...
  • 引言:CSP(http://www.cspro.org/lead/application/ccf/login.jsp)是由中國電腦學會(CCF)發起的"電腦職業資格認證"考試,針對電腦軟體開發、軟體測試、信息管理等領域的專業人士進行能力認證。認證對象是從事或將要從事IT領域專業技術與技術管理人 ...
  • 1、 Python入門導學 1.1 Python概念 Python(英國發音:/ˈpaɪθən/ 美國發音:/ˈpaɪθɑːn/) 是一個高層次的結合瞭解釋性、編譯性、互動性和麵向對象的腳本語言。 Python 的設計具有很強的可讀性,相比其他語言經常使用英文關鍵字,其他語言的一些標點符號,它具有比 ...
  • 本文為原創,轉載請註明出處 1.前言 .net平臺下導出word文件還可以使用Microsoft.Office.Interop和NPOI,但是這兩者都有缺點,微軟的Office.Interop組件需要程式運行的主機上安裝office,至於NPOI,由於長期無人維護,BUG眾多,各種對象和屬性名的命名 ...
  • 前言 前幾篇博客筆者介紹了maven項目的入門程式,以及相關的命令的作用以及生命周期,接下來筆者就介紹一下如何使用eclipse構建maven項目,以便筆者之後的複習,也作為和大家交流的內容,有錯請指出,筆者經常博客線上,如果喜歡,請推薦! 一、maven項目構建 1.1m2e插件的安裝 1.1.1 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...