歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux與Linux之間共享目錄設置

Linux與Linux之間共享目錄設置

日期:2017/2/28 13:57:45   编辑:Linux教程

Linux與Linux之間共享目錄設置

1. 【修改server端】修改/etc/export文件,加入:
/home/user/source *(rw)

/home/user/source *(rw,sync,no_wdelay,insecure_locks,no_root_squash)

/home/wyq/share 192.* (insecure,rw,sync,no_root_squash)

exports配置文件說明
/home/user/source 共享的目錄
192.* 允許訪問的主機IP, 如果不能確定 ,請使用 * (在Fedora 20實驗中表示任意IP時,不用加星號,否則nfs會無法啟動)
insecure 一個安全選項, 如果nfs服務端口號小於1024則可以不添加這個選項, 否則不添加的話, 是無法訪問的.其他主機訪問的話就會被拒絕.
rw 共享目錄的權限,rw 是可讀寫的權限,只讀的權限是ro.
sync 同步的選項, 可選的還有 async. sync是不使用緩存,隨時寫入同步, async是使用緩存的.
no_root_squash NFS服務共享的目錄的屬性, 如果用戶是root, 那麼對這個目錄就有root的權限.

2. 【server端】執行如下命令使新增的共享生效
$/etc/rc.d/init.d/nfs restart

3. 【客戶端】執行如下命令掛載共享:
sudo mount -t nfs zxhost001:/home/user/share /u01/user/mount_point

mount -t nfs -o rw 192.168.10.94:/home/user/source /home/user/target
注意: 開啟兩台主機之間的NFS防火牆

4. 【客戶端】取消掛載
umount /u01/user/mount_point

5. 【客戶端】開機後自動掛載
如果想在開機後不手動掛載共享目錄,那麼需要設置開機自動掛載。

mount_AtoB.sh文件內容,其中passwordxxx為192.168.10.94的密碼:

set fileformat=unix
#!bin/bash
mount -t nfs -o rw 192.168.10.94:/home/user/source /home/user/target <<EOF
passwordxxx
EOF

1)、修改mount_AtoB.sh的密碼
2)、將mount_AtoB.sh文件放到/home/user目錄下
3)、改變文件的執行權限,執行如下命令:
chmod 777 mount_AtoB.sh
4)、將文件加入到啟動文件中:
$ echo /home/user/mount_94to93.sh >> /etc/rc.d/rc.local

Copyright © Linux教程網 All Rights Reserved