使用mount挂载NFS

来源:互联网 发布:爬虫软件刷奖软件下载 编辑:程序博客网 时间:2024/05/21 11:24

在项目中使用到NFS,就是网路文件系统。这个就不多说了。NFS就是实现远程机器上的文件路径挂载到某个机器上,这样在使用的时候感觉和本地路径是一样的。在linux上我要实现挂载一个路径,是程序需要。先说要实现的目标。在192.168.0.74这台机器上有个程序,有个功能需要读取接口返回的文件,我的项目里是用挂载方式实现的。就是在192.168.0.41这台机器上布置的接口程序,当74上的程序访问接口后,返回结果只有文件名,没有文件,文件是接口程序生成在本地的一个路径上:/usr/ccag/etp/ivrfile/ttstmp/74上的程序需要到41这个路径上自己取文件,然后完成自己的功能。这个就是通过挂载实现的。首先74上指定一个路径/share/ttstmptest,然后41上使用挂载mount把/usr/ccag/etp/ivrfile/ttstmp/挂载到74上的/share/ttstmptest。这样接口41上生成文件后,74上的程序访问本地的/share/ttstmptest就等同于在访问41上的/usr/ccag/etp/ivrfile/ttstmp/。这样就实现了文件共享功能,不用文件流传递文件,也不用ftp传递文件,这样其实更快更省时间。下面我来说具体的操作。首先使用mount命令的那台机器就是客户端,被挂载的那台机器就是服务端。======服务端(74):先查看/etc/exports,这个文件要配置被挂载的路径。CTI-01:/etc # CTI-01:/etc # cat /etc/exports# See the exports(5) manpage for a description of the syntax of this file.# This file contains a list of all directories that are to be exported to # other computers via NFS (Network File System).# This file used by rpc.nfsd and rpc.mountd. See their manpages for details# on how make changes in this file effective./share 192.168.0.0/255.255.255.0(rw,all_squash,async,anonuid=65534,anongid=65533)/home/record 192.168.0.0/255.255.255.0(rw,all_squash,async,anonuid=65534,anongid=65533)CTI-01:/etc # CTI-01:/etc # CTI-01:/etc # CTI-01:/etc # 修改路径可以被哪些ip访问,我就直接改成所有ip访问vi /etc/exports/share *(rw,all_squash,async,anonuid=65534,anongid=65533)修改后还要使之生效,使用exportfs -rv 不要使用service nfs restart,重启nfs服务也可以但是最好不要用这种方式。CTI-01:/home # CTI-01:/home # CTI-01:/home # cat /etc/exports# See the exports(5) manpage for a description of the syntax of this file.# This file contains a list of all directories that are to be exported to # other computers via NFS (Network File System).# This file used by rpc.nfsd and rpc.mountd. See their manpages for details# on how make changes in this file effective./share *(rw,all_squash,async,anonuid=65534,anongid=65533)/home/record *(rw,all_squash,async,anonuid=65534,anongid=65533)You have new mail in /var/mail/rootCTI-01:/home # CTI-01:/home # CTI-01:/home # CTI-01:/home # exportfs -rvexporting *:/home/recordexporting *:/shareCTI-01:/home # CTI-01:/home # 不改在客户端会出现:[root@localhost ~]# [root@localhost ~]# mount -a -t nfs 192.168.0.74:/share/faxtest /usr/ccag/etp/ivrfile/fax/mount: 192.168.0.74:/share/faxtest failed, reason given by server: Permission denied[root@localhost ~]# =====================================================================================服务端改好后,客户端就可以运行mount命令进行挂载了。======客户端:(41)mount -a -t nfs 192.168.0.74:/share/faxtest /usr/ccag/etp/ivrfile/fax/mount -a -t nfs 192.168.0.74:/share/ttstmptest /usr/ccag/etp/ivrfile/ttstmp/[root@localhost ~]# [root@localhost ~]# df鏂囦欢绯荤粺               1K-鍧?       宸茬敤     鍙敤 宸茬敤% 鎸傝浇鐐?/dev/hda7             95961744  10811152  80197356  12% //dev/hda9              9920592    153904   9254620   2% /tmp/dev/hda8             79356500   4135988  71124344   6% /opt/dev/hda6             99188468   5082472  88986084   6% /home/dev/hda5             99188468   8364324  85704232   9% /usr/dev/hda3                93327     11370     77138  13% /boottmpfs                   955808    602900    352908  64% /dev/shm[root@localhost ~]# [root@localhost ~]# [root@localhost ~]# [root@localhost ~]# mount -a -t nfs 192.168.0.74:/share/faxtest /usr/ccag/etp/ivrfile/fax/[root@localhost ~]# [root@localhost ~]# [root@localhost ~]# df鏂囦欢绯荤粺               1K-鍧?       宸茬敤     鍙敤 宸茬敤% 鎸傝浇鐐?/dev/hda7             95961744  10811152  80197356  12% //dev/hda9              9920592    153904   9254620   2% /tmp/dev/hda8             79356500   4135988  71124344   6% /opt/dev/hda6             99188468   5082472  88986084   6% /home/dev/hda5             99188468   8364324  85704232   9% /usr/dev/hda3                93327     11370     77138  13% /boottmpfs                   955808    602900    352908  64% /dev/shm192.168.0.74:/share/faxtest                      20152864  10117568  10035296  51% /usr/ccag/etp/ivrfile/fax[root@localhost ~]# [root@localhost ~]# mount -a -t nfs 192.168.0.74:/share/ttstmptest /usr/ccag/etp/ivrfile/ttstmp/[root@localhost ~]# [root@localhost ~]# [root@localhost ~]# df鏂囦欢绯荤粺               1K-鍧?       宸茬敤     鍙敤 宸茬敤% 鎸傝浇鐐?/dev/hda7             95961744  10811152  80197356  12% //dev/hda9              9920592    153904   9254620   2% /tmp/dev/hda8             79356500   4135988  71124344   6% /opt/dev/hda6             99188468   5082472  88986084   6% /home/dev/hda5             99188468   8364324  85704232   9% /usr/dev/hda3                93327     11370     77138  13% /boottmpfs                   955808    602900    352908  64% /dev/shm192.168.0.74:/share/faxtest                      20152864  10117568  10035296  51% /usr/ccag/etp/ivrfile/fax192.168.0.74:/share/ttstmptest                      20152864  10117568  10035296  51% /usr/ccag/etp/ivrfile/ttstmp[root@localhost ~]# [root@localhost ~]# 看到df结果中有我们挂载的路径,就完成了。如果出现其他问题,可能是nfs服务的问题,也可能是防火墙的问题,或者是路径或者文件权限的问题。nfs重启:[root@localhost ivrfile]# service nfs restart关闭 NFS mountd:[确定]关闭 NFS 守护进程:[确定]关闭 NFS quotas:[确定]关闭 NFS 服务: [失败]启动 NFS 服务: [确定]关掉 NFS 配额:[确定]启动 NFS 守护进程:[确定]启动 NFS mountd:[确定][root@localhost ivrfile]# [root@localhost ivrfile]# 重新挂载/etc/exports中的路径[root@localhost ivrfile]# [root@localhost ivrfile]# exportfs -rvexporting *:/usr/ccag/etp/ivrfile/ttstmpexporting *:/usr/ccag/etp/ivrfile/fax[root@localhost ivrfile]# [root@localhost ivrfile]# 关闭防火墙[root@localhost ivrfile]# [root@localhost ivrfile]# service iptables stop[root@localhost ivrfile]# [root@localhost ivrfile]# [root@localhost ivrfile]# [root@localhost ivrfile]# [root@localhost ivrfile]# chkconfig iptables off[root@localhost ivrfile]# [root@localhost ivrfile]# 修改挂载路径的读写权限,服务端也要改,否则无法读写。chmod -R 777 /usr/ccag/etp 其他基本上不会有什么问题。还有一个现象,就是服务端74上有个路径被挂载后就不能被第2台机器挂载[root@localhost ivrfile]# [root@localhost ivrfile]# [root@localhost ivrfile]# mount -a -t nfs 192.168.0.74:/share/fax /usr/ccag/etp/ivrfile/fax/mount.nfs: /usr/ccag/etp/ivrfile/fax is already mounted or busy[root@localhost ivrfile]# /share/fax这个路径已经被其他机器挂载了,我再想挂载到现在的机器上就报这个错。=====================================================================================showmount 查看挂载的目录showmount -e nfs_server_IP查看指定ip的挂载目录CTI-01:/etc # CTI-01:/etc # showmount Hosts on CTI-01:192.168.0.*192.168.0.0/255.255.255.0192.168.0.71192.168.0.72192.168.0.74192.168.0.75192.168.0.89192.168.0.90192.168.0.91CTI-01:/etc # CTI-01:/etc # CTI-01:/etc # =====================================================================================





0 0
原创粉丝点击