阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Linux下NFS搭建步骤

137次阅读
没有评论

共计 3937 个字符,预计需要花费 10 分钟才能阅读完成。

一、NFS 简介

NFS 是 Network File System 的缩写,即网络文件系统。一种使用于分散式文件协定,有 SUN 公司开发。功能是通过网络让不同的机器、不同的操作系统能够分享个人数据,让应用程序通过网络可以访问位于服务器磁盘中的数据。

NFS 在文件传送或信息传送的过过程中,依赖于 RPC 协议。RPC,远程过程调用(Remote Procedure Call), 是使客户端能够执行其他系统中程序的一种机制。NFS 本身是没有提供信息传输的协议和功能的,但 NFS 却能让我们通过网络进行资料的分享,就是因为 NFS 使用了 RPC 提供的传输协议,可以说 NFS 就是使用 PRC 的一个程序。

NFS 服务端、RPC 协议、客户端三者可以理解为房源、中介、租客之间的关系:

Linux 下 NFS 搭建步骤

二、系统环境

      CentOS release 6.7 (Final)  2.6.32-573.el6.i686
        NFS IP:172.16.1.31
        web IP : 172.16.1.8
        /etc/init.d/iptables status
        iptables:未运行防火墙
        SElinux  :getenforce  Permissive
三、开始搭建
1)软件安装,NFS 只需要安装两个软件,在通常情况下是作为系统默认软件安装的
【rpcbind】centos 下面 RPC 主程序
【nfs-utils】NFS 服务主程序,包括 NFS 的基本命令和监控程序

[root@nfs01 ~]# yum install rpcbind nfs-utils
 
 2)开启 RCP 服务
[root@nfs01 ~]# /etc/init.d/rpcbind start
查看 rpcbind 服务端口

[root@nfs01 ~]# netstat -antlp|grep rpcbind
tcp        0      0 0.0.0.0:111                0.0.0.0:*                  LISTEN      1368/rpcbind
 
查看此时 rpc 服务上面是否有端口注册

[root@nfs01 ~]# rpcinfo -p localhost
  program vers proto  port  service
    100000    4  tcp    111  portmapper
    100000    3  tcp    111  portmapper
    100000    2  tcp    111  portmapper
    100000    4  udp    111  portmapper
    100000    3  udp    111  portmapper
    100000    2  udp    111  portmapper
 
3)开启 NFS 服务

[root@nfs01 ~]# /etc/init.d/nfs start
现在 rpc 上应该能看到好多新被注册的 nfs 端口了

[root@nfs01 ~]# rpcinfo -p localhost
    100003    2  tcp  2049  nfs
    100003    3  tcp  2049  nfs
    100003    4  tcp  2049  nfs
    100227    2  tcp  2049  nfs_acl
    100227    3  tcp  2049  nfs_acl
 
设置两个服务开机自启动

[root@nfs01 ~]# chkconfig rpcbind on
[root@nfs01 ~]# chkconfig nfs on
 
4)服务端配置共享目录(/data)

配置前确认 rpcbind、nfs 服务进程正常

[root@nfs01 ~]# /etc/init.d/nfs status
[root@nfs01 ~]# /etc/init.d/rpcbind status
[root@nfs01 ~]# ps -ef|egrep “rpc|nfs”
rpc      1368    1  0 00:14 ?        00:00:00 rpcbind
rpcuser  1391    1  0 00:14 ?        00:00:00 rpc.statd
root      1440    2  0 00:14 ?        00:00:00 [rpciod/0]
root      1449    1  0 00:14 ?        00:00:00 rpc.rquotad
root      1454    1  0 00:14 ?        00:00:00 rpc.mountd
root      1461    2  0 00:14 ?        00:00:00 [nfsd4]
root      1462    2  0 00:14 ?        00:00:00 [nfsd4_callbacks]
root      1463    2  0 00:14 ?        00:00:00 [nfsd]
root      1464    2  0 00:14 ?        00:00:00 [nfsd]
root      1465    2  0 00:14 ?        00:00:00 [nfsd]
root      1466    2  0 00:14 ?        00:00:00 [nfsd]
 
创建共享目录并授权(”nfsnobody”)

 #nfsnobody 用户是开启 rpc、nfs 进程后系统自动创建的

[root@nfs01 ~]# mkdir /data
[root@nfs01 ~]# chown -R nfsnobody.nfsnobody /data 
 
修改服务端配置文件(/etc/exports)

[root@nfs01 ~]# vim /etc/exports

#share /data by oldboy for bingbing at 20160524
/data 172.16.1.0/24(rw,sync)
####
/data1 172.16.1.0/24(rw,sync,all_squash,anonuid=65534,anongid=65534)
 
注意!
# 此时可以修改“anonuid”值来修改 NFS 默认虚拟用户,前提是用户在系统中存在,可以指定“-s /sbin/nologin”
查看系统加载的配置

[root@nfs01 ~]# cat /var/lib/nfs/etab
/data  172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
 
重新平滑加载服务

 

[root@nfs01 ~]# /etc/init.d/nfs reload
 
确认服务、目录等配置正确,共享成功

[root@nfs01 ~]# showmount -e
Export list for nfs01:
/data  172.16.1.0/24
 
5)客户端配置

客户端只需要安装 rpcbind 程序,并确认服务正常

[root@web01 ~]# /etc/init.d/rpcbind status
rpcbind (pid  1361) 正在运行 …
 
挂载 nfs 共享目录

[root@web01 ~]# mount -t nfs 172.16.1.31:/data /mnt
[root@web01 ~]# df -h
Filesystem        Size Used Avail Use% Mounted on
/dev/sda3          6.9G 1.3G  5.2G  20% /
tmpfs              503M    0 503M  0% /dev/shm
/dev/sda1          190M  33M  147M  19% /boot
172.16.1.31:/data  6.9G 1.3G  5.2G  20% /mnt
 
开机自动挂载

echo “mount -t nfs172.16.1.31:/data /mnt”>>/etc/rc.local

另外,实现 NFS 共享自动挂载也可以在 /ets/fstab 里实现,不过此时要系统开启 netfs 服务
因为有可能在系统在重启过程中,先实现挂载,后启动网络,此时出现挂载不成功问题

Linux 下 NFS 搭建步骤

开启 netfs 服务
[root@web01 ~]# chkconfig netfs on

NFS 文件系统详解  http://www.linuxidc.com/Linux/2016-06/131940.htm

Ubuntu 12.04 安装 NFS server http://www.linuxidc.com/Linux/2012-09/70728.htm

NFS 服务器安装配置实现 Ubuntu 12.04 与 ARM 文件共享 http://www.linuxidc.com/Linux/2012-10/73159.htm

Ubuntu 搭建 nfs 服务器 http://www.linuxidc.com/Linux/2012-10/71930.htm

文件服务器 NFS 配置详解 http://www.linuxidc.com/Linux/2013-06/86542.htm

Ubuntu 下搭建 NFS 网络文件系统服务器 http://www.linuxidc.com/Linux/2013-07/87367.htm

Heartbeat_ldirector+LB+NFS 实现 HA 及 LB、文件共享 http://www.linuxidc.com/Linux/2013-06/85292.htm

CentOS 5.5 配置 NFS 服务器教程 http://www.linuxidc.com/Linux/2013-03/81737.htm

Ubuntu 12.10 下 NFS 的安装使用 http://www.linuxidc.com/Linux/2013-03/80478.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-08/134022.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计3937字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中