Loading

centos7 下nfs的配置

 

补充知识:


  • RPC 主程序:rpcbind

    我们的 NFS 其实可以被视为一个 RPC 服务,而要启动任何一个 RPC 服务之前,我们都需要做好 port 的对应 (mapping) 的工作才行,这个工作其实就是『 rpcbind 』这个服务所负责的!也就是说, 在启动任何一个 RPC 服务之前,我们都需要启动 rpcbind 才行! ( CentOS 5.x 以前这个软件称为 portmap,在 CentOS 6.x 之后才称为 rpcbind 的!)

  • NFS 主程序:nfs-utils

就是提供 rpc.nfsd rpc.mountd 这两个 NFS daemons 与其他相关 documents 与说明文件、执行文件等的软件!这个就是 NFS 服务所需要的主要软件啦!一定要有喔!

好了,知道我们需要这两个软件之后,现在干嘛?赶快去你的系统先用 RPM 看一下有没有这两个软件啦! 没有的话赶快用 RPM yum 去安装喔!不然就玩不下去了!

例题:

请问我的主机是以 RPM 为套件管理的 Linux distribution ,例如 Red Hat, CentOS SuSE 等版本,那么我要如何知道我的主机里面是否已经安装了 rpcbind nfs 相关的软件呢?

答:

简单的使用『 rpm -qa | grep nfs 』与『 rpm -qa | grep rpcbind 』即可知道啦!如果没有安装的话, 在 CentOS 内可以使用『 yum install nfs-utils 』来安装!


环境:

系统平台:Centos 7

防火墙 :关闭



1.编辑exports文件,配置共享目录以及权限

[root@localhost var]# vim /etc/exports




expports文件中的权限设置可以限制用户的访问,目录本身的权限也限制着用户的访问。

[shao@localhost nfs]$ ll

总用量 4

-rw-rw-r--. 1 qi qi 0 411 22:20 qi

-rw-rw----. 1 shao shao 5 411 22:23 shao

2.开启nfs服务:

1)首先开启rpcbind

2)开启nfs


 

 


3.关闭防火墙(实验环境,真实环境时参见下文对防火墙配置):

qi@zhuandshao:~$ showmount -e 192.168.1.1

clnt_create: RPC: Port mapper failure - Unable to receive: errno 113 (No route to host)

#以上在客户端测试时出现的问题就是由于防火墙的缘故,使得端口无法使用

[root@localhost var]# systemctl stop firewalld.service

 

4.客户端挂载

qi@zhuandshao:~$ sudo mount -t nfs 192.168.1.1:/var/nfs /mnt/nfs

 

5.设置nfs开机自启动

[root@localhost ~]# systemctl enable rpcbind.service

[root@localhost ~]#

[root@localhost ~]# systemctl enable nfs-server.service

ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/multi- user.target.wants/nfs-server.service'


6.端口

1nfs需要的端口

  • rpcbind 启动的 port 111 ,同时启动在 UDP TCP

  • nfs 本身的服务启动在 port 2049 上头!

  • 其他 rpc.* 服务启动的 port 则是随机产生的,因此需向 port 111 注册。

2nfs打开的端口:

[root@localhost qi]# netstat -tulnp| grep -E '(rpc|nfs)'

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1480/rpcbind

tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 2528/rpc.mountd

tcp6 0 0 :::111 :::* LISTEN 1480/rpcbind

tcp6 0 0 :::20048 :::* LISTEN 2528/rpc.mountd

udp 0 0 0.0.0.0:111 0.0.0.0:* 1480/rpcbind

udp 0 0 0.0.0.0:669 0.0.0.0:* 1480/rpcbind

udp 0 0 0.0.0.0:20048 0.0.0.0:* 2528/rpc.mountd

udp6 0 0 :::111 :::* 1480/rpcbind

udp6 0 0 :::669 :::* 1480/rpcbind

udp6 0 0 :::20048 :::* 2528/rpc.mountd


7.设置开机挂载

如果想在客户机开机时就自动挂载服务器下的/var/nfs的话,就要在客户机下的/etc/fstab添加东西了

192.168.1.1:/var/nfs /mnt/nfs nfs defaults 0 0

这样就行了,也不用每次都自己mount


出现的问题:

[root@localhost /]# systemctl start nfs

Job for nfs-server.service failed. See 'systemctl status nfs-server.service' and 'journalctl -xn' for details.

没建立/etc/exports里的目录的问题!!!


参考资料:

1.鸟哥的Linux私房菜(服务器篇)http://cn.linux.vbird.org/linux_server/0330nfs_2.php

 


posted @ 2017-04-12 09:27  Q1mt  阅读(1217)  评论(0编辑  收藏  举报