####################################
#NFS_Configuration
#Author:楚霏
#Date: 2010-4-20
#Update:2010-4-26
#Env: Centos 5.4 x86_64
####################################
二、环境介绍
####################################
两台机器全是Centos 5.4 x86_64
服务端IP=10.0.0.52
客户端IP=10.0.0.166
####################################
三、配置服务端
####################################
#因为默认已经安装portmap,nfs-utils-lib和nfs-utils,所以直接配置即可
#创建要共享的目录
#nfs的主配置文件是/etc/exports
4 |
/nfsdata 10.0.0.0/24(rw,root_squash,no_all_squash, sync ) |
#保存设置
#配置文件每行分为段:
#第一段为共享的目录,使用绝对路径
#第二段为客户端地址及权限:
地址可以使用完整IP或网段,例如10.0.0.8或10.0.0.0/24,10.0.0.0/255.255.255.0当然也可以
地址可以使用主机名,DNS解析的和本地/etc/hosts解析的都行,支持通配符,例如:*.chengyongxu.com
权限有:
rw:read-write,可读写;
ro:read-only,只读;
sync:文件同时写入硬盘和内存;
async:文件暂存于内存,而不是直接写入内存;
no_root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,也拥有root权限。显然开启这项是不安全的。
root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,拥有匿名用户权限,通常他将使用nobody或nfsnobody身份;
all_squash:不论NFS客户端连接服务端时使用什么用户,对服务端分享的目录来说都是拥有匿名用户权限;
anonuid:匿名用户的UID值,通常是nobody或nfsnobody,可以在此处自行设定;
anongid:匿名用户的GID值。
####################################
四、启动、测试
####################################
#先启动所依赖的postmap
#本地测试
3 |
Export list for 10.0.0.52: |
#创建挂载点
#挂载
1 |
mount -t nfs 10.0.0.52:/nfsdata /root/nfsdata |
#检查
03 |
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw) |
04 |
proc on /proc type proc (rw) |
05 |
sysfs on /sys type sysfs (rw) |
06 |
devpts on /dev/pts type devpts (rw,gid=5,mode=620) |
07 |
/dev/hda1 on /boot type ext3 (rw) |
08 |
tmpfs on /dev/shm type tmpfs (rw) |
09 |
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) |
10 |
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) |
11 |
nfsd on /proc/fs/nfsd type nfsd (rw) |
12 |
10.0.0.52:/nfsdata on /root/nfsdata type nfs (rw,addr=10.0.0.52) |
#写文件进行测试
1 |
echo "This is a test" >> /nfsdata/ test |
#检查一下
#客户端测试
#步骤相似
4 |
mount -t nfs 10.0.0.52:/nfsdata /root/nfsdata |
#检查
03 |
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw) |
04 |
proc on /proc type proc (rw) |
05 |
sysfs on /sys type sysfs (rw) |
06 |
devpts on /dev/pts type devpts (rw,gid=5,mode=620) |
07 |
/dev/hda1 on /boot type ext3 (rw) |
08 |
tmpfs on /dev/shm type tmpfs (rw) |
09 |
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) |
10 |
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) |
11 |
nfsd on /proc/fs/nfsd type nfsd (rw) |
12 |
10.0.0.52:/nfsdata on /root/nfsdata type nfs (rw,addr=10.0.0.52) |
#读写一下检查检查
#注意:
#如果需要开机挂载的话别忘了在/etc/fstab中加入
2 |
/root/nfsdata 10.0.0.52:/nfsdata |
####################################
五、常见错误
####################################
错误一:Cannot register service: RPC
03 |
Shutting down NFS mountd: [ OK ] |
04 |
Shutting down NFS daemon: [ OK ] |
05 |
Shutting down NFS quotas: [ OK ] |
06 |
Shutting down NFS services: [ OK ] |
07 |
Starting NFS services: [ OK ] |
08 |
Starting NFS quotas: Cannot register service: RPC: Unable to receive; errno = Connection refused |
09 |
rpc.rquotad: unable to register (RQUOTAPROG, RQUOTAVERS, udp). |
01 |
错误二:Address already in use |
02 |
tail -f /var/log/message |
04 |
Apr 10 13:43:27 bogon nfsd[15918]: nfssvc: Setting version failed: errno 16 (Device or resource busy) |
05 |
Apr 10 13:43:27 bogon nfsd[15918]: nfssvc: unable to bind UPD socket: errno 98 (Address already in use) |
06 |
Apr 10 13:45:27 bogon nfsd[15978]: nfssvc: Setting version failed: errno 16 (Device or resource busy) |
07 |
Apr 10 13:45:27 bogon nfsd[15978]: nfssvc: unable to bind UPD socket: errno 98 (Address already in use) |
08 |
Apr 10 13:49:05 bogon nfsd[16080]: nfssvc: Setting version failed: errno 16 (Device or resource busy) |
错误三:mount: 10.0.0.52:/nfsdata failed, reason given by server: Permission denied
2 |
a.把该客户端的ip加入服务端的/etc/exports |
3 |
b.服务端的和客户端规则要统一,要么都使用主机名(注意每台机器的hosts文件),要么都使用IP |
错误四:客户端挂载超时
01 |
tail -f /var/log/message |
03 |
Apr 10 14:42:35 localhost kernel: portmap: server localhost not responding, timed out |
04 |
Apr 10 14:42:35 localhost kernel: RPC: failed to contact portmap (errno -5). |
05 |
Apr 10 14:42:46 localhost kernel: RPC: failed to contact portmap (errno -512). |
06 |
Apr 10 14:42:46 localhost kernel: lockd_up: makesock failed, error=-512 |
07 |
Apr 10 14:42:46 localhost kernel: RPC: failed to contact portmap (errno -512). |
11 |
service portmap restart |
错误五:Error: RPC MTAB does not exist.
03 |
Starting NFS services: [ OK ] |
04 |
Starting NFS quotas: [ OK ] |
05 |
Starting NFS daemon: [ OK ] |
06 |
Starting NFS mountd: [ OK ] |
07 |
Starting RPC idmapd: Error: RPC MTAB does not exist. |
12 |
mount -t rpc_pipefs sunrpc /var/lib/nfs/rpc_pipefs/ |
15 |
rpc_pipefs /var/lib/nfs/rpc_pipefs rpc_pipefs defaults 0 0 |
16 |
nfsd /proc/fs/nfsd nfsd defaults 0 0 |
####################################
阅读(1639) | 评论(0) | 转发(0) |