Redhat 6.3 NFS的安装配置、启动及mount挂载方法

一、环境介绍:

  服务器:redhat虚拟机 192.168.253.128

  客户端:redhat虚拟机 192.168.253.129

二、安装:

   redhat 6(在redhat 6.3当中,portmap服务由rpcbind负责) :

yum -y install nfs-utils rpcbind

三、服务器端配置:

1.创建共享目录:
[root@localhost /]# mkdir /usr/local/test

2.NFS文件配置:
[root@localhost /]# vim /etc/exports

#增加一行:
/usr/local/test/ 192.168.253.129(rw,no_root_squash,no_all_squash,sync)

使配置生效:
[root@localhost /]# exportfs -r

注:配置文件说明:

/usr/local/test/ 为共享的目录,使用绝对路径。
192.168.253.129(rw,no_root_squash,no_all_squash,sync) 为客户端的地址及权限,地址可以是一个网段,一个IP地址或者是一个域名,域名支持通配符,如:*.youxia.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值。

3.启动服务:

[root@localhost /]# service rpcbind start
Starting rpcbind:                                          [  OK  ]

[root@localhost /]# service nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Stopping RPC idmapd:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
[root@localhost /]# 


四、客户端挂载:

1.创建需要挂载的目录:
[root@localhost ~]# mkdir /usr/local/test
[root@localhost ~]# 

2.测试挂载:
[root@localhost ~]# showmount -e 192.168.253.128
Export list for 192.168.253.128:
/usr/local/test 192.168.253.129
[root@localhost ~]# 

如果显示:rpc mount export: RPC: Unable to receive; errno = No route to host,则需要在服务端关闭防火墙(稍候会详细说)。

3.挂载:
[root@localhost ~]# mount -t nfs 192.168.253.128:/usr/local/test /usr/local/test

[root@localhost ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
192.168.253.128:/usr/local/test on /usr/local/test type nfs (rw,vers=4,addr=192.168.253.128,clientaddr=192.168.253.129)
[root@localhost ~]# 

如果信息如上显示则挂载成功!

4、测试:

客户端生成一个文件:
[root@localhost /]# cd /usr/local/test/
[root@localhost /]# echo "hello nfs test">>test
[root@localhost /]# ll
total 4
-rw-r--r-- 1 root root 15 Apr  9 13:24 test
[root@localhost /]#

服务端检查:
[root@localhost /]# cd /usr/local/test/
[root@localhost test]# ll
total 4
-rw-r--r-- 1 root root 15 Apr  9 13:24 test
[root@localhost test]# 

挂载成功!

五、解除挂载:
[root@localhost ~]# umount /usr/local/test

[root@localhost ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
nfsd on /proc/fs/nfsd type nfsd (rw)
[root@localhost ~]# 

如果遇到:umount.nfs: /usr/local/test: device is busy

可能用命令:
[root@localhost /]# fuser -m -v /usr/local/test

                     用户     进程号 权限   命令
/usr/local/test/:              root       2798 ..c.. bash
                     root       2996 ..c.. su
[root@localhost /]# kill -9 2798

[root@localhost /]# kill -9 2996

[root@localhost /]# umount /usr/local/test
[root@localhost /]#

六、服务器端防火墙设置(NFS 开启防墙配置):
NFS 用到的服务有 portmapper nfs rquotad nlockmgr mountd
通过命令 rpcinfo -p 可查看nfs使用的端口

其中 portmapper nfs 服务端口是固定的分别是 111 2049
另外 rquotad nlockmgr mountd 服务端口是随机的。由于端口是随机的,这导致防火墙无法设置。
这时需要配置/etc/sysconfig/nfs 使 rquotad nlockmgr mountd 的端口固定。
找到以下几项,将前面的#号去掉。
RQUOTAD_PORT=875
LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892


[root@localhost /]# service nfs restart

[root@localhost /]# rpcinfo -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100024    1   udp  36073  status
    100024    1   tcp  48571  status
    100011    1   udp    875  rquotad
    100011    2   udp    875  rquotad
    100011    1   tcp    875  rquotad
    100011    2   tcp    875  rquotad
    100005    1   udp    892  mountd
    100005    1   tcp    892  mountd
    100005    2   udp    892  mountd
    100005    2   tcp    892  mountd
    100005    3   udp    892  mountd
    100005    3   tcp    892  mountd
    100003    2   tcp   2049  nfs
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    2   tcp   2049  nfs_acl
    100227    3   tcp   2049  nfs_acl
    100003    2   udp   2049  nfs
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    2   udp   2049  nfs_acl
    100227    3   udp   2049  nfs_acl
    100021    1   udp  32769  nlockmgr
    100021    3   udp  32769  nlockmgr
    100021    4   udp  32769  nlockmgr
    100021    1   tcp  32803  nlockmgr
    100021    3   tcp  32803  nlockmgr
    100021    4   tcp  32803  nlockmgr

设置防火墙:
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p tcp --dport 875 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p tcp --dport 2049 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p tcp --dport 32769 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p tcp --dport 32803 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p tcp --dport 892 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p udp --dport 892 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p udp --dport 32803 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p udp --dport 32769 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p udp --dport 111 -j ACCEPT
[root@localhost /]# iptables -I INPUT -s 192.168.253.0/24 -p udp --dport 2049 -j ACCEPT

猜你喜欢

转载自sarawon.iteye.com/blog/2047963