ubuntu搭建nfs伺服器

2021-08-27 06:03:24 字數 2372 閱讀 5969

由於工作中需要兩台伺服器之間共享一塊硬碟空間,因此準備搭建乙個nfs伺服器,下面會為大家闡述安裝步驟和用php去訪問共享分割槽

nfs(netword file system),網路檔案系統,是unix系統之間實現磁碟檔案共享的一種方法,它支援應用程式在客戶端通過網路訪問位於伺服器磁碟中資料的一種檔案系統協議。(ps:

我理解的nfs呢,是一種c/s的架構,server共享目錄給client使用)

許可權問題,客戶端與伺服器端必須具備相同的帳號(uid一致)才能夠訪問共享的目錄和檔案。

nfs執行在sun的rpc(remote procedure call, 遠端過程呼叫)基礎上, rpc定義了一種與系統無關的方法來實現程序間通訊. 由此, nfs server也可以看作是rpc server.

正因為nfs是乙個rpc服務程式, 所以在使用它之前, 先要對映好埠——通過portmap設定. 比如: 某個nfs client發起nfs服務請求時, 它需要先得到乙個埠(port). 所以它先通過portmap得到port number.

sudo apt-get install nfs-kernel-server

安裝完nfs-kernel-server後,系統會自動為我們安裝好portmap(埠對映器)和nfs-common(客戶端軟體,用於測試)

sudo vim /etc/exports

注釋掉一條配置語句如下:

#options = "-i 127.0.0.1"

重啟portmap(ps:真bug,portmap竟然不支援直接restart)

sudo  service  portmap  stop

sudo service portmap start

sudo vim  /etc/exports
乙個典型的共享目錄配置**如下:

/home/xiaoyi  *(rw,sync,no_subtree_check)

/home :伺服器端需要共享的檔案目錄(可自己任意指定)

* : 容許訪問的計算機,可以是以下內容:

單個機器=>乙個完整的ip位址,乙個全限定網域名稱(能夠被伺服器解析),主機名(能夠被伺服器解析)

萬用字元指定的主機名,ip位址中不允許使用萬用字元,*表示允許所有能訪問到server的主機來連線共享目錄

():共享選項

rw:客戶端擁有讀寫許可權(ro:**只有讀許可權)

sync:同步寫入資料到記憶體和硬碟中

no_subtree_check:不檢測子目錄許可權

root_squash:如果客戶端使用root許可權訪問共享目錄,則會被認為是匿名使用者(許可權縮小)

no_root_squash:如果客戶端使用root許可權訪問共享目錄,許可權依舊為root

配置完成後,重啟nfs-server服務

sudo  /etc/init.d/nfs-kernel-server  restart

sudo apt-get install nfs-common

同樣的,apt會自動幫你安裝好portmap

sudo vim /etc/default/portmap
注釋掉一條命令如下:

#options="-i 127.0.0.1"
重啟portmap

sudo service portmap stop

sudo service portmap start

sudo  mount  server_ip:/share_nfs_directory  client_nfs_directory

sudo  umonut  client_nfs_directory

<?php

//1.測試建立目錄

$temp_dir = "/srv/www/nfs/image";

if(mkdir($temp_dir))

else

//2.測試建立檔案

$temp_file = $temp_dir."/ceshi.txt";

if(!$fp = fopen($temp_file, 'a'))

$content = "hello world!\n";

if(fwrite($fp, $content))

else

fclose($fp);

Ubuntu搭建NFS伺服器

sudo apt get install nfs kernel servernfs允許掛載的目錄和許可權需要在檔案 etc exports 這個檔案是使用上述命令安裝nfs kernel server後才生成的 中進行定義。在 etc exports的末尾新增 home liyihai rw,syn...

Ubuntu下搭建nfs伺服器

nfs分伺服器和客戶機,當使用遠端檔案時只要用mount命令就可把遠端nfs伺服器 ubuntu系統 上的檔案系統掛載在本地檔案系統之下,操作遠端檔案與操作本地檔案沒有不同。nfs伺服器所共享檔案或目錄記錄在 etc exports檔案中。嵌入式linux開發中,會經常使用nfs,目標系統 開發板a...

NFS 伺服器搭建

首先在vmware上搭建兩個系統我選擇的兩個ubuntu系統 ubuntu1 ip位址192.168.1.49 ubuntu2 ip位址192.168.1.51 兩個系統分別執行下面的命令 sudo apt get install nfs kernel server 安裝 nfs 伺服器端 sudo...