美文网首页
NFS服务命令与配置

NFS服务命令与配置

作者: Java_Evan | 来源:发表于2018-06-30 15:21 被阅读168次

    # rpcinfo -p           //查看rpc服务信息

    启动NFS服务器

    为了使NFS服务器能正常工作,需要启动rpcbind和nfs两个服务,并且rpcbind一定要先于nfs启动。

    /etc/init.d/rpcbind start    //启动rpcbind服务

    /etc/init.d/nfs start  //启动nfs服务

    重启服务

    /etc/init.d/rpcbind restart  //重启服务

    /etc/init.d/nfs restart  //重启服务

    查看服务状态

    ps -ef | grep rpcbind    //查看rpcbind服务状态

    /etc/init.d/rpcbind status  //查看rpcbind服务状态

    # rpcbind (pid  5212) is running...

    停止服务

    停止两个服务,nfs要优先于rpcbind

    /etc/init.d/nfs stop  //停止nfs服务

    /etc/init.d/rpcbind stop  //停止rpcbind服务

    添加服务开机自启

    chkconfig nfs on  //添加nfs服务开机自启

    chkconfig rpcbind on  //添加rpcbind服务开机自启

    chkconfig --list nfs  //检查nfs服务是否成功添加开机自启

    chkconfig --list rpcbind     //检查rpcbind服务是否成功添加开机自启

    nfs-client配置

    root@nfsclient /]# /etc/init.d/rpcbind start

    Starting rpcbind:                                          [  OK  ]

    [root@nfsclient /]# /etc/init.d/rpcbind status

    rpcbind (pid  25927) is running...

    [root@nfsclient /]# chkconfig rpcbind on

    [root@nfsclient /]# chkconfig --list rpcbind

    rpcbind            0:off    1:off    2:on    3:on    4:on    5:on    6:off

    nfs-server端配置

    [root@nfsserver /]# mkdir /data            #创建共享目录

    [root@nfsserver /]# vim /etc/exports    #nfs配置文件 默认为空

    [root@nfsserver /]# cat /etc/exports

    #shared data for bbs by oldboy at 20160810

    /data 192.168.161.0/24(rw,sync)

    注:这里的共享目录是/data目录;指定一个网段192.168.161.0/24(也可以指定单个IP);rw为可读写(ro只读);sync为同步模式(sync写入数据是直接写入磁盘,async非同步,写入数据写书内存、如果nfs服务端宕机容易造成数据丢失)详细注解可使用man exports命令;具体参数可参考下面nfs默认的配置、

    [root@nfsserver /]# cat /var/lib/nfs/etab      #nfs默认的配置参数

    /data    192.168.161.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@nfsserver /]# /etc/init.d/nfs reload

    [root@nfsserver /]# showmount -e localhost        #现在本机检查共享是否成功

    Export list for localhost:

    /data 192.168.161.0/24

     nfs-client端配置

    [root@nfsclient /]# showmount -e 192.168.161.133    //此为服务端IP

    注:要关闭防火墙、不然客户端查不到共享,汇报如下错误:

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

    clnt_create:RPC:端口映射器失败——不能接受:errno 113(没有通往主机)

    [root@nfsclient /]# service iptables stop    #关闭client端防火墙 或开放相应的端口

    iptables:将链设置为政策 ACCEPT:filter                    [确定]

    iptables:清除防火墙规则:                                [确定]

    iptables:正在卸载模块:                                  [确定]

    [root@nfsserver /]# service iptables stop                #关闭client端防火墙 或开放相应的端口

    iptables:将链设置为政策 ACCEPT:filter                    [确定]

    iptables:清除防火墙规则:                                [确定]

    iptables:正在卸载模块:                                  [确定]

    故障排查:[root@nfsclient /]# ping 192.168.161.133

    [root@nfsclient /]# telnet 192.168.161.133 111

    [root@nfsclient /]# showmount -e 192.168.161.133    #成功检测到共享

    Export list for 192.168.161.133:

    /data 192.168.161.0/24

    [root@nfsclient /]# df -h

    Filesystem      Size  Used Avail Use% Mounted on

    /dev/sda3        16G  4.0G  12G  27% /

    tmpfs          495M  80K  495M  1% /dev/shm

    /dev/sda1      2.0G  59M  1.8G  4% /boot

    /dev/sr0        4.2G  4.2G    0 100% /media/CentOS_6.5_Final

    /dev/sr0        4.2G  4.2G    0 100% /media/cdrom

    [root@nfsclient /]# mount -t nfs 192.168.161.133:/data /mnt  #挂载到/mnt下

    [root@nfsclient /]# df -h

    Filesystem            Size  Used Avail Use% Mounted on

    /dev/sda3              16G  4.0G  12G  27% /

    tmpfs                  495M  80K  495M  1% /dev/shm

    /dev/sda1              2.0G  59M  1.8G  4% /boot

    /dev/sr0              4.2G  4.2G    0 100% /media/CentOS_6.5_Final

    /dev/sr0              4.2G  4.2G    0 100% /media/cdrom

    192.168.161.133:/data  16G  3.9G  12G  26% /mnt  #挂载成功

    [root@nfsclient /]# cd /mnt

    [root@nfsclient mnt]# ll

    total 0

    -rw-r--r--. 1 root root 0 Aug 10 15:49 11

    -rw-r--r--. 1 root root 0 Aug 10 15:49 22

    -rw-r--r--. 1 root root 0 Aug 10 15:49 33

    [root@nfsclient mnt]# touch test.log      #测试下是否有写入权限

    touch: cannot touch `test.log': Permission denied    拒绝访问

    到nfs-server端检查

    [root@nfsserver /]# ll /data -ld

    drwxr-xr-x 2 root root 4096 Aug 10 15:49 /data

    [root@nfsserver /]# cat /var/lib/nfs/etab    #此目录是nfs默认的用户的信息

    /data    192.168.161.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@nfsserver /]# grep 65534 /etc/passwd    #根据用户id查出用户

    nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

    [root@nfsserver /]# chown -R nfsnobody.nfsnobody /data    #给nsfnobody赋予权限

    [root@nfsclient mnt]# touch test.log    #创建测试目录

    [root@nfsclient mnt]# ll

    total 0

    -rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 10 15:49 11

    -rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 10 15:49 22

    -rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 10 15:49 33

    -rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 10 16:02 test.log  #创建成功

    开机自动挂载  修改/etc/fstab文件

    nfs客户端自动挂载autofs,为什么需要autofs

    autofs可以实现当前用户访问的时候在挂载,如果没有用户访问,指定之间、内,就自动卸载。

    可以解决NFS服务器和客户端紧密耦合的问题。缺点:是用户请求才会挂载,所有请求的瞬间效率较差。一般的企业不用它

    部分内容摘自  https://www.cnblogs.com/zzzhfo/p/5797187.html 

    相关文章

      网友评论

          本文标题:NFS服务命令与配置

          本文链接:https://www.haomeiwen.com/subject/sxituftx.html