1. 程式人生 > >手動搭建一個nfs服務器

手動搭建一個nfs服務器

localhost ash res 防火墻 進行 配置 輸出 rpcbind 目錄

  • 開放/nfs/shared目錄,供所有用戶查閱資料
  • 開放/nfs/upload目錄為172.16.12.0、24網段的數據上傳目錄,並將所有用戶及所屬的用戶組都映射為nfs-upload,其UID與GID均為300
  • 1:rpm沒有安裝包的先下載nfs-utils安裝包安裝,nfs的安裝和啟動
    安裝軟件包:yum -y install nfs-utils
    啟動nfs服務:systemctl start rpcbind nfs-server
    查看一下服務進程啟動沒有;
    [root@localhost ~]# ss -antl
    State Recv-Q Send-Q Local Address:Port Peer Address:Port

    LISTEN 0 128 :111 :
    LISTEN 0 128
    :20048 :
    LISTEN 0 128 :22 :
    LISTEN 0 100 127.0.0.1:25
    :
    LISTEN 0 128
    :58651 :
    LISTEN 0 64 :38560 :
    LISTEN 0 64
    :2049 :
    LISTEN 0 128 :::41899 :::
    LISTEN 0 128 :::111 :::

    LISTEN 0 128 :::20048 :::
    LISTEN 0 128 :::22 :::

    LISTEN 0 100 ::1:25 :::
    LISTEN 0 64 :::46558 :::

    LISTEN 0 64 :::2049 :::*
    查看到111和2049就可以確定服務器啟動了。
    2編輯etc/exportfs
    [root@localhost ~]# vim /etc/exports
    /nfs/shared 172.16.12.128(ro,sync)
    /nfs/upload 172.16.12.0(anongid=300,anonuid=30 )
    systemctl stop firewalld.service 關閉防火墻
    exportfs -vr 在不重啟的情況下啟動這個配置文件並在屏幕上顯示出來。
    root@localhost ~]# exportfs -vr
    /nfs/shared 172.16.12.128(ro,sync,wdelay,hide,no_subtree_check,sec=sys,secure,root_squash,no_all_squash)
    3顯示指定的NFS服務器上說有輸出的共享目錄,將主機的共享目錄掛載到客戶端的目錄裏面,
    root@localhost ~]# showmount -e
    Export list for localhost.localdomain:
    /nfs/shared 172.16.12.12
    進入到客戶端創建一個nfs/shared的目錄
    進行掛載root@localhost ~]#mount --t nfs SERVER:/nfs/shared /nfs/shared
    然後接下來進入到客戶端/nfs/shared就能讀取到主機共享目錄nfs/shared裏面的數據了。

    手動搭建一個nfs服務器