您的位置:首页 > 运维架构 > Linux

CentOS配置NFS服务器的方法

2011-05-24 15:43 671 查看
1,NFS服务器的安装

在CentOS系统中,默认情况下已经安装了NFS文件系统,如果没有安装就需要手工安装了

#rpm–qnfs-utilsportmap

2,查看NFS是否启动

#servicenfsstarus
#serviceportmapstatus

3,启动NFS

#servicenfsstart
#serviceportmapstatus

4,修改NFS系统配置文件

#vim/etc/exports

/home/yaronli/nfs_space*(sync,rw)

解释说明:

/home/yaronli/nfs_space:共享目录名

*:表示所有主机都可以连接改NFS

(sync,rw):设置选项

sync:设置NFS服务器同步写磁盘,这样不会轻易丢失数据,建议所有的NFS共享目录都使用该选项
ro:设置输出的共享目录只读,与rw不能共同使用
rw:设置输出的共享目录可读写,与ro不能共同使用

exports文件中“客户端主机地址”字段可以使用多种形式表示主机地址

192.168.152.13 指定IP地址的主机
nfsclient.test.com 指定域名的主机
192.168.1.0/24 指定网段中的所有主机
*.test.com 指定域下的所有主机
* 所有主机

5,生效配置文件

命令#exportfs–rv可以让新设置的exports文件内容生效

以上是Server端的配置步骤

Client端的配置步骤如下:

1,直接mount到nfsserver即可

#mount-tnfs10.60.1.91:/home/yangguang/nfs_space/mnt/
说明:
10.60.1.91:是nfsserver的ip地址
/home/yangguang/nfs_space:是nfsserver中的共享目录
/mnt:为本地的目录

执行成功后,即可在/mnt目录中看到nfsserver挂载的内容

2,卸载已经挂载的nfs共享目录

#umount/mnt/

常见问题:


>:mount-onolock10.78.28.103:/usr/n300/mnt

mount:RPC:Unabletoreceive;errno=Noroutetohost

mount:nfsmountfailed:Badfiledescriptor

mount:Mounting10.78.28.103:/usr/n300on/mntfailed:Badfiledescriptor

如果有上面类似错误,有可能是如下原因

a:先ping客户端能否连通服务器ip

RPC:Unabletoreceive;errno=Noroutetohost的原因

b:nfs服务器是否有防火墙屏蔽了对应端口

c:/etc/hosts.deny/etc/hosts.allow是否屏蔽了客户端ip

Badfiledescriptor的原因

d:/etc/exports配置有问题,确保文件中的"()"是英文的,如果你从其他地方copy有可能出现如上问题

解决办法:

[root@localhostn300]#serviceiptablesstop

Flushingfirewallrules:[OK]

SettingchainstopolicyACCEPT:filter[OK]

Unloadingiptablesmodules:[OK]

[root@localhostn300]#serviceiptablesstatus

Firewallisstopped.

[root@localhostn300]#cat/etc/hosts

hostshosts.allowhosts.deny

[root@localhostn300]#cat/etc/hosts.deny

#

#hosts.denyThisfiledescribesthenamesofthehostswhichare

#*not*allowedtousethelocalINETservices,asdecided

#bythe'/usr/sbin/tcpd'server.

#

#Theportmaplineisredundant,butitislefttoremindyouthat

#thenewsecureportmapuseshosts.denyandhosts.allow.Inparticular

#youshouldknowthatNFSusesportmap!

[root@localhostn300]#cat/etc/hosts.allow

#

#hosts.allowThisfiledescribesthenamesofthehostswhichare

#allowedtousethelocalINETservices,asdecided

#bythe'/usr/sbin/tcpd'server.

#

[root@localhostn300]#


5:解决上面问题后应该可以正确的mount了

>:mount-onolock10.78.28.103:/usr/mnt

mount:10.78.28.103:/usrfailed,reasongivenbyserver:Permissiondenied#还是有错,iptable在作怪

mount:nfsmountfailed:Badfiledescriptor

mount:Mounting10.78.28.103:/usron/mntfailed:Badfiledescriptor

>:

>:

>:####自给解决上面的错误

>:

>:mount-onolock10.78.28.103:/usr/n300/mnt##正确了

>:

>:

>:df

FilesystemSizeUsedAvailableUse%Mountedon

/dev/root6.6M6.6M0100%/

/dev/mtdblock/51.0M68.0k956.0k7%/info

/dev/mtdblock/642.0M3.3M38.7M8%/apps

/dev/mtdblock/75.0M196.0k4.8M4%/logs

10.78.28.218:/home/webserver8.4G7.2G780.8M90%/tmp/mnt

10.78.28.103:/usr/n3009.6G6.7G2.4G73%/mnt


常用命令:

显示当前主机中NFS服务器的输出列表
#showmount-e
显示当前主机NFS服务器中已经被NFS客户机挂载使用的共享目录
#showmount-d
显示NFS服务器的输出
#showmount-e10.60.1.91
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: