NFS利用

[复制链接]
发表于 2025-8-21 14:31:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

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

安装nfs
  1. # nfs依赖于rpc,故需安装nfs-utils rpcbind
  2. yum install -y nfs-utils rpcbind
  3. ​
  4. # 指定nfs监听端口
  5. vim /etc/sysconfig/nfs
  6. ​
  7. RQUOTAD_PORT=30001
  8. LOCKD_TCPPORT=30002
  9. LOCKD_UDPPORT=30002
  10. MOUNTD_PORT=30003
  11. STATD_PORT=30004
  12. ​
  13. # nfs依赖于rpc,故需先启动rpcbind,后启动nfs
  14. systemctl start rpcbind
  15. systemctl enable rpcbind
  16. systemctl start nfs-server
  17. systemctl enable nfs-server
  18. ​
  19. # 查看rpc启动的监听端口
  20. /usr/sbin/rpcinfo -p localhost
  21. ​
  22. # 查看nfs服务状态
  23. systemctl status nfs-server
复制代码
挂载nfs
  1. # 在nfs节点创建共享目录
  2. mkdir /nfsfile
  3. # 赋权
  4. chmod -Rf 777 /nfsfile
  5. # 模拟写入数据
  6. echo "welcome to localhost.com" > /nfsfile/readme
  7. ​
  8. -----------------------------------------------
  9. ​
  10. # 设置nfs目录访问权限(rw:读写,sync:同时将数据写入内存与硬盘中,保证数据不丢失)
  11. vim /etc/exports
  12. ​
  13. # 允许主机挂载nfs节点的/nfsfile目录
  14. /nfsfile 主机ip(rw,sync,root_squash)
  15. /nfsfile2 主机ip(rw,sync,root_squash)
  16. ​
  17. # 查看NFS服务器端共享的文件系统
  18. showmount -e 主机ip
  19. ​
  20. # 需在挂载nfs目录的节点安装并启动rpcbind、nfs
  21. yum install -y nfs-utils rpcbind
  22. ​
  23. # 启动rpcbind、nfs
  24. systemctl start rpcbind
  25. systemctl enable rpcbind
  26. systemctl start nfs-server
  27. systemctl enable nfs-server
  28. ​
  29. # 挂载nfs(mount -t nfs SERVER:/path/to/sharedfs  /path/to/mount_point)
  30. mount -t nfs 主机ip:/nfsfile /nfsfile
复制代码
挂载磁盘
  1. # 以md10分区为例
  2. ​
  3. # 进入parted,设置md10分区类型为gpt
  4. parted /dev/md10 -s mklabel gpt
  5. ​
  6. # 指定分区类型为主分区。其中,0%是分区开始位置,100%是分区结束位置
  7. parted /dev/md10 -s -- mkpart primary 0% 100%
  8. ​
  9. # 格式化分区
  10. mkfs.xfs -f /dev/md10
  11. ​
  12. # 设置开机自挂载
  13. echo "UUID=$(/sbin/blkid | grep md10 | awk -F " '{print $2}') /data01                   xfs     defaults        0 0" >> /etc/fstab
  14. ​
  15. # 重新加载/etc/fstab
  16. mount -a
复制代码
监控nfs
  1. # 通过以下网址下载go安装包(编译nfs_exporter需要使用到go)
  2. https://studygolang.com/dl
  3. ​
  4. # 解压
  5. tar -zxvf go1.21.7.linux-amd64.tar.gz -C /usr/local
  6. ​
  7. # 配置环境变量
  8. vim /etc/profile
  9. ​
  10. export GOROOT=/usr/local/go
  11. export GOPATH=/usr/local/gopath
  12. export PATH=$PATH:$GOROOT/bin
  13. ​
  14. # 重新加载环境变量
  15. source /etc/profile
  16. ​
  17. # 配置go代理
  18. go env -w GO111MODULE=on
  19. go env -w GOPROXY=https://goproxy.io,direct
  20. ​
  21. # 编译nfs_exporter
  22. go get -u -v github.com/aixeshunter/nfs_exporter
  23. ​
  24. # 编译成功后,会在以下路径生成可执行的二进制文件nfs_exporter
  25. /usr/local/gopath/bin/nfs_exporter
  26. ​
  27. # 启动nfs_exporter
  28. /usr/local/gopath/bin/nfs_exporter --nfs.storage-path="/nfsfile" --nfs.address="主机ip"
复制代码
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表