NFS使用
本文分享自天翼云開(kāi)發(fā)者社區(qū)《NFS使用》,作者:2****m
安裝nfs
# nfs依賴(lài)于rpc,故需安裝nfs-utils rpcbind
yum install -y nfs-utils rpcbind
?
# 指定nfs監(jiān)聽(tīng)端口
vim /etc/sysconfig/nfs
?
RQUOTAD_PORT=30001
LOCKD_TCPPORT=30002
LOCKD_UDPPORT=30002
MOUNTD_PORT=30003
STATD_PORT=30004
?
# nfs依賴(lài)于rpc,故需先啟動(dòng)rpcbind,后啟動(dòng)nfs
systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs-server
systemctl enable nfs-server
?
# 查看rpc啟動(dòng)的監(jiān)聽(tīng)端口
/usr/sbin/rpcinfo -p localhost
?
# 查看nfs服務(wù)狀態(tài)
systemctl status nfs-server
掛載nfs
# 在nfs節(jié)點(diǎn)創(chuàng)建共享目錄
mkdir /nfsfile
# 賦權(quán)
chmod -Rf 777 /nfsfile
# 模擬寫(xiě)入數(shù)據(jù)
echo "welcome to localhost.com" > /nfsfile/readme
?
-----------------------------------------------
?
# 設(shè)置nfs目錄訪(fǎng)問(wèn)權(quán)限(rw:讀寫(xiě),sync:同時(shí)將數(shù)據(jù)寫(xiě)入內(nèi)存與硬盤(pán)中,保證數(shù)據(jù)不丟失)
vim /etc/exports
?
# 允許主機(jī)掛載nfs節(jié)點(diǎn)的/nfsfile目錄
/nfsfile 主機(jī)ip(rw,sync,root_squash)
/nfsfile2 主機(jī)ip(rw,sync,root_squash)
?
# 查看NFS服務(wù)器端共享的文件系統(tǒng)
showmount -e 主機(jī)ip
?
# 需在掛載nfs目錄的節(jié)點(diǎn)安裝并啟動(dòng)rpcbind、nfs
yum install -y nfs-utils rpcbind
?
# 啟動(dòng)rpcbind、nfs
systemctl start rpcbind
systemctl enable rpcbind
systemctl start nfs-server
systemctl enable nfs-server
?
# 掛載nfs(mount -t nfs SERVER:/path/to/sharedfs /path/to/mount_point)
mount -t nfs 主機(jī)ip:/nfsfile /nfsfile
掛載磁盤(pán)
# 以md10分區(qū)為例
?
# 進(jìn)入parted,設(shè)置md10分區(qū)類(lèi)型為gpt
parted /dev/md10 -s mklabel gpt
?
# 指定分區(qū)類(lèi)型為主分區(qū)。其中,0%是分區(qū)開(kāi)始位置,100%是分區(qū)結(jié)束位置
parted /dev/md10 -s -- mkpart primary 0% 100%
?
# 格式化分區(qū)
mkfs.xfs -f /dev/md10
?
# 設(shè)置開(kāi)機(jī)自?huà)燧d
echo "UUID=$(/sbin/blkid | grep md10 | awk -F \" '{print $2}') /data01 xfs defaults 0 0" >> /etc/fstab
?
# 重新加載/etc/fstab
mount -a
監(jiān)控nfs
# 通過(guò)以下網(wǎng)址下載go安裝包(編譯nfs_exporter需要使用到go)
https://studygolang.com/dl
?
# 解壓
tar -zxvf go1.21.7.linux-amd64.tar.gz -C /usr/local
?
# 配置環(huán)境變量
vim /etc/profile
?
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export PATH=$PATH:$GOROOT/bin
?
# 重新加載環(huán)境變量
source /etc/profile
?
# 配置go代理
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct
?
# 編譯nfs_exporter
go get -u -v github.com/aixeshunter/nfs_exporter
?
# 編譯成功后,會(huì)在以下路徑生成可執(zhí)行的二進(jìn)制文件nfs_exporter
/usr/local/gopath/bin/nfs_exporter
?
# 啟動(dòng)nfs_exporter
/usr/local/gopath/bin/nfs_exporter --nfs.storage-path="/nfsfile" --nfs.address="主機(jī)ip"

浙公網(wǎng)安備 33010602011771號(hào)