linux 兩台服務器共享目錄NFS實現


一、環境信息

服務器1:10.10.82.73        文件夾:/home/fileroot

服務器2:10.10.82.72       文件夾:/home/fileroot

將服務器1的/home/fileroot文件夾共享到服務器2的/home/fileroot文件夾。

 

要求兩個服務器都安裝有NFS服務。

 

yum -y install nfs*

 

二、服務器1設置

 

1、修改exports文件

vi /etc/exports

一般為空文件,添加以下內容

/home/fileroot *(insecure,rw,sync,no_root_squash)

*代表運行所有機器訪問,或者指定10.10.82.72 訪問

 

/home/fileroot 服務器1上要共享的文件夾

():內添加具體的參數,可添加的參數如下:

    ro:該主機對該共享目錄有只讀權限
    rw:該主機對該共享目錄有讀寫權限
    root_squash:客戶機用root用戶訪問該共享文件夾時,將root用戶映射成匿名用戶 ;
    no_root_squash:NFS服務器共享目錄用戶的屬性,客戶機用root訪問該共享文件夾時,不映射root用戶;
    all_squash 客戶機上的任何用戶訪問該共享目錄時都映射成匿名用戶
    anonuid 將客戶機上的用戶映射成指定的本地用戶ID的用戶
    anongid 將客戶機上的用戶映射成屬於指定的本地用戶組ID
    sync 資料同步寫入到內存與硬盤中
    async 資料會先暫存於內存中,而非直接寫入硬盤
    insecure 允許從這台機器過來的非授權訪問

 

 

2、設置NFS自啟動

chkconfig nfs on
    service nfs start

 

 #CentOS7:
    systemctl start nfs
    systemctl enable nfs

三、服務器2設置

1、設置NFS自啟動

chkconfig nfs on
    service nfs start

 

 #CentOS7:
    systemctl start nfs
    systemctl enable nfs

如遇到報錯

rpc.nfsd: writing fd to kernel failed: errno 111 (Connection refused)

 解決辦法:

1 #service rpcbind restart

2 #service nfs start

 

2、執行掛載語句

 

mount -t nfs 10.10.82.73:/home/fileroot/  /home/fileroot/

 

3、查看掛載結果

df -h

 

4、編輯啟動文件,將掛載命令設置為啟動自動執行

vi /etc/rc.local

添加之前執行的掛載語句:

mount -t nfs 10.10.82.73:/home/fileroot/  /home/fileroot/

 

【注意】

CentOS7開始,默認情況下開機是不執行/etc/rc.local文件的,需要授予執行權限,才能開機啟動執行此文件

chmod 777 /etc/rc.local

 

四、其他命令

1、服務器2取消掛載(取消掛載時,不能處於掛載目錄內):

umount /home/fileroot

2、服務器1查看以共享的目錄

showmount -e

3、服務器2查看服務器1共享目的目錄

showmount -e 10.10.82.73

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM