在 CentOS 7.x 架設 NFS Server

因為要分享檔案給內部區域網路使用,所以架設了 NFS Server。
參考網站:
鳥哥的 Linux 私房菜 — NFS 伺服器
CentOS 7 NFS服务器和客户端设置 – 阿泰的菜园
How to setup NFS Server on CentOS 7 / RHEL 7 / Fedora 22

NFS Server IP: 192.168.1.13
1. 在 CentOS 7.x 下安裝
# yum install nfs-utils

2. 建立要分享的目錄設定檔 /etc/exports
# cat /etc/exports
# 分享目錄 允許連線來源(權限)
# ro 唯讀
# async 非同步寫入到硬碟
# no_root_squash 使用 root 身份連線
/home/test 192.168.1.0/24(ro,async,no_root_squash)[@more@]3. 之後如果有重新修改 /etc/exports 檔案時,不用重新啟動 NFS Server,只要執行下面指令即可!
# /usr/sbin/exportfs -arv
選項與參數:
-a :全部掛載(或卸載) /etc/exports 檔案內的設定
-r :重新掛載 /etc/exports 裡面的設定,此外,亦同步更新 /etc/exports
        及 /var/lib/nfs/xtab 的內容!
-u :卸載某一目錄
-v :在 export 的時候,將分享的目錄顯示到螢幕上!

4. 在 NFS Server 上,啟動 SELiux 放行規定
# setsebool -P nfs_export_all_rw on
# setsebool -P nfs_export_all_ro on

5. 執行 NFS Server
# systemctl restart nfs-server
# systemctl enable nfs-server

6. 檢查 NFS Server 的 Port 使用狀態
# netstat -tulnp| grep -E ‘(rpc|nfs)’
tcp        0      0 0.0.0.0:662             0.0.0.0:*               LISTEN      4612/rpc.statd
tcp        0      0 0.0.0.0:1002             0.0.0.0:*               LISTEN      6033/rpc.mountd
udp        0      0 0.0.0.0:111             0.0.0.0:*                           4558/rpcbind
udp        0      0 0.0.0.0:662             0.0.0.0:*                           4612/rpc.statd
udp        0      0 0.0.0.0:1002             0.0.0.0:*                           6033/rpc.mountd
udp     6144      0 0.0.0.0:913             0.0.0.0:*                           4558/rpcbind
udp        0      0 127.0.0.1:972           0.0.0.0:*                           4612/rpc.statd

7. 顯示出目前這部主機的 RPC 狀態
# /usr/sbin/rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  33438  status
    100024    1   tcp  45447  status
    100005    1   udp   1002  mountd
    100005    1   tcp   1002  mountd
    100005    2   udp   1002  mountd
    100005    2   tcp   1002  mountd
    100005    3   udp   1002  mountd
    100005    3   tcp   1002  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  58234  nlockmgr
    100021    3   udp  58234  nlockmgr
    100021    4   udp  58234  nlockmgr
    100021    1   tcp  33450  nlockmgr
    100021    3   tcp  33450  nlockmgr
    100021    4   tcp  33450  nlockmgr

8. 顯示 NFS Server 分享的資源
# /usr/sbin/showmount -e 127.0.0.1
Export list for 127.0.0.1:
/home/test 192.168.1.0/24
# /usr/sbin/showmount -e 192.168.1.13
Export list for 192.168.1.13:
/home/t850008 192.168.1.0/24

9. 在 Linux 下進行連線
建立目錄
# mkdir /mnt/nfs_test

進行掛載
# mount -t nfs 192.168.1.13:/home/test /mnt/nfs_test

取消掛載
# umount  /mnt/nfs_test