分享

NFS 自动挂载 主备切换

 豆芽爱尚阅 2015-09-05

由于文件服务器采用的是主备的模式,当主备机进行切换的时候,访问挂载在应用服务上的nfs共享目录时会报错,提示

“Stale NFS file handle” 错误。  这是由于共享的目录移走的原因造成的。

那么当主备机进行切换的时候,如何才能避免这种问题呢。

在下才疏学浅,没想到什么好的方法,临时找了中解决办法,如果谁有更高明的办法,洗耳恭听

 

那就说说我的思路吧,根据鸟哥的文档,我采用的是自动登录的方式,就是共享目录有需要访问的时候才进行连接,当不用的时候,过一会儿,自己会自动断掉,这个过一会儿,我经过测试,应该是 4分钟左右吧,这也就是说,如果主机死掉的话,如果没有访问的话,4分钟后会自动连接到备机上,但是,如果这时候一直有访问的话,那样应该就会报连接失败的错误了。

 

自动挂载的另一个好处是

“在傳統的 NFS 檔案系統的使用當中,如果用戶端要使用伺服器端所提供的 NFS 檔案系統時, 要嘛就是得在 /etc/fstab 當中設定開機時掛載,要嘛就得要手動利用 mount 來掛載。 此外,用戶端得要預先手動的建立好掛載點目錄,然後掛載上來。

不過有個小問題,我們知道 NFS 伺服器與用戶端的連線或許可能不會永遠存在, 而 RPC 這個服務又挺討厭的,如果掛載了 NFS 伺服器後,任何一方離線都可能造成另外一方老是在等待逾時~ 而且,掛載的 NFS 檔案系統可能又不是常常被使用,但若不掛載的話,有時候要使用又得通知系統管理員, 這又很不方便”

 

我的方法如下:

1、首先建立 auto.master 文件,没有的话就新建,如果存在的话修改下就行

我的原来就有,于是我就在此基础上修改的

########################

[root@localhost ~]# vi /etc/auto.master

#
# $Id: auto.master,v 1.4 2005/01/04 14:36:54 raven Exp $
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
/misc   /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
/net    -hosts
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
#+auto.master

/var/Net/Files       /etc/auto.nfs

 

################

我把配置文件中红色的部分注释掉了,因为存在的话 查看日志文件的话会有错误提示

 

tail -f /var/log/messages

Dec  2 08:52:21 localhost automount[6475]: lookup_read_master: lookup(nisplus): couldn't locate nis+ table auto.master

 

2、然后建立目录 

mkdir /var/Net/Files

注意,要保证 Files 目录是空的

 

3、建立 auto.nfs 配置文件

[root@localhost ~]# vi /etc/auto.nfs

temp  -rw,bg,soft,rsize=32768,wsize=32768 10.2.2.136:/var/Net/Files/temp
UPGRADE_FILE  -rw,bg,soft,rsize=32768,wsize=32768 10.2.2.136:/var/Net/Files/UPGRADE_FILE
UPGRADE_DOC  -rw,bg,soft,rsize=32768,wsize=32768 10.2.2.136:/var/Net/Files/UPGRADE_DOC

 

4、136是服务器,137是客户端,红色部分需要和服务器中的exports配置文件相对应

 

[root@localhost rsync]# cat /etc/exports
/var/Net/Files/temp / 10.2.2.137(rw,no_root_squash)
/var/Net/Files/UPGRADE_DOC / 10.2.2.137(rw,no_root_squash)
/var/Net/Files/UPGRADE_FILE / 10.2.2.137(rw,no_root_squash)

 

服务器要开启 portmap 和 nfs 服务

 

[root@localhost rsync]# /etc/init.d/portmap restart

[root@localhost rsync]# /etc/init.d/nfs restart

 

5、客户端启动 autofs 服务


[root@localhost Files]# /etc/init.d/autofs restart

查看日志,保证没有错误

tail -f /var/log/messages

查看服务端是否开启/提供服务

[root@localhost Files]# showmount -e 10.2.2.136(服务端)
Export list for 10.2.2.136:
/var/Net/111                10.2.2.137
/var/Net/Files/temp         10.2.2.137
/var/Net/Files/UPGRADE_DOC  10.2.2.137
/var/Net/Files/UPGRADE_FILE  10.2.2.137

 

6、测试的方法就是

cd /var/Net/Files目录中看不见任何内容,

然后

cd UPGRADE_FILE

cd UPGRADE_DOC

cd temp

能进去,能使用 ,差不多就这样

 

 

 

附:

解决Stale NFS file handle方法

1、等待

2、#fuser -k /directory

3、#umount -f /directory

 

扩展资料:

http://linux./linux_server/0330nfs.php

 

 

 

 

 

 

 

 

 

 

 

 

 

 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多