企业NFS服务器拓扑图:



nfs showmount 使用_开发工具



需求:



1、/media目录



共享/media目录,允许所有客户端访问该目录并只有只读权限。



2、/nfs/public目录



共享/nfs/public目录,允许192.168.8.0/24和192.168.9.0/24网段的客户端访问,并且对此目录只有只读权限。



3、/nfs/team1、/nfs/team2、/nfs/team3目录



共享/nfs/team1、/nfs/team2、/nfs/team3目录,并/nfs/team1只有team1.michael.com域成员可以访问并有读写权限,/nfs/team2、/nfs/team3目录同理哈~



4、/nfs/works目录



共享/nfs/works目录,192.168.8.0/24网段的客户端具有只读权限,并且将root用户映射成匿名用户。



5、/nfs/test目录



共享/nfs/test目录,所有人都具有读写权限,但当用户使用该共享目录时都将帐号映射成匿名用户,并且指定匿名用户的UID和GID都为65534。



6、/nfs/security目录



共享/nfs/security目录,仅允许192.168.8.88客户端访问并具有读写权限。



解决方案:



1、创建相应目录



nfs showmount 使用_nfs showmount 使用_02



2、安装nfs-utils及portmap软件包



没有就用rpm或yum安装一下哈~



nfs showmount 使用_客户端_03



nfs-utils-1.0.9-24.el5:nfs服务的主程序包,它提供rpc.nfsd及rpc.mountd这两个daemons以及相关的说明文件。



portmap-4.0-65.2.2.1:rpc主程序,记录服务的端口映射信息。



3、编辑/etc/exports配置文件



/etc/exports:nfs服务的主配置文件



vim /etc/exports



nfs showmount 使用_网络_04



配置后



nfs showmount 使用_nfs showmount 使用_05



注意:在发布共享目录的格式中除了共享目录是必跟参数外,其他参数都是可选的。并且共享目录与客户端之间及客户端与客户端之间需要使用空格符号,但是客户端与参数之间是不能有空格的哈~



nfs showmount 使用_网络_06



4、配置nfs固定端口



vim /etc/sysconfig/nfs



自定义以下端口,然而不能和其他端口冲突



RQUOTAD_PORT=5001
LOCKD_TCPPORT=5002
LOCKD_UDPPORT=5002
MOUNTD_PORT=5003
STATD_PORT=5004



nfs showmount 使用_开发工具_07



5、配置iptables策略



iptables -P INPUT -j DROP
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp -m multiport --dport 111,2049 -j ACCEPT
iptables -A INPUT -p udp -m multiport --dport 111,2049 -j ACCEPT
iptables -A INPUT -p tcp --dport 5001:5004 -j ACCEPT
iptables -A INPUT -p udp --dport 5001:5004 -j ACCEPT
service iptables save



nfs showmount 使用_nfs showmount 使用_08



6、启动portmap和nfs服务



由于NFS服务是基于portmap服务的,所以我们需要先启动portmap服务: service portmap restart ,然后 service nfs restart



nfs showmount 使用_客户端_09



7、测试



NFS服务器本机测试



1)使用rpcinfo命令检测nfs是否使用了固定端口



rpcinfo -p



nfs showmount 使用_开发工具_10



2)检测nfs的rpc注册状态



rpcinfo -u 主机名或IP地址 进程



rpcinfo -u 192.168.8.188 nfs



nfs showmount 使用_操作系统_11



3)查看共享目录和参数设置



cat /var/lib/nfs/etab



nfs showmount 使用_客户端_12



4)使用showmount命令查看共享目录发布及使用情况



showmount -eshowmount -e IP地址



nfs showmount 使用_网络_13



showmount -d或者 showmount -d IP地址



nfs showmount 使用_网络_14



Linux客户端测试



nfs showmount 使用_网络_15



1)查看nfs服务器共享目录



showmount -e 192.168.8.188



nfs showmount 使用_操作系统_16



2)挂载及卸载NFS文件系统



mount -t nfs NFS服务器IP地址或主机名:共享名 本地挂载点



nfs showmount 使用_开发工具_17



如果想挂载一个没有权限访问的NFS共享目录就会报错哈~



nfs showmount 使用_开发工具_18



3)启动自动挂载nfs文件系统



vim /etc/fstab



nfs showmount 使用_操作系统_19



保存退出并重启系统



nfs showmount 使用_nfs showmount 使用_20



我们在nfs服务器/nfs/test目录中新建个文件测试一下



nfs showmount 使用_nfs showmount 使用_21



linux客户端系统启动了



nfs showmount 使用_网络_22



我们来看下/nfs/test有没挂载成功了哈~



nfs showmount 使用_开发工具_23



 



 




转载于:https://blog.51cto.com/andyzhao/160444