NFS使用

本文分享自天翼云开发者社区《NFS使用》,作者:2****m

安装nfs

# nfs依赖于rpc,故需安装nfs-utils rpcbind yum install -y nfs-utils rpcbind ​ # 指定nfs监听端口 vim /etc/sysconfig/nfs ​ RQUOTAD_PORT=30001 LOCKD_TCPPORT=30002 LOCKD_UDPPORT=30002 MOUNTD_PORT=30003 STATD_PORT=30004 ​ # nfs依赖于rpc,故需先启动rpcbind,后启动nfs systemctl start rpcbind systemctl enable rpcbind systemctl start nfs-server systemctl enable nfs-server ​ # 查看rpc启动的监听端口 /usr/sbin/rpcinfo -p localhost ​ # 查看nfs服务状态 systemctl status nfs-server 

挂载nfs

# 在nfs节点创建共享目录 mkdir /nfsfile # 赋权 chmod -Rf 777 /nfsfile # 模拟写入数据 echo "welcome to localhost.com" > /nfsfile/readme ​ ----------------------------------------------- ​ # 设置nfs目录访问权限(rw:读写,sync:同时将数据写入内存与硬盘中,保证数据不丢失) vim /etc/exports ​ # 允许主机挂载nfs节点的/nfsfile目录 /nfsfile 主机ip(rw,sync,root_squash) /nfsfile2 主机ip(rw,sync,root_squash) ​ # 查看NFS服务器端共享的文件系统 showmount -e 主机ip ​ # 需在挂载nfs目录的节点安装并启动rpcbind、nfs yum install -y nfs-utils rpcbind ​ # 启动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 主机ip:/nfsfile /nfsfile 

挂载磁盘

# 以md10分区为例 ​ # 进入parted,设置md10分区类型为gpt parted /dev/md10 -s mklabel gpt ​ # 指定分区类型为主分区。其中,0%是分区开始位置,100%是分区结束位置 parted /dev/md10 -s -- mkpart primary 0% 100% ​ # 格式化分区 mkfs.xfs -f /dev/md10 ​ # 设置开机自挂载 echo "UUID=$(/sbin/blkid | grep md10 | awk -F \" '{print $2}') /data01 xfs defaults 0 0" >> /etc/fstab ​ # 重新加载/etc/fstab mount -a 

监控nfs

# 通过以下网址下载go安装包(编译nfs_exporter需要使用到go) https://studygolang.com/dl ​ # 解压 tar -zxvf go1.21.7.linux-amd64.tar.gz -C /usr/local ​ # 配置环境变量 vim /etc/profile ​ export GOROOT=/usr/local/go export GOPATH=/usr/local/gopath export PATH=$PATH:$GOROOT/bin ​ # 重新加载环境变量 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 ​ # 编译成功后,会在以下路径生成可执行的二进制文件nfs_exporter /usr/local/gopath/bin/nfs_exporter ​ # 启动nfs_exporter /usr/local/gopath/bin/nfs_exporter --nfs.storage-path="/nfsfile" --nfs.address="主机ip"

来源链接:https://www.cnblogs.com/developer-tianyiyun/p/19050974

请登录后发表评论

    没有回复内容