设为首页 收藏本站
查看: 605|回复: 0

[经验分享] 企业级NFS网络文件共享服务

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-12-29 14:59:10 | 显示全部楼层 |阅读模式
虚拟实验:
操作系统:CentOS release 6.8 (Final)
虚拟机:VMware
任务:NFS网络文件共享服务
默认是没有安装NFS软件包,NFS主要功能是通过网络让不同的主机系统之间可以共享文件或目录。NFS网络文件系统很像Windows系统的网络共享、安全功能、网络驱动映射,而互联网中小型网站集群架构后端常用NFS进行数据共享。
NFS服务器IP: 192.168.222.130
NFS客户端IP1: 192.168.222.138
NFS客户端IP2:192.168.222.139
N个客户端
NFS服务器端设置:
[iyunv@localhost ~]# yum install nfs-utils rpcbind –y
[iyunv@localhost ~]# rpm -qa nfs-utils rpcbind
nfs-utils-1.2.3-70.el6_8.2.x86_64
rpcbind-0.2.0-12.el6.x86_64
[iyunv@localhost ~]# /etc/init.d/rpcbind status
rpcbind is stopped
[iyunv@localhost ~]# /etc/init.d/rpcbind start   #启动rpc服务
Starting rpcbind:                                          [  OK  ]
[iyunv@localhost ~]# lsof -i:111
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 1839  rpc    6u  IPv4  13719      0t0  UDP *:sunrpc
rpcbind 1839  rpc    8u  IPv4  13722      0t0  TCP *:sunrpc (LISTEN)
rpcbind 1839  rpc    9u  IPv6  13724      0t0  UDP *:sunrpc
rpcbind 1839  rpc   11u  IPv6  13727      0t0  TCP *:sunrpc (LISTEN)
[iyunv@localhost ~]# netstat -lntup|grep rpcbind  #查看NFS服务向RPC服务注册的端口
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1839/rpcbind        
tcp        0      0 :::111                      :::*                        LISTEN      1839/rpcbind        
udp        0      0 0.0.0.0:742                 0.0.0.0:*                               1839/rpcbind        
udp        0      0 0.0.0.0:111                 0.0.0.0:*                               1839/rpcbind        
udp        0      0 :::742                      :::*                                    1839/rpcbind        
udp        0      0 :::111                      :::*                                    1839/rpcbind     
[iyunv@localhost ~]# 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
[iyunv@localhost ~]# chkconfig --list rpcbind
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
NFS服务的相关操作:
[iyunv@localhost ~]# /etc/init.d/nfs status
rpc.svcgssd 已停
rpc.mountd is stopped
nfsd is stopped
[iyunv@localhost ~]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
正在启动 RPC idmapd:                                      [确定]
[iyunv@localhost ~]# 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
    100005    1   udp  38130  mountd
    100005    1   tcp  54803  mountd
    100005    2   udp  54566  mountd
    100005    2   tcp  37618  mountd
    100005    3   udp  56646  mountd
    100005    3   tcp  43214  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
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  43937  nlockmgr
    100021    3   udp  43937  nlockmgr
    100021    4   udp  43937  nlockmgr
    100021    1   tcp  46011  nlockmgr
    100021    3   tcp  46011  nlockmgr
    100021    4   tcp  46011  nlockmgr
配置NFS服务器端开机自动启动: chkconfig和/etc/rc.local的配置二选一即可。
[iyunv@localhost ~]# chkconfig rpcbind on
[iyunv@localhost ~]# chkconfig nfs on
[iyunv@localhost ~]# chkconfig --list rpcbind
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[iyunv@localhost ~]# chkconfig --list nfs
nfs             0:off   1:off   2:on    3:on    4:on    5:on    6:off
配置NFS服务器端:配置文件路径
创建需要共享的目录并授权:
-bash: l: command not found
[iyunv@localhost ~]# mkdir /data
[iyunv@localhost ~]# ll /data
total 0
[iyunv@localhost ~]# chown -R nfsnobody.nfsnobody /data
[iyunv@localhost ~]# ls -ld /data
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Dec 28 23:54 /data
配置NFS服务配置文件:
[iyunv@localhost ~]# vi /etc/exports
/data 192.168.222.0/24(rw,sync)
[iyunv@localhost ~]# exportfs –rv   #查看挂载信息
exporting 192.168.222.0/24:/data
[iyunv@localhost ~]# showmount -e localhost   #查看本地服务器挂载情况
Export list for localhost:
/data 192.168.222.0/24
[iyunv@localhost /]# mount -t nfs 192.168.222.130:/data /mnt
[iyunv@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              27G  3.0G   23G  12% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1              93M   51M   38M  58% /boot
192.168.222.130:/data      27G  3.0G   23G  12% /mnt
NFS Client端执行的操作:
安装客户端软件rpcbind
[iyunv@localhost ~]# yum install rpcbind –y
[iyunv@localhost ~]# rpm -qa rpcbind
rpcbind-0.2.0-12.el6.x86_64
[iyunv@localhost ~]# showmount
-bash: showmount: command not found
[iyunv@localhost ~]# yum install nfs-utils –y
启动RPC服务
[iyunv@localhost ~]# /etc/init.d/rpcbind start
正在启动 rpcbind:                                         [确定]
[iyunv@localhost ~]# showmount  -e  192.168.222.130
Export list for 192.168.222.130:
/data 192.168.222.0/24
[iyunv@localhost ~]# mount -t nfs 192.168.222.130:/data /mnt
[iyunv@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              27G  939M   25G   4% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1              93M   51M   38M  58% /boot
192.168.222.130:/data      27G  3.0G   23G  12% /mnt
[iyunv@localhost ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.222.130:/data on /mnt type nfs (rw,vers=4,addr=192.168.222.130,clientaddr=192.168.222.138)
[iyunv@localhost ~]# ls /mnt/
[iyunv@localhost ~]# mkdir /mnt/source
[iyunv@localhost ~]# ls -l /mnt
总用量 4
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 12月 29 2016 source
将rpcbind服务和挂载加入开机自启动,如下:
[iyunv@localhost ~]# echo "/etc/inti.d/rpcbind start" >>/etc/rc.local
[iyunv@localhost ~]# echo "/bin/mount -t nfs 192.168.222.130:/data /mnt" >>/etc/rc.local
[iyunv@localhost ~]# tail -2 /etc/rc.local
/etc/inti.d/rpcbind start
/bin/mount -t nfs 192.168.222.130:/data /mnt
注意:关于防火墙和文件权限的相关设置在这里省略。


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-321117-1-1.html 上篇帖子: Linux手动添加用户 下篇帖子: 虚拟机Redhat桥接无法获取IP地址 网络
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表