zoukankan      html  css  js  c++  java
  • CentOS 6.5配置nfs服务

    CentOS 6.5配置nfs服务

    网络文件系统(Network File System,NFS),一种使用于分散式文件系统的协议,由升阳公司开发,于1984年向外公布。功能是通过网络让不同的机器、不同的操作系统能够彼此 分享个别的数据,让应用程序在客户端通过网络访问位于服务器磁盘中的数据,是在Unix系统间实现磁盘文件共享的一种方法。

    NFS的基本原则是“容许不同的客户端及服务端通过一组RPC分享相同的文件系统”,它是独立于操作系统,容许不同硬件及操作系统的系统共同进行文件的分享。

    演示环境介绍

    系统:CentOS 6.5
    nfs服务器ip:192.168.1.65
    nfs客户端ip:192.168.1.66

    开始安装配置

    1. #安装
    2. yum install nfs-utils rpcbind

    安装完以后先不急着启动,先来了解一下nfs服务运行在哪些端口上,它默认需要使用5个端口,其中有4个端口是动态的,所以如果服务器和客户端之间有 iptables,就要先把这4个动态端口设置成静态的,然后加入进防火墙规则里,需要修改的端口有如下四个(端口可以根据需求改,不一定就和我这一 样):

    1. #编辑nfs配置文件
    2. vi /etc/sysconfig/nfs
    3.  
    4. LOCKD_TCPPORT=30001 #TCP锁使用端口
    5. LOCKD_UDPPORT=30002 #UDP锁使用端口
    6. MOUNTD_PORT=30003 #挂载使用端口
    7. STATD_PORT=30004 #状态使用端口

    改好以后保存退出,除了以上四个端口要通过iptables,还有nfs协议端口2049以及rpc的111端口,这样才能顺利的使用nfs服务。

    1. #往iptables里写入规则,让需要的端口通过
    2. -A INPUT -m state --state NEW -m tcp -p tcp --dport 111 -j ACCEPT
    3. -A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
    4. -A INPUT -m state --state NEW -m tcp -p tcp --dport 30001 -j ACCEPT
    5. -A INPUT -m state --state NEW -m tcp -p tcp --dport 30002 -j ACCEPT
    6. -A INPUT -m state --state NEW -m tcp -p tcp --dport 30003 -j ACCEPT
    7. -A INPUT -m state --state NEW -m tcp -p tcp --dport 30004 -j ACCEPT
    8.  
    9. #我在/mnt下新建一个目录,并touch一个测试文件test
    10. mkdir /mnt/aiplaypc1
    11. touch /mnt/aiplaypc1/tset
    12.  
    13. #编辑配置文件,默认是空的
    14. vi /etc/exports
    15.  
    16. #把/mnt/aiplaypc1目录共享给192.168.1.0的所有主机,可以写主机名、域名等,使用默认参数(ro,sync,wdelay,root_squash)
    17. /mnt/aiplaypc1 192.168.1.0/24(ro,sync,wdelay,root_squash)
    18.  
    19. #参数详解
    20. ro #只读共享
    21. rw #读写共享
    22.  
    23. sync #同步写操作
    24. async #异步写操作
    25. wdelay #延迟写操作
    26.  
    27. root_squash #屏蔽远程root权限
    28. no_root_squash #不屏蔽远程root权限
    29. all_squash #屏蔽所有远程用户的权限
    30.  
    31. #准备工作做好了,现在就可以启动服务了。
    32. service nfs start
    33. chkconfig nfs on
    34.  
    35. service rpcbind start
    36. chkconfig rpcbind on

    接下来是客户端的操作

      1. #安装
      2. yum install nfs-utils
      3.  
      4. #挂载nfs服务器的共享目录到/mnt/aiplaypc2
      5. mount -t nfs 192.168.1.65:/mnt/aiplaypc1 /mnt/aiplaypc2
      6.  
      7. #检查是否读取到了服务器的共享文件,不出意外就可以看到有个test文件
      8. ls /mnt/aiplaypc2
      9.  
      10. #开机自动挂载
      11. echo "192.168.1.65:/mnt/aiplaypc1 /mnt/aiplaypc2 nfs defaults 0 0" >> /etc/fstab
  • 相关阅读:
    不务正业系列-浅谈《过气堡垒》,一个RTS玩家的视角
    [LeetCode] 54. Spiral Matrix
    [LeetCode] 40. Combination Sum II
    138. Copy List with Random Pointer
    310. Minimum Height Trees
    4. Median of Two Sorted Arrays
    153. Find Minimum in Rotated Sorted Array
    33. Search in Rotated Sorted Array
    35. Search Insert Position
    278. First Bad Version
  • 原文地址:https://www.cnblogs.com/timssd/p/4609305.html
Copyright © 2011-2022 走看看