zoukankan      html  css  js  c++  java
  • linux学习笔记--NFS

    NFS分为客户端,服务端。客户端要访问服务端,要写从RPC服务获得端口。

    整个流程分为:

    1,服务端rpc服务先启动
    2,nfs服务把端口上报给rpc服务
    3,rpc客户端通过服务端的rpcbind拿到访问端口
    4,rpc客户端通过端口访问文件

    rpc服务,在centos5.x下叫portmap,在centos6.x下叫rcpbind

    客户端也要有rpc才能访问服务端

    所以NFS的软件列表:

    nfs-utils
    rpcbind


    安装NFS
    yum install nfs-utils rpcbind
    最好客户端也要安装

    查看是否已安装
    rpm -qa nfs-utils

    lsof -i:111

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

    查看rpc池的信息
    rpcinfo -p localhost

    注意:一定要先启动rpcbind,然后再启动nfs。因为nfs会把端口上报给rpc

    [root@nfsServer init.d]# /etc/init.d/nfs status
    rpc.svcgssd is stopped
    rpc.mountd is stopped
    nfsd is stopped
    rpc.rquotad is stopped
    [root@nfsServer init.d]# 
    [启动nfs服务
    [root@nfsServer init.d]# /etc/init.d/nfs start
    Starting NFS services:                                     [  OK  ]
    Starting NFS quotas:                                       [  OK  ]
    Starting NFS mountd:                                       [  OK  ]
    Starting NFS daemon:                                       [  OK  ]
    Starting RPC idmapd:                                       [  OK  ]

    再看rpc池的信息就有很多了

    [root@nfsServer init.d]# 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
        100011    1   udp    875  rquotad
        100011    2   udp    875  rquotad
        100011    1   tcp    875  rquotad
        100011    2   tcp    875  rquotad
        100005    1   udp  36696  mountd
        100005    1   tcp  59667  mountd
        100005    2   udp  36644  mountd
        100005    2   tcp  36430  mountd
        100005    3   udp  49056  mountd
        100005    3   tcp  55778  mountd
        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
        100003    2   udp   2049  nfs
        100003    3   udp   2049  nfs

    NFS的配置文件:

    /etc/exports

    格式:
    nfs共享目录 nfs客户端地址(参数1,参数2)

    把/image文件夹共享给103 104的机器

    [root@nfsServer log]# cat /etc/exports 
    /image 192.168.1.103(rw,sync) 192.168.1.104(rw,sync)

    共享给所有用户
    /data *(rw,sync)

    重启nfs
    /etc/init.d/nfs reload

    查看共享的文件夹
    [root@nfsServer ~]# showmount -e 192.168.1.102
    Export list for 192.168.1.102:
    /image 192.168.1.104,192.168.1.103
    挂在本机上试试
    [root@nfsServer image]# 
    [root@nfsServer image]# mount -t nfs 192.168.1.102:/image /mnt
    [root@nfsServer image]# cd /mnt/
    [root@nfsServer mnt]# ls
    baseImage.log

    但是这时候通过/mnt 写入权限不足???

    [root@nfsServer image]# cd /mnt/
    [root@nfsServer mnt]# touch xc.log
    touch: cannot touch `xc.log': Permission denied

    因为有些权限没有配置,所以在服务端看来,所有有的访问都是65534(nfsnobody)的用户权限

    [root@nfsServer mnt]# cat /var/lib/nfs/etab 
    /image  192.168.1.*(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)

    这时候如果客户端写的文件权限是nfsnobody,服务端的是root(服务端的用户)

    [root@nfsServer mnt]# ls -l
    total 0
    -rwxrwxrwx 1 root      root      0 Jul 23 03:09 baseImage.log
    -rw-r--r-- 1 nfsnobody nfsnobody 0 Jul 23 03:44 vv.log

    参数说明:
    sync 写入到磁盘,同步写
    async 异步写
    root_squash 如果用户是root的话,回映射成匿名用户
    no_root_squash 客户端访问共享文件夹,客户端用户如果是root的话,有root权限
    all_squash 不管用户权限如何,都会压缩成匿名用户nfsnobody(anonuid=65534,anongid=65534),uid gid是可以改的

    客户端:

    要启动bind服务
    [root@nfsClient01 etc]# /etc/init.d/rpcbind start
    Starting rpcbind: [ OK ]
    客户端查看是不是能和服务端连上
    [root@nfsClient01 etc]# showmount -e 192.168.1.102
    Export list for 192.168.1.102:
    /image 192.168.1.*

    没有问题的话,客户端就可以mount挂载了

    排查错误:
    先ping 看能不能通
    111是nfs的主端口
    telnet 102.168.1.102 111


    exportfs -rv 等价于 /etc/init.d/nfs reload

    服务端的参数
    cat /var/lib/nfs/etab
    客户端的参数
    cat /proc/mounts

  • 相关阅读:
    Web Ajax入门一讲
    Delphi – 我的代码之简单五子棋
    闲话 纪念我的4520G
    Delphi 我的代码之窗体移动
    破文 黑客游戏
    破文 OD常用断点
    Web 简单的开始 – Ajax + XML +DOM
    工具 – XMLSPY 和 UModel 商业版 2010v12.0有注册机
    API InterlockedCompareExchange用法
    软件工程 设计模式学习之策略模式Strategy
  • 原文地址:https://www.cnblogs.com/zpitbolg/p/5701621.html
Copyright © 2011-2022 走看看