Home mail me! Syndicate this site using RSS

CentOS下搭建NFS平台

注:以下只是本人在VM下搭建高可用性负载的测试笔记。

1、先在VM下装一个CentOS作为NFS服务器(nfs-server.example.com),再克隆一个作为NFS客户端(nfs-client.example.com),MINI安装即可。

NFS服务器分配IP为192.168.1.100,NFS客户端分配IP为192.168.1.200。

nfs-server.example.com配置如下:

[root@nfs-server ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=nfs-server.example.com
[root@nfs-server ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1   localhost.localdomain localhost
192.168.1.200   nfs-client.example.com   nfs-client


nfs-client.example.com配置如下:

[root@nfs-client ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=nfs-client.example.com
[root@nfs-client ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1   localhost.localdomain localhost
192.168.1.100   nfs-server.example.com   nfs-server

2、配置NFS服务器(nfs-server.example.com)

默认安装下已经装好NFS服务了,所以只用开启服务器即可。

[root@nfs-server ~]# chkconfig nfs on

比如要共享/data/目录:

[root@nfs-server ~]# mkdir /data
[root@nfs-server ~]# vi /etc/exports
/data/ 192.168.1.200(rw,no_root_squash,no_all_squash,sync)

现在就可以启动NFS服务了。

[root@nfs-server ~]# service nfs start

3、配置NFS客户端(nfs-client.example.com)

测试NFS服务器。

[root@nfs-client ~]# showmount -e nfs-server
Export list for share:
/data 192.168.1.200

如果没有出现以上信息,说明NFS服务器还没配置正确,一般是IP设置错误。

MOUNT共享目录/data:

[root@nfs-client ~]# mkdir /data
[root@nfs-client ~]# mount -t nfs 192.168.1.100:/data /data

接下来就测试共享目录/data是否可读写:

[root@nfs-client ~]# echo "hello world" > /data/test

然后上NFS服务器看看是否有/data/test文件:)�

如果想NFS客户端一开机就自动挂载共享目录,只需修改/etc/fstab,加 入以下一句就可以了:

192.168.1.100:/data  /data  nfs   rw   0 0

4、排错参考

当/etc/exports设置的权限,不符合client端的来源时,则会出现以下错误信息:

mount: hostname:/dir failed, reason given by server: Permission denied

然而必须注意的是,若在nfs server的/etc/hosts內有设置IP与hostname的对照

则nfs会先把来源IP转换成hostname,再与/etc/exports內的设置做对比

若此时/etc/exports的设置使用IP而非hostname,则会产生� 法匹配的错误

� 此而出现,虽然來源IP在/etc/exports已正确设置,却仍然发生Permission denied的现象
解决方案是在/etc/exports內采用hostname,避免使用IP,或者是设置正确的IP段。

Create NFS services CentOS – 【GNU/LINUX】 said,

November 9, 2009 @ 04:17:28

[...] NFS servers using Linux set up a text, very good, it is also useful http: / / http://www.sofee.cn/blog/2006/09/29/46/ [...]

RSS feed for comments on this post · TrackBack URI

Leave a Comment

*
To prove that you're not a bot, enter this code
Anti-Spam Image