1.启动NFS相关服务

rpm -qantfs-utls portmap #查看是否已安装ntfs

service portmap start #启动portmap服务

/etc/init.d/portmap status #可以查看状态

netstat -nlt #查看端口,出现111端口

rpcinfo -p localhost #报告RPC服务

/etc/init.d/nfs start #启动nfs服务

[root@localhost ~]# /etc/init.d/nfs start

启动 NFS 服务:                                            [确定]

关掉 NFS 配额:                                            [确定]

启动 NFS 守护进程:                                        [确定]

启动 NFS mountd                                          [确定]

[root@localhost ~]# /etc/init.d/nfs status  #检查nfs状态

rpc.mountd (pid 3983) 正在运行...

nfsd (pid 3980 3979 3978 3977 3976 3975 3974 3973) 正在运行...

rpc.rquotad (pid 3951) 正在运行...

1.1nfsd

主是功能是管理Client端口是否能够登入主机,其中还包含登入者的ID

2.配置nfs开机自启动

chkconfig portmap on

chkconfig nfs on

chkconfig--list | egrep "portmap | nfs" 检查配置启动

3.nfs的配置文件

/etc/exports#文件配置格式为

nfs共享目录客户端地址1(参数1客户端地址2(参数)

例一

/data/110.0.0.0/24(rw,sync) # rw允许读写,sync数据同步写#入到内存和硬盘中。在IP地址中出*代表所有主机,如10.0.0.*/24代表掩码。

/data/110.0.0.0/24(rw,sync,all_squash,anonuid=2000,anongi=2000)  

#生产环境常用的配置适合多客户端共离一个NFS目录,

/data/110.0.0.15(ro) #只读共享

echo"/data  192.168.0.0/24(rw,sync)">> /etc/exports #没音(rw前没有空格。

/etc/init.d/nfs reload #重载配置文件

[root@localhost~]# showmount -e 192.168.0.246  #查看主机有哪些共享目录

Export list for 192.168.0.246:

/data 192.168.0.0/24

mount-t nfs 192.168.0.246:/data  /mnt 持载目录

chmod777 /data #允许目录可写

id apache  uid=48(apache) gid=48(apache) groups=48(apache)

/data10.0.0.0/24(rw,sync,all_squash,anonuid=48,anongi=48)

chown apache.apache /data  #同时修改目录权限

chmod777 /data #允许目录可写

cat /var/lib/nfs/etab  #显示哪个权限的用会连接过NFS

cat /var/lib/nfs/rmtab #显示正在连接的用户

[root@localhost mnt]# cat /var/lib/nfs/etab

/data   10.0.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=48,anongid=48)

[root@localhost mnt]# cat/var/lib/nfs/rmtab

192.168.0.246:/data:0x00000001

永久挂载NFS目录可以在/etc/fsta中进行配置

192.168.0.246:/data    /mnt  nfsdefaults 1 1

注意:在生产环境中,对于共享的NFS目录,一般不会配置到/etc/fstab里。因为,在客户端主机重启时如果由于网络等原因连接不上nfs server时就会导致客户端主机无法启动。一般通过mount -t nfs 192.168.0.246:/data /mnt 命令放到rc.local中实现开机自动挂载NFS,不过这也会引起另外的问题,就是重起nfs客户端后,可能挂载NFS不成功。

如果想卸载挂载点出现占用时可强制卸载挂载点

umount-lf /mnt

1.生产环境应用案例

要点:NFS服务默认的匿名的UIDGID655534

/etc/init.d/portmap  #启动RPC服务

/etc/init.d/portmap status

service nfs restart

vim /etc/exports

mkdir /data

/etc/init.d/nfs reload

tail /etc/exports

/data 192.168.0.0/24(rw,sync)

[root@localhost ~]# cat /var/lib/nfs/etab

/data 192.168.0.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

方法一、32位操作系统

showmount –e192.168.0.246 #查看目标主机共享的目录

mount -t nfs192.168.0.246:/data /mnt  #客户端挂载

/mnt目录里写文件。

/data 这个目录不允许客户端写的。可以使改变权限

chown -Rnobody.nobody /data  #修改止目录的用户权限

chmod 777 /data  #修改可写可执行

/etc/init.d/nfsreload

vim /etc/exports

/data 192.168.0.0/24(rw,sync,all_squash) #无论什么用户都映射成nobody用户

方法二、机器为64位系统时。5.x

Vim/etc/exports

/data 192.168.0.0/24(rw,sync,all_squash,anonuid=4292967294,anongid=4292967294)

方法三、万能的方法

要在NFS客户端和服务端都要建立WYJ用户和WYJ用户组。

groupaddwyj –g 1207

useraddwyj-u 1207 –g wyj

/data192.168.0.0/245(rw,sync,all_squash,anonuid=1207,anongid=1207)

/etc/init.d/nfsreload

mount –tnfs 192.168.0.246:/data /mnt

mount –tnfs –o nosuid,noexec,nodev,rw,hard,intr,rsize=32768 192.168.0.246:/data /mnt

intr当使用hard方式挂载时,若加上inter这个参数,则当RPC持续呼叫时,呼叫是可以被中断的(interrupted)

rsize,wsize读写区块大小,影响客户端与服务端传输数据的缓冲存储容易,一般来说在局域网,在内存许可的情况下,可以设大点。

exportfs#可以不通过配置文件实现共享

exportfs–o rw,sync,all_squash,mp,fsid=2 192.168.0.0/24:/data /mnt

/etc/init.d/nfs–reload #相同作用不reload也可以,使用/usr/sbin/exportfs –r