linux nfs

发布于:2025-03-24 ⋅ 阅读:(20) ⋅ 点赞:(0)

前言

  • TencentOS Server 3.3

nfs服务器搭建

  • TencentOS Server 3.3
  • IP: 172.21.32.8

安装nfs服务

shell> systemctl stop firewalld.service
shell> setenforce 0
shell> yum install nfs-utils rpcbind -y
shell> systemctl enable rpcbind.service
shell> systemctl start rpcbind.service
shell> systemctl status rpcbind.service
● rpcbind.service - RPC Bind
   Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2025-03-23 17:24:39 CST; 28min ago
     Docs: man:rpcbind(8)
 Main PID: 10111 (rpcbind)
    Tasks: 1 (limit: 22744)
   Memory: 1.0M
   CGroup: /system.slice/rpcbind.service
           └─10111 /usr/bin/rpcbind -w -f

Mar 23 17:24:39 VM-32-8-tencentos systemd[1]: Starting RPC Bind...
Mar 23 17:24:39 VM-32-8-tencentos systemd[1]: Started RPC Bind.

shell> systemctl enable nfs-server.service
shell> systemctl start nfs-server.service
shell> systemctl status nfs-server.service
● nfs-server.service - NFS server and services
   Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; disabled; vendor preset: disabled)
   Active: active (exited) since Sun 2025-03-23 17:25:09 CST; 28min ago
  Process: 18523 ExecReload=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
  Process: 10393 ExecStart=/bin/sh -c if systemctl -q is-active gssproxy; then systemctl reload gssproxy ;>
  Process: 10381 ExecStart=/usr/sbin/rpc.nfsd (code=exited, status=0/SUCCESS)
  Process: 10379 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
 Main PID: 10393 (code=exited, status=0/SUCCESS)
    Tasks: 0 (limit: 22744)
   Memory: 0B
   CGroup: /system.slice/nfs-server.service

Mar 23 17:25:09 VM-32-8-tencentos systemd[1]: Starting NFS server and services...
Mar 23 17:25:09 VM-32-8-tencentos systemd[1]: Started NFS server and services.

编辑exports文件

编辑exports文件:

shell> vim /etc/exports  

exports文件内容:

/data 172.21.32.0/24(rw,sync,fsid=0)

exports文件内容说明:
文件内容分为三个部分:
第一部分:/data ,表示本主机上的/data目录作为共享目录挂载到其它主机上。
第二部分:172.21.32.0/24 ,表示172.21.32.x IP段的主机可以挂载共享目录。
第三部分:括号中部分内容含义。

  • rw表示可读写,ro只读。
  • sync :同步模式,内存中数据时时写入磁盘;async :不同步,把内存中数据定期写入磁盘中。
  • fsid=0表示将/opt/nfs整个目录包装成根目录。

重启nfs服务

shell> systemctl reload nfs-server.service
shell> systemctl status nfs-server.service

确认nfs服务器是否配置完成

nfs和rpcbind服务启动状态

shell> systemctl status rpcbind.service
shell> systemctl status nfs-server.service

查看可挂载目录及可连接的IP

shell> showmount -e 172.21.32.8
Export list for 172.21.32.8:
/data 172.21.32.0/24
  • 172.21.32.8 主机的 /data 目录可挂载
  • 172.21.32.0/24 IP段的主机可挂载172.21.32.8上的nfs文件系统

其它主机挂载nfs文件系统

  • TencentOS Server 3.3
  • IP: 172.21.32.2

安装nfs服务

shell> yum install nfs-utils rpcbind -y
shell> systemctl enable rpcbind.service
shell> systemctl start rpcbind.service
shell> systemctl status rpcbind.service

查看可挂载目录及可连接的IP

shell> showmount -e 172.21.32.8
Export list for 172.21.32.8:
/data 172.21.32.0/24
  • 172.21.32.8 为nfs文件系统主机
  • 172.21.32.8 主机的 /data 目录可挂载
  • 172.21.32.0/24 IP段的主机可挂载172.21.32.8上的nfs文件系统
  • 172.21.32.2 为172.21.32.0/24 IP段内的IP

挂载目录

使用 mount 挂载nfs文件系统的目录/data到本主机的目录/nfs-data下。

shell>  mkdir /nfs-data  
shell>  mount -t nfs 172.21.32.8:/data/ /nfs-data/    

开机自动挂载

需要编辑/etc/fstab

shell>  vim /etc/fstab

加入以下内容:

172.21.32.8:/data/                  /nfs-data/    nfs    nolock   0 0   

手动触发(/etc/fstab中配置的)重新挂载

shell>  mount -a

参考

Linux安装samba与windows实现共享文件夹


网站公告

今日签到

点亮在社区的每一天
去签到