Chinaunix首页 | 论坛 | 博客
  • 博客访问: 349339
  • 博文数量: 42
  • 博客积分: 1984
  • 博客等级: 上尉
  • 技术积分: 927
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-30 14:40
文章分类

全部博文(42)

文章存档

2016年(11)

2014年(3)

2013年(7)

2012年(3)

2011年(8)

2010年(10)

分类: LINUX

2013-03-22 09:54:55

NFS是Network File System的简写,即网络文件系统,是一种将远程主机上的分区(目录)经网络挂载到本地系统的一种机制,通过对网络文件系统的支持,用户可以在本地系统上像操作本地分区一样来对远程主机的共享分区(目录)进行操作。
 
Linux下的NFS服务器默认是安装的,如果没有安装,请用yum install nfs*命令进行安装。以下实验平台为CentOS 6.2。
 
NFS本身没有端口号,需要调用其他服务与客户端进行连接,
RHEL版本5中, NFS调用的是portmap服务,
RHEL版本6中, NFS调用的是rpcbind服务。
 
 
一、服务器端NFS服务器配置
 
1.修改主配文件
以root身份登陆,主配文件/etc/exports,内容默认为空,修改为所有人可读写,修改后的内容如下:
[root@itpro ~]# cat /etc/exports 
/dir    * (rw,sync)
(注:指定共享目录及其权限,这里*表示所有人,相当于匿名anonymous,也可以针对某个网段如192.168.0.*或某个IP;rw表示读写权限;sync表示数据同步写入内在和硬盘)
 
2.启动nfs服务,
如果rpcbind尚未开启,则先开启rpcbind,再开启nfs,
[root@itpro ~]# service rpcbind restart
[root@itpro ~]# service nfs start
如果rpcbind和nfs都已运行,则重启nfs,
[root@itpro ~]# service nfs restart
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS quotas:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Starting NFS services:  exportfs: No options for /dir *: suggest *(sync) to avoid warning
exportfs: No host name given with /dir (rw,sync), suggest *(rw,sync) to avoid warning
exportfs: incompatible duplicated export entries:
exportfs:       *:/dir (0x424) [IGNORED]
exportfs:       *:/dir (0x425)
                                                           [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
[root@itpro ~]#
(注:rpcbind服务默认随系统启动;nfs服务默认不随系统启动的,需要使用chkconfig nfs on)
 
在NFS 服务器启动后,还需要检查Linux 服务器的防火墙等设置(一般需要关闭防火墙服务),确保没有屏蔽掉NFS 使用的端口和允许通信的主机。
 
在Linux服务器上进行nfs服务器的回环测试,验证共享目录是否能够被访问。(注:本机内网IP地址为192.168.56.101)
[root@itpro ~]# mount -t nfs 192.168.56.101:/dir /mnt
[root@itpro ~]# ls /mnt
t01  t02  t03
 
 
二、NFS客户端配置
 
A.手动加载(与上面服务器上的回环测试是一样的)
[root@pca ~]# mount -t nfs 192.168.56.101:/dir /mnt
[root@pca ~]# ls /mnt
t01  t02  t03  lost+found
(注:相当于windows里的磁盘映射,但下次开机后,需要重新加载)
 
B.设备自动加载
(注:进行该设置后,当访问服务器端的共享目录时,系统用自动加载服务器上的共享目录,如果一段时间(5分钟或10分钟)不操作,系统用自动卸载。)
1.设置挂载点
[root@pca ~]# vim /etc/auto.master 
#/misc  /etc/auto.misc
/dir    /etc/auto.misc
……
(注:为防止意外出现,操作前确保本地系统没/dir目录,设置后,会自动生成的)
 
2.配置文件的设置
[root@pca ~]# vim /etc/auto.misc 
#linux          -ro,soft,intr           ftp.example.org:/pub/linux
101dir           -rw,soft,intr           192.168.56.101:/dir
……
(注:101dir表示用于访问目录,可以随便设置,最后客户端访问的/dir/101dir,就是服务器端的/dir目录)
 
3.重新加载autofs
如果已开启autofs,则重载,不必要restart
[root@pca ~]# service autofs reload
Reloading maps
如果没有开启,则开启,
[root@pca ~]# service autofs start
Starting automount:                                        [  OK  ]
 
4.访问服务器端的共享文件
以下命令,/dir是可以通过tab自动补充完整的,但101dir要手动输入,
[root@pca ~]# cd /dir/101dir
[root@pca 101dir]# ls
t01  t02  t03  lost+found
[root@pca 101dir]# cat t01
T01
[root@pca 101dir]# touch t04
touch: cannot touch `t04': Read-only file system
(以上操作,在进入远端共享目录时,反应比较很慢,不知道是否是网络原因;另外,发现有r权限,但没有w权限,有点奇怪,由于服务器端及客户端的配置都是rw,按理应该是可读可写的,未得解)

本文出自 “一树清劲” 博客,转载请务必保留此出处。


阅读(1325) | 评论(0) | 转发(2) |
给主人留下些什么吧!~~