Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> 關於Linux

用 NFS 在 Linux 上配置共享磁碟

場景:共享端為 192.168.1.100,對外分享目錄 /opt/resource/,僅允許 192.168.1.* 網段存取。

一、服務端設定

編輯 /etc/exports,加入:

/opt/resource 192.168.1.*(rw,async,no_root_squash)

讓設定生效:

exportfs -a

為了方便防火牆放行,先把 NFS 相關埠號固定下來。編輯 /etc/sysconfig/nfs,取消下列行的註解:

RQUOTAD_PORT=875
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892

重啟服務:

service nfs restart

防火牆需要放行 portmap(111)、nfsd(2049)、rquotad(875)、mountd(892)與 lockd(32803/32769):

-A INPUT -p tcp --dport 111 -j ACCEPT
-A INPUT -p udp --dport 111 -j ACCEPT
-A INPUT -p tcp --dport 2049 -j ACCEPT
-A INPUT -p udp --dport 2049 -j ACCEPT
-A INPUT -p tcp --dport 875 -j ACCEPT
-A INPUT -p udp --dport 875 -j ACCEPT
-A INPUT -p tcp --dport 892 -j ACCEPT
-A INPUT -p udp --dport 892 -j ACCEPT
-A INPUT -p tcp --dport 32803 -j ACCEPT
-A INPUT -p udp --dport 32769 -j ACCEPT

二、用戶端掛載

假設掛載端為 192.168.1.200,要掛到 /opt/web/resource/:

mount -t nfs 192.168.1.100:/opt/resource /opt/web/resource

若要開機自動掛載,在 /etc/fstab 補上一行:

192.168.1.100:/opt/resource  /opt/web/resource  nfs  defaults  0  0

作者:surelei

Copyright © Linux教程網 All Rights Reserved