Linux安裝NFS伺服器
阿新 • • 發佈:2020-10-20
安裝Linux系統,這裡是CentOS7,操作全程在root下進行,關閉防火牆和SELinux。
新增新的硬碟
fdisk -l #檢視硬碟狀態 Disk /dev/sdb: 3298.5 GB, 3298534883328 bytes, 6442450944 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes fdisk /dev/sdb #對磁碟進行操作 Command (m for help): m # 根據提示新增新的分割槽 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition g create a new empty GPT partition table G create an IRIX (SGI) partition table l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) 操作完成後按“w”儲存退出。 #對分割槽進行格式化,此處為xfs格式,還有ext4、ext3等 mkfs -t xfs /dev/sdb1
建立將要作為NFS分享的資料夾:mkdir /nfs
,更改歸屬組與使用者chown -R root.root /nfs
掛載硬碟:mount /dev/sdb1 /nfs
永久儲存掛載點
vi /etc/fstab
#填入下面的內容
/dev/sdb1 /nfs xfs defaults 0 0
#儲存退出,重啟機器
安裝NFS服務
yum install -y nfs-utils rpcbind #設定開機自啟 systemctl enable rpcbind systemctl enable nfs-server # 編輯exports $ vi /etc/exports # 輸入以下內容(格式:FS共享的目錄 NFS客戶端地址1(引數1,引數2,...) 客戶端地址2(引數1,引數2,...)) $ /nfs 192.168.2.0/24(rw,async,no_root_squash) #如果設定為 /nfs *(rw,async,no_root_squash) 則對所以的IP都有效
- 常用選項:
- ro:客戶端掛載後,其許可權為只讀,預設選項;
- rw:讀寫許可權;
- sync:同時將資料寫入到記憶體與硬碟中;
- async:非同步,優先將資料儲存到記憶體,然後再寫入硬碟;
- Secure:要求請求源的埠小於1024
- 使用者對映:
- root_squash:當NFS客戶端使用root使用者訪問時,對映到NFS伺服器的匿名使用者;
- no_root_squash:當NFS客戶端使用root使用者訪問時,對映到NFS伺服器的root使用者;
- all_squash:全部使用者都對映為伺服器端的匿名使用者;
- anonuid=UID:將客戶端登入使用者對映為此處指定的使用者uid;
- anongid=GID:將客戶端登入使用者對映為此處指定的使用者gid
# 檢視nfs服務端資訊
$ nfsstat -s
# 檢視nfs客戶端資訊
$ nfsstat -c