|
)实例:服务器端使用NFS服务输出/cxm目录为只读,/cxm下的目录为读写,并且开机自启动;客户端使用autofs服务自动挂载服务器输出的目录,并且1分钟无操作自动卸载。 服务器端:rhel6.3(192.168.200.122) [iyunv@localhost 桌面]# mkdir /cxm #新建父目录 [iyunv@localhost 桌面]# mkdir /cxm/zyk #新建子目录 [iyunv@localhost 桌面]# ll -d /cxm #查看父目录所有者 drwxr-xr-x. 3 root root 4096 2月 2 10:21 /cxm [iyunv@localhost 桌面]# id nfsnobody #查看nfsnobody用户的信息 uid=65534(nfsnobody) gid=65534(nfsnobody) 组=65534(nfsnobody) [iyunv@localhost 桌面]# grep nfsnobody /etc/passwd #nsfnobody用户为NFS的匿名用户 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin [iyunv@localhost 桌面]# chown nfsnobody:nfsnobody /cxm –Rf #将/cxm所有者和组改为nfsnobody [iyunv@localhost 桌面]# vim /etc/exports #编辑NFS的配置文件(要输出的目录) /cxm *(ro,async,no_root_squash) #输出/cxm,所有人都可访问,只读权限,同步内容,不映射成nfsnobody /cxm/zyk 192.168.200.0/24(rw,async,no_root_squash) #输出/cxm/zyk,200段的用户可访问,读写权限,同步内容,不映射成nfsnobody [iyunv@localhost 桌面]# /etc/init.d/nfs restart #重启服务 注:第一次做时可以restart,但是若是修改文件,不建议使用restart,可使用exportfs –rv 重新读取配置文件,这样就不用重启了 [iyunv@localhost 桌面]# chkconfig nfs on #开机自启动 [iyunv@localhost 桌面]# chkconfig nfs --list nfs 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
客户端:rhel6.6(192.168.200.126) 首先查看服务器端输出的目录: [iyunv@localhost 桌面]# showmount -e 192.168.200.122 #查122服务器输出的目录 Export list for 192.168.200.122: /cxm * /cxm/zyk 192.168.200.0/24 然后安装autofs,并完成自动挂载: [iyunv@localhost 桌面]# rpm -qa | grep autofs [iyunv@localhost 桌面]# yum list | grep autofs autofs.x86_64 1:5.0.5-109.el6 [iyunv@localhost 桌面]# yum install autofs.x86_64 #安装autofs [iyunv@localhost 桌面]# rpm -ql autofs | more #查配件目录 /etc/auto.master /etc/auto.misc [iyunv@localhost 桌面]# vim /etc/auto.master #编辑配件,添加分割文件 /misc /etc/auto.misc /opt /etc/auto.opt --timeout 60 [iyunv@localhost 桌面]# cp /etc/auto.misc /etc/auto.opt [iyunv@localhost 桌面]# vim /etc/auto.opt #编辑分割文件 * -rw,soft,intr 192.168.200.122:/cxm/& [iyunv@localhost 桌面]# /etc/init.d/autofs restart 停止 automount: [确定] 正在启动 automount: [确定] 测试: [iyunv@localhost 桌面]# df -h /opt #因为autofs比较安全,会隐藏服务器的ip Filesystem Size Used Avail Use% Mounted on - 0 0 0 - /opt [iyunv@localhost 桌面]# df –h #后面不加挂载点不会显示输出的文件系统目录 Filesystem Size Used Avail Use% Mounted on /dev/mapper/JUNXI-root 12G 11G 76M 100% / tmpfs 491M 76K 491M 1% /dev/shm /dev/sda1 190M 33M 148M 19% /boot /dev/mapper/JUNXI-home 2.0G 3.0M 1.9G 1% /home /dev/sr0 3.6G 3.6G 0 100% /media/RHEL-6.6 Server.x86_64 [iyunv@localhost 桌面]# cd /opt [iyunv@localhost opt]# ls 因为autofs,不会显示二级目录 [iyunv@localhost opt]# cd zyk #进入到二级目录 [iyunv@localhost zyk]#df –h #因为触发了/cxm下的zyk目录,所以才会显示出来的 192.168.200.122:/cxm/zyk 13G 11G 1.8G 86% /mnt [iyunv@localhost zyk]# cd /opt [iyunv@localhost opt]# ls zyk [iyunv@localhost opt]# ls #无操作1分钟后不再显示zyk了 [iyunv@localhost opt]# 注:NFS为网络文件系统,即将远程主机分享的目录挂载到本地主机 autofs为客户端自动挂载工具,当文件使用时会自动挂载,不使用时会自动卸载,不用再手动挂载和卸载了,但是使用autofs时要注意服务器共享的目录下面应该有子目录,即二级目录,也应该将其输出,有多少个输出多少个,这样客户端才能使用。因为设置了autofs后,一级目录下不能做操作,只能在二级目录下做操作,但是做autofs时只需在分割文件中写父目录即可。(autofs会隐藏服务器的ip和输出的目录,不会显示出来,二级目录也不会显示出来,但可以进入;但是一旦触发了一级目录下的二级目录df –h 会显示服务器的ip, ‘ls 挂载点’会显示出触发的二级目录)
(2) <1>使用NFS服务输出目录 服务器端:rhel6.3(192.168.200.122) [iyunv@localhost 桌面]# mkdir /cxm #新建父目录 [iyunv@localhost 桌面]# mkdir /cxm/zyk #新建子目录 [iyunv@localhost 桌面]# ll -d /cxm #查看父目录所有者 drwxr-xr-x. 3 root root 4096 2月 2 10:21 /cxm [iyunv@localhost 桌面]# id nfsnobody #查看nfsnobody用户的信息 uid=65534(nfsnobody) gid=65534(nfsnobody) 组=65534(nfsnobody) [iyunv@localhost 桌面]# grep nfsnobody /etc/passwd #nsfnobody用户为NFS的匿名用户 nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin [iyunv@localhost 桌面]# chown nfsnobody:nfsnobody /cxm –Rf #将/cxm所有者和组改为nfsnobody [iyunv@localhost 桌面]# vim /etc/exports #编辑NFS的配置文件(要输出的目录) /cxm *(ro,async,no_root_squash) #输出/cxm,所有人都可访问,只读权限,同步内容,不映射成nfsnobody /cxm/zyk 192.168.200.0/24(rw,async,no_root_squash) #输出/cxm/zyk,200段的用户可访问,读写权限,同步内容,不映射成nfsnobody [iyunv@localhost 桌面]# /etc/init.d/nfs restart #重启服务 注:第一次做时可以restart,但是若是修改文件,不建议使用restart,可使用exportfs –rv 重新读取配置文件,这样就不用重启了 [iyunv@localhost 桌面]# chkconfig nfs on #开机自启动 [iyunv@localhost 桌面]# chkconfig nfs --list nfs 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 客户端:rhel6.6(192.168.200.126) [iyunv@localhost 桌面]# showmount -e 192.168.200.122 #查122服务器输出的目录 Export list for 192.168.200.122: /cxm * /cxm/zyk 192.168.200.0/24 [iyunv@localhost 桌面]# mount.nfs4 192.168.200.122:/cxm/zyk /mnt #挂载服务器的目录到本地的/mnt下 [iyunv@localhost 桌面]# df -h /mnt #查看是否挂载 Filesystem Size Used Avail Use% Mounted on 192.168.200.122:/cxm/zyk 13G 11G 1.8G 86% /mnt [iyunv@localhost 桌面]# touch /mnt/111 #测试一下,建个文件看是否成功 注:此时服务器的/cxm/zyk下会多了一个111文件 <2>多输出几个目录 服务器端: [iyunv@localhost 桌面]# mkdir /cxm/web [iyunv@localhost 桌面]# vim /etc/exports /cxm *(ro,async,no_root_squash) /cxm/zyk 192.168.200.0/24(rw,async,no_root_squash) /cxm/web 192.168.200.0/24(rw,async,no_root_squash) [iyunv@localhost 桌面]# exportfs -rv exporting 192.168.200.0/24:/cxm/web exporting 192.168.200.0/24:/cxm/zyk exporting *:/cxm 客户端: [iyunv@localhost 桌面]# showmount -e 192.168.200.122 Export list for 192.168.200.122: /cxm * /cxm/web 192.168.200.0/24 /cxm/zyk 192.168.200.0/24 [iyunv@localhost 桌面]# mount.nfs4 192.168.200.122:/cxm/web /opt [iyunv@localhost 桌面]# df -h 192.168.200.122:/cxm/zyk 13G 11G 1.8G 86% /mnt 192.168.200.122:/cxm/web 13G 11G 1.8G 86% /opt [iyunv@localhost 桌面]# touch /opt/111 注:此时服务器的/cxm/web目录下会多一个111文件 <3>使用autofs自动挂载NFS服务(客户端操作) 客户端: [iyunv@localhost 桌面]# umount /mnt [iyunv@localhost 桌面]# umount /opt [iyunv@localhost 桌面]# rpm -qa | grep autofs [iyunv@localhost 桌面]# yum list | grep autofs autofs.x86_64 1:5.0.5-109.el6 [iyunv@localhost 桌面]# yum install autofs.x86_64 [iyunv@localhost 桌面]# rpm -ql autofs | more /etc/auto.master /etc/auto.misc [iyunv@localhost 桌面]# vim /etc/auto.master /misc /etc/auto.misc /opt /etc/auto.opt --timeout 60 [iyunv@localhost 桌面]# cp /etc/auto.misc /etc/auto.opt [iyunv@localhost 桌面]# vim /etc/auto.opt * -rw,soft,intr 192.168.200.122:/cxm/& [iyunv@localhost 桌面]# /etc/init.d/autofs restart 停止 automount: [确定] 正在启动 automount: [确定] [iyunv@localhost 桌面]# df -h /opt Filesystem Size Used Avail Use% Mounted on - 0 0 0 - /opt [iyunv@localhost 桌面]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/JUNXI-root 12G 11G 76M 100% / tmpfs 491M 76K 491M 1% /dev/shm /dev/sda1 190M 33M 148M 19% /boot /dev/mapper/JUNXI-home 2.0G 3.0M 1.9G 1% /home /dev/sr0 3.6G 3.6G 0 100% /media/RHEL-6.6 Server.x86_64
|