找回密码
 立即注册
首页 业界区 安全 NFS使用

NFS使用

裴涛 2025-9-28 18:13:45
本文分享自天翼云开发者社区《NFS使用》,作者:2****m

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

举报

分享、互助 让互联网精神温暖你我
您需要登录后才可以回帖 登录 | 立即注册