Centos 7/8 搭建NFS Server


NFS Server

1. 安裝nfs-server

  # yum install -y nfs-utils

2. 創建NFS目錄

  # mkdir /nfs

3. 配置NFS目錄

 

  # echo "/nfs    *(rw,sync,no_root_squash)" >> /etc/exports

  參數說明: 

    rw 讀寫
    ro 只讀
    sync 數據直接寫入磁盤
    async 數據先寫入內存
    no_root_squash 對root用戶不壓制,在服務端都映射為服務端的root用戶
    root_squash 如果客戶端是用戶root操作,會被壓制成nobody用戶
    all_squash 不管客戶端的使用nfs的用戶是誰,都會壓制成nobody用戶
    nonuid=uid: 指定uid的值
    anongid=gid:指定gid的值

 

  # exportfs -rv  # 立即生效

4. 啟動NFS服務

  # systemctl enable --now nfs-server.service

  # showmount -e

 

 

NFS Client(方法一)

1. 安裝nfs-client

  # yum install -y nfs-utils

2. 創建掛載目錄

  # mkdir /var/nfs

3. 查看NFS Server目錄

  # showmount -e nfs-server-ip

4. 掛載NFS Server目錄

  # mount -t nfs nfs-server-ip:/nfs /var/nfs

 

NFS Client(方法二)

要實現開機自動掛載,通常將掛載配置信息直接寫入到 /etc/fstab文件中。
​autofs自動掛載服務是一種Linux系統守護進程,當檢測到用戶訪問一個尚未掛載的文件系統時,會自動根據配置文件進行掛載(動態掛載)。

 

1. 安裝autofs

  # yum install autofs

2. 創建掛載目錄

  # mkdir /var/nfs

3. 自動掛載NFS配置

  # echo "/var/nfs    /etc/auto.nfs" >> /etc/auto.master

  # echo "data -fstype=nfs nfs-server-ip:/nfs" >> /etc/auto.nfs

4. 啟動autofs服務

  # systemctl enable --now autofs.service


免責聲明!

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



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