nfs
用於linux
主機訪問網路中其他
linux
主機上的共享資源。
nfs的原理是在客戶端上通過網路將遠端主機共享檔案系統以掛載
(mount)
的方式加入本機的檔案系統,之後的操作就如同在本機上一樣。
nfs
伺服器(
宿主機)
1.
安裝nfs
ubuntu上預設是沒有安裝nfs伺服器的,首先要安裝nfs服務程式:
$ sudo apt-get install nfs-kernel-server
(安裝nfs-kernel-server時,apt會自動安裝nfs-common和portmap)
這樣,宿主機就相當於nfs server。
1.伺服器端:sudo apt-get install portmap
2.伺服器端:sudo apt-get install nfs-kernel-server
3.客戶端:sudo apt-get install nfs-common
2.配置
nfs1)
配置portmap
$ sudo dpkg-reconfigure portmap
對should portmap be bound to the loopback address? 選n.
2)配置
/etc/hosts.deny
$ sudo gedit /etc/hosts.deny
(禁止任何host(主機)能和你的nfs伺服器進行nfs連線),加入:
### nfs daemons
portmap:all
lockd:all
mountd:all
rquotad:all
statd:all
3)配置
/etc/hosts.allow
$ sudo gedit /etc/hosts.allow
允許那些你想要的主機和你的nfs伺服器建立連線。下列步驟將允許任何ip位址以192.168.1開頭的主機(連線到nfs伺服器上),也可以指定特定的ip位址。
### nfs daemons
portmap: 192.168.1.
lockd: 192.168.1.
rquotad: 192.168.1.
mountd: 192.168.1.
statd: 192.168.1.
藍色文字可略過
起用保護機制
上面設定了只要在
192.168.1.
*這個網段的所有
ip位址使用者都可以訪問共享目錄,但我只想讓乙個
ip位址訪問,比如
192.168.1.101
那麼就可以這樣設定了。
可以通過設定
/etc/hosts.deny
和/etc/hosts.allow
檔案來限制網路服務的訪問許可權。
***/etc/hosts.deny***
portmap:all
lockd:all
mountd:all
rquotad:all
statd:all
***/etc/hosts.allow***
portmap:192.168.1.101
lockd:192.168.1.101
mountd:192.168.1.101
rquotad:192.168.1.101
statd:192.168.1.101
同時使用這兩個檔案就會使得只有ip為
192.168.1.101
的機器使用
nfs服務。你的
target board的ip
位址設定為
192.168.1.101
,這樣就可以了。
/etc/hosts.deny
和/etc/hosts.allow
設定對portmap
的訪問.
採用這兩個配置檔案有點類似
"mask"
的意思.
現在/etc/hosts.deny
中禁止所有使用者對
portmap
的訪問.
再在/etc/hosts.allow
中允許某些使用者對
portmap
的訪問。
4
)重啟portmap daemon
每次對/etc/hosts.deny
和/etc/hosts.allow
兩檔案的修改後都要重啟
portmap daemon
。不然修改無效。
$ sudo /etc/init.d/portmap restart
5)配置
/etc/exports
nfs掛載目錄及許可權由/etc/exports檔案定義。
$sudo gedit /etc/exports
比如我要將將我的home目錄中的/home/lin/nfsshare目錄讓192.168.1.*的ip共享, 則在該檔案末尾新增下列語句:
/home/lin/nfsshare 192.168.1.*(rw,sync,no_root_squash)
然後儲存退出。
/home/lin/nfsshare
就表示共享目錄,當然,你可以隨便換成自己喜歡的目錄。
192.168.1.*:
前面三位是你主機(
nfs客戶端)的
ip位址(本機終端
ifconfig
命令就可以獲得本機的
ip位址)。rw:
讀/寫許可權,唯讀許可權的引數為ro;
sync
:資料同步寫入記憶體和硬碟,也可以使用
async
,此時資料會先暫存於記憶體中,而不立即寫入硬碟。
no_root_squash
:nfs
伺服器共享目錄使用者的屬性,如果使用者是
root
,那麼對於這個共享目錄來說就具有
root
的許可權。
6)
重啟nfs
服務
$ sudo /etc/init.d/nfs-kernel-server restart
7)showmount檢視共享目錄
showmout
-a :這個引數是一般在nfs server上使用,是用來顯示已經mount上本機nfs目錄的clinet機器。
-e :顯示指定的nfs server上export出來的目錄。
ubuntu18 安裝配置nfs
1.新建目錄 mkdir home nfs dir 2.安裝nfs服務 sudo apt install nfs kernel server 3.修改配置檔案 vim etc exports 在最後新增 home nfs dir rw,sync,no root squash,no subtree c...
nfs安裝配置
nfs安裝於配置 2.配置nfs vi etc exports home nfs rw,sync,no root squash 3.啟動nfs etc init.d nfs kernel server start 啟動nfs etc init.d nfs kernel server stop 停止n...
NFS安裝配置
環境概述 將web伺服器a和b的目錄 data wwwroot配置為 共享目錄,共享目錄所屬使用者組為www 伺服器a nfs服務端 ip 172.16.28.123 yum y install nfs utils rpcbind useradd www 檢視www的使用者的uid和gid,和客戶端...