菜鸟学习---NFS共享文件服器务搭建
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了菜鸟学习---NFS共享文件服器务搭建相关的知识,希望对你有一定的参考价值。
一、搭建环境
服务端:Linux nfsser 2.6.32-431.el6.x86_64 IP:10.10.10.11
客户端:Linux nfsclient 2.6.32-431.el6.x86_64 IP:10.10.10.12
二、服务端和客户端安装nfs-utils rpcbind
1、对服务端配置
检查系统是否安装rpcbind和nfs-utils
[[email protected] ~]# rpm -qa |grep rpcbind [[email protected] ~]# rpm -qa |grep nfs-utils
通过yum进行安装
[[email protected] ~]# yum install -y rpcbind nfs-utils portmap Loaded plugins: fastestmirror, security base | 3.7 kB 00:00 base/primary_db | 4.7 MB 00:03 extras | 3.4 kB 00:00 extras/primary_db | 29 kB 00:00 updates | 3.4 kB 00:00 中间省略。。。。。。 Dependency Updated: keyutils-libs.x86_64 0:1.4-5.el6 Complete!
查看安装结果:
[[email protected] ~]# rpm -qa nfs-utils portmap rpcbind rpcbind-0.2.0-13.el6_9.1.x86_64 nfs-utils-1.2.3-75.el6.x86_64
2、对服务端进行配置
[[email protected] ~]# /etc/init.d/rpcbind start #启动rpcbind服务 Starting rpcbind: [ OK ] [[email protected] ~]# ps -ef |grep rpcbind #查看rpcbind服务进程 rpc 26947 1 0 21:34 ? 00:00:00 rpcbind root 26951 1500 0 21:35 pts/0 00:00:00 grep rpcbind [[email protected] ~]# /etc/init.d/rpcbind status #查看服务运行状态 rpcbind (pid 26947) is running... [[email protected] ~]# 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
#如查rpcbind服务停止后,查看rpcbind本地对应端口 [[email protected] ~]# /etc/init.d/rpcbind stop #停止rpcbind服务 Stopping rpcbind: [ OK ] [[email protected] ~]# rpcinfo -p localhost rpcinfo: can‘t contact portmapper: RPC: Remote system error - Connection refused #报错原因是因为rpcbind服务未启动 [[email protected] ~]# /etc/init.d/rpcbind reload #平滑加载nfs服务 Stopping rpcbind: [FAILED] Starting rpcbind: [ OK ] :通过reload启动rpcbind服务(通过reload启动服务,类似于你在5点银行下班的时候你已经在银行大 厅,不会影响你办理业务,但5点的时候外面的人在进来是进不来的) [[email protected] ~]# /etc/init.d/nfs start #启动nfs服务 Starting NFS services: [ OK ] Starting NFS quotas: [ OK ] Starting NFS mountd: [ OK ] Starting NFS daemon: [ OK ] Starting RPC idmapd: [ OK ] [[email protected] ~]# 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 50275 mountd 100005 1 tcp 46245 mountd 100005 2 udp 45499 mountd 100005 2 tcp 51182 mountd 100005 3 udp 36337 mountd 100005 3 tcp 52782 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 52478 nlockmgr 100021 3 udp 52478 nlockmgr 100021 4 udp 52478 nlockmgr 100021 1 tcp 41895 nlockmgr 100021 3 tcp 41895 nlockmgr 100021 4 tcp 41895 nlockmgr [[email protected] ~]# chkconfig rpcbind on #加入开自启 [[email protected] ~]# chkconfig nfs on [[email protected] ~]# chkconfig --list rpcbind #检查是否加入开机自启 rpcbind 0:off1:off2:on3:on4:on5:on6:off [[email protected] ~]# chkconfig --list nfs nfs 0:off1:off2:on3:on4:on5:on6:off
2、对客户端配置(服务端只用开启rpcbind服务即可)
[[email protected] ~]# yum install -y rpcbind nfs-utils portmap Loaded plugins: fastestmirror, security base | 3.7 kB 00:00 base/primary_db | 4.7 MB 00:03 extras | 3.4 kB 00:00 extras/primary_db | 29 kB 00:00 updates | 3.4 kB 00:00 中间省略。。。。。。 Dependency Updated: keyutils-libs.x86_64 0:1.4-5.el6 Complete!
查看安装结果:
[[email protected] ~]# rpm -qa nfs-utils portmap rpcbind rpcbind-0.2.0-13.el6_9.1.x86_64 nfs-utils-1.2.3-75.el6.x86_64 [[email protected] ~]# /etc/init.d/rpcbind start #启动rpcbind服务 Starting rpcbind: [ OK ] [[email protected] ~]# chkconfig rpcbind on #加入开机自启 [[email protected] ~]# chkconfig --list rpcbind #检查是否添加开机自启 rpcbind 0:off1:off2:on3:on4:on5:on6:off [[email protected] ~]# /etc/init.d/rpcbind status rpcbind (pid 27102) is running... [[email protected] ~]#
二、对共享文件配置
1、配置服务器端文件
[[email protected] ~]# mkdir /sharedata #建立共享sharedata [[email protected] ~]# vi /etc/exports #编辑nfs配置文件 [[email protected] ~]# cat /etc/exports #查看nfs配置文件结果 ##share data at 20171018 /sharedata 10.10.10.0/24(rw,sync)
注:
[[email protected] ~]# cat /var/lib/nfs/etab #查看nfs默认配置 /sharedata10.10.10.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,ro,root_squash,no_all_squash) /sharedata*(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)
[[email protected] ~]# showmount -e localhost #查看本机共享是否成功 Export list for localhost: /sharedata (everyone)
2、配置客户端文件
[[email protected] ~]# showmount -e 10.10.10.11 #成功检没到共享 Export list for 10.10.10.11: /sharedata (everyone)
[[email protected] ~]# mount -t nfs 10.10.10.11:/sharedata /mnt #挂载到/mnt下 [[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 59G 1.6G 55G 3% / tmpfs 931M 0 931M 0% /dev/shm /dev/sda1 194M 34M 151M 19% /boot 10.10.10.11:/sharedata 59G 1.6G 55G 3% /alidata
[[email protected] mnt]# ll #查文件sharedata文件里的内容 total 72 -rw-r--r--. 1 root root 46850 Mar 23 2016 log.txt -rw-r--r--. 1 root root 14476 Mar 23 2016 mytlv-20160119.log -rw-r--r--. 1 root root 4537 Sep 5 22:12 qzj.txt [[email protected] mnt]# touch 123 #测试能否有写入权限 touch: cannot touch `123‘: Permission denied 拒绝访问
在nfsser端检查
[[email protected] /]# ll -ld /sharedata/
drwxr-xr-x. 2 root root 4096 Oct 18 22:51 /sharedata/
[[email protected] sharedata]# cat /var/lib/nfs/etab /sharedata10.10.10.0/24(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,ro,root_squash,no_all_squash) /sharedata*(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) [[email protected] sharedata]# grep 65534 /etc/passwd #根据ID查找用户 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin [[email protected] sharedata]# chown -R nfsnobody.nfsnobody /sharedata/ #给sharedata赋予权限 [[email protected] /]# ll -ld /sharedata/ drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Oct 18 22:51 /sharedata/
[[email protected] alidata]# touch asd # 测试创建asd文件 [[email protected] alidata]# ll total 72 -rw-r--r--. 1 root root 0 Oct 18 23:53 ad -rw-r--r--. 1 nfsnobody nfsnobody 0 Oct 19 00:11 asd 创建成功 -rw-r--r--. 1 nfsnobody nfsnobody 46850 Mar 23 2016 log.txt -rw-r--r--. 1 nfsnobody nfsnobody 14476 Mar 23 2016 mytlv-20160119.log -rw-r--r--. 1 nfsnobody nfsnobody 4537 Sep 5 22:12 qzj.txt
客户端在重启后,挂载的alidata会丢失,需要加载到开机自启。
echo "mount -t nfs 10.10.10.11:/sharedata /alidata" >>/etc/rc.local
本文出自 “菜鸟八哥” 博客,请务必保留此出处http://cainiaibage.blog.51cto.com/5307589/1974118
以上是关于菜鸟学习---NFS共享文件服器务搭建的主要内容,如果未能解决你的问题,请参考以下文章