Linux-nfs 文件共享

  • 一台机器作为服务端, 一台作为客户端. 系统版本为 CentOS 7.
  • 安装 nfs-utils:
    yum install nfs-utils
    服务端和客户端都要安装
  • 设置 nfs 服务为开机启动:
    systemctl enable rpcbind
    systemctl enable nfs
  • 启动 nfs 服务并查看状态:
    • systemctl start rpcbind
    • systemctl start nfs
    • systemctl status nfs.status
      可以看到状态是 active, 说明 nfs 已经启动了.
      view status
  • 开启防火墙:
    • firewall-cmd --zone=public --permanent --add-service={rpc-bind,mountd,nfs}
    • firewall-cmd --reload
  • 服务端配置共享目录:
    • 创建共享目录:
      • mkdir /home/share
      • chmod 755 /home/share
    • 配置 /etc/exports:
      • /home/share: 共享目录位置.
      • 192.168.1.0/24: 客户端 IP 范围 *代表所有,即没有限制.
      • rw: 权限设置, 可读可写.
      • sync: 同步共享目录.
      • no_root_squash: 可以使用 root 授权.
      • no_all_squash: 可以使用普通用户授权.
      /home/share     192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
      
    • 更改配置后重启 nfs 服务: systemctl restart nfs.service
    • 查看本地共享目录: showmount -e localhost
      看到如下图所示, 则服务端配置成功了.

view share

  • 客户端连接 nfs:

    • 测试连接: showmount -e 192.168.1.181
      看到如下图所示则证明客户端能够连接到服务端
    • 挂载目录: mount -t nfs 192.168.0.101:/home/share /home/share

    show mount server

  • 设置开机自动挂载:
    在 /etc/fstab 中增加一行配置

    192.168.0.110:/home/share     /home/share                   nfs     defaults        0 0
    

    view fstab

  • 参考:
    [1] : CentOS 7 下 yum 安装和配置 NFS
    [2] : centos7 下nfs的配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值