nfs配置过程

1、开启portmap和nfs服务service portmap start
     service nfs start
     chkconfig --level nfs 35 on
     chkconfig --level protmap 35 on

2、将要共享的目录写到exports文件中 假设共享的目录为 /sharedisk/
     vim /etc/exports
     在exports文件中添加
     /sharedisk    192.168.0.0/24(rw,no_root_squash,async)
     #表示将/sharedisk这个目录共享给192.168.0.*这些客户机,括号中的参数设置意义为:

01 ro                     该主机对该共享目录有只读权限
02 rw                    该主机对该共享目录有读写权限
03 root_squash       客户机用root用户访问该共享文件夹时,将root用户映射成匿名用户
04 no_root_squash  客户机用root访问该共享文件夹时,不映射root用户
05 all_squash          客户机上的任何用户访问该共享目录时都映射成匿名用户
06 anonuid             将客户机上的用户映射成指定的本地用户ID的用户
07 anongid             将客户机上的用户映射成属于指定的本地用户组ID
08 sync                  资料同步写入到内存与硬盘中
09 async                资料会先暂存于内存中,而非直接写入硬盘
10 insecure            允许从这台机器过来的非授权访问

3、重启nfs 或者使用exportfs命令使设置生效
     重启nfs:
     service nfs restart

     用exportfs
     exportfs -rv

     #exportfs用法
     -a :全部mount或者unmount /etc/exports中的内容 
     -r :重新mount /etc/exports中分享出来的目录 
     -u :umount 目录 
     -v :将详细的信息输出到屏幕上
    这样nfs的服务器端就设置好了。

4、在客户端挂载该目录:

     在本地创建挂载的目录 
     mkdir /sharedisk
     mount -t nfs 192.168.0.10:/sharedisk  /sharedisk
     #将服务器192.168.0.10上的/sharedisk/ 路径挂载到本地
     此时,如果服务器端的防火墙有开着的话,将会提示错误,如:
     mount: mount to NFS server '192.168.0.10' failed: System Error: No route to host.
     这个主要是因为防火墙的问题导致的 防火墙上开放对应端口即可
     由于nfs服务需要开启 mountd,nfs,nlockmgr,portmapper,rquotad这5个服务,需要将这5个服务的端口加到iptables里面
     而nfs 和 portmapper两个服务是固定端口的,nfs为2049,portmapper为111。其他的3个服务是用的随机端口,那就需要先把这3个服务的端口设置成固定的。

5、查看当前这5个服务的端口并记录下来 用rpcinfo -p
    把显示 nfs  2049, portmapper  111, 以及剩下的三个服务的端口随便选择一个记录下来
    mountd  976
    rquotad  966
    nlockmgr  33993

6、将这3个服务的端口设置为固定端口,修改/etc/service,添加以下内容(端口号必须在1024以下,且未被占用)
     vim  /etc/services 
     在文件的最后一行添加:
     mountd  976/tcp
     mountd  976/udp
     rquotad  966/tcp
     rquotad  966/udp
     nlockmgr 33993/tcp
     nlockmgr 33993/udp
     保存并退出。 

附带nfs服务端口的设置

[root@localhost]# vi /etc/sysconfig/nfs

# Port rquotad should listen on.
RQUOTAD_PORT=966
# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=33993
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=33993
# Port rpc.mountd should listen on.
MOUNTD_PORT=976
 
其中 portmapper nfs 服务端口是固定的分别是 111 2049

另外 rquotad nlockmgr mountd 服务端口是随机的。由于端口是随机的,这导致防火墙无法设置。

这时需要配置/etc/sysconfig/nfs 使 rquotad nlockmgr mountd 的端口固定。

找到以下几项,将前面的#号去掉。

7、重启下nfs服务。  service nfs restart

8、在防火墙中开放这5个端口
     编辑iptables配置文件   
     vim /etc/sysconfig/iptables
     添加如下行:

01 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p tcp --dport 111 -j ACCEPT
02 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p tcp --dport 976 -j ACCEPT
03 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p tcp --dport 2049 -j ACCEPT
04 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p tcp --dport 966 -j ACCEPT
05 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p tcp --dport 33993 -j ACCEPT
06
07 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p udp --dport 111 -j ACCEPT
08 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p udp --dport 976 -j ACCEPT
09 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p udp --dport 2049 -j ACCEPT
10 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p udp --dport 966 -j ACCEPT
11 -A RH-Firewall-1-INPUT -s 192.168.0.0/24 -m state --state NEW -p udp --dport 33993 -j ACCEPT

保存退出并重启iptables
service iptables restart
重新执行步骤4挂载即可

8、nfs安全设置方面
hosts.allow和hosts.deny设置
hosts.allow设置:
portmap: ip
hosts.deny设置:
portmap:ALL

 

配置完成

 

补充资料

01 ro                      只读访问
02 rw                      读写访问
03 sync                    所有数据在请求时写入共享
04 async                   NFS在写入数据前可以相应请求
05 secure                  NFS通过1024以下的安全TCP/IP端口发送
06 insecure                NFS通过1024以上的端口发送
07 wdelay                  如果多个用户要写入NFS目录,则归组写入(默认)
08 no_wdelay               如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。
09 hide                    在NFS共享目录中不共享其子目录
10 no_hide                 共享NFS目录的子目录
11 subtree_check           如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认)
12 no_subtree_check        和上面相对,不检查父目录权限
13 all_squash              共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
14 no_all_squash           保留共享文件的UID和GID(默认)
15 root_squash             root用户的所有请求映射成如anonymous用户一样的权限(默认)
16 no_root_squas           root用户具有根目录的完全管理访问权限
17 anonuid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的UID
18 anongid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的GID
 

1 /home/share     192.168.102.15(rw,sync,wdelay,hide,nocrossmnt,
2 secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,
3 mapping=identity,anonuid=65534,anongid=65534)
4 /home/share     *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,
5 no_all_squash,subtree_check,secure_locks,acl,mapping=identity,
6 anonuid=65534,anongid=65534)


你可能感兴趣的:(service,用户,文件夹,start,客户机)