close

NFS就像是windows的網方一樣,

NFS client可以藉由掛載的方式使用NFS Server上的空間.

以下指令請使用root權限sudo來執行

 

Server安裝

yum install -y nfs-utils nfs-utils-lib

建立一個分享的目錄+開啟權限

mkdir /var/sharedNFS

chmod -R 777 /var/sharedNFS

編輯設定檔->哪個目錄要分享與相關權限

vi /etc/exports

/var/sharedNFS 192.168.30.31(rw,sync,no_root_squash,no_subtree_check)
/var/sharedNFS 192.168.30.32(rw,sync,no_root_squash,no_subtree_check)

每次修改exports都要執行下面的指令

exportfs -a

關閉防火牆 (我懶了,直接關掉)

service iptables stop

chkconfig iptables off

如果要加入規則,請參考 

https://mcdee.com.au/tutorial-configure-iptables-for-nfs-server-on-centos-6/   or

http://blog.xuite.net/tolarku/blog/298104183-Linux+NFS+%E6%AA%94%E6%A1%88%E5%88%86%E4%BA%AB+-+CentOS+6.6

設定服務啟動

chkconfig nfs on 

service rpcbind start

service nfs start

 

Client安裝

yum install -y nfs-utils nfs-utils-lib

永久建立掛載的目標目錄

mkdir -p /mnt/nfs/sharedNFS

掛載

mount 192.168.30.11:/var/sharedNFS /mnt/nfs/sharedNFS

檢查磁碟,便可知是否有掛載成功

df -h

192.168.30.11:/var/sharedNFS                      3.9G  659M  3.0G  18% /mnt/nfs/sharedNFS
 

mount

/dev/mapper/vg_template-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.30.11:/var/sharedNFS on /mnt/nfs/sharedNFS type nfs (rw,vers=4,addr=192.168.30.11,clientaddr=192.168.30.32)

 

確保重開機後還是掛載狀態,在fstab加入一行(如果是server重啟,還是得手動掛載,所以推薦另一個作法,參考使用動態載入 autofs )

vi /etc/fstab

192.168.30.11:/var/sharedNFS  /mnt/nfs/sharedNFS   nfs      auto,noatime,nolock,bg,nfsvers=3,intr,tcp,actimeo=1800 0 0

 

測試的話就在client寫個檔看看就知道囉
 

參考

https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nfs-mount-on-centos-6

http://www.phpini.com/linux/rhel-centos-7-install-nfs-server

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 abcg5 的頭像
    abcg5

    Aaron Yang

    abcg5 發表在 痞客邦 留言(0) 人氣()