Google

笔记分类

2008年10月29日星期三

ubuntu linux安装配置NFS

1.安装NFS

Ubuntu上默认是没有安装NFS服务器的,首先要安装NFS服务程序:

xhylyx@xhylyx-desktop:~$ sudo apt-get install nfs-kernel-server

安装nfs-kernel-server时,apt会自动安装nfs-common和portmap

这样,宿主机就相当于NFS Server

2.配置NFS

(1)配置portmap

方法1: 编辑/etc/default/portmap, 将 -i 127.0.0.1 去掉.

方法2: $ sudo dpkg-reconfigure portmap , 对Should portmap be bound to the loopback address? 选N.

(2)配置/etc/hosts.deny

禁止任何host(主机)能和你的NFS服务器进行NFS连接,加入:

### NFS DAEMONS

portmap:ALL

lockd:ALL

mountd:ALL

rquotad:ALL

statd:ALL

(3)配 置/etc/hosts.allow

允许那些你想要的主机和你的NFS服务器建立连接。下列步骤将允许任何IP地址以192.168.2开头的主机(连 接到NFS服务器上),也可以指定

特定的IP地址,加入:

### NFS DAEMONS

portmap: 192.168.2.

lockd: 192.168.2.

rquotad: 192.168.2.

mountd: 192.168.2.

statd: 192.168.2.

/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似"mask"的意思. 现在/etc/hosts.deny中禁止所有用

户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问.

xhylyx@xhylyx-desktop:~$sudo /etc/init.d/portmap restart

重启portmap daemon.

(4)配置/etc/exports

NFS挂载目录及权限由/etc/exports文件定义

比如我要将将我的/opt/FriendlyARM/QQ2440/root_nfs目录让172.16.53.*的IP共享, 则在该文件末尾添加下列语句:

/opt/FriendlyARM/QQ2440/root_nfs 172.16.53.*(rw,sync,no_root_squash)

或者:/opt/FriendlyARM/QQ2440/root_nfs 172.16.53.0/24(rw,sync,no_root_squash)

172.16.53.* 网段内的NFS客户端能够共享NFS服务器/opt/FriendlyARM/QQ2440/root_nfs目录内容.且有读,写权限, 并且该用户进入

/opt/FriendlyARM/QQ2440/root_nfs目录后的身份为root

最好加上sync, 否则 $ sudo exportfs -r 时会给出警告, sync是NFS的默认选项.

root@xhylyx-desktop:/#showmount -e 查看NFS server的export list.

若更改了/etc/exports, 运行 xhylyx@xhylyx-desktop:~$sudo exportfs -r 更新

运行 xhylyx@xhylyx-desktop:~$ sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务

(5)测试NFS

可以尝试一下挂载本地磁盘

我前面开始时已经提到了我的主机IP是172.16.53.214

我现在试把/opt/FriendlyARM/QQ2440/root_nfs目录挂载到/mnt目录下

root@xhylyx-desktop:/#mount -t nfs 172.16.53.214:/opt/FriendlyARM/QQ2440/root_nfs /mnt

成功的挂载上的话你会在/mnt目录下看到root_nfs这个文件夹下的内容

(6)错误解决
# mount -t nfs -o ro,soft,intr fs:/share /mnt/fs/share

mount: wrong fs type, bad option, bad superblock on fs04:/share,

missing codepage or helper program, or other error

(for several filesystems (e.g. nfs, cifs) you might

need a /sbin/mount. helper program)

In some cases useful info is found in syslog - try

dmesg | tail or so
解决
# apt-get install nfs-common

没有评论:

发表评论