NFS 网络文件系统快速部署手册

NFS服务端部署配置

一、安装nfs-utils和rpcbind服务,安装完后检查

# yum install -y nfs-utils rpcbind

# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-12.el6.x86_64
nfs-utils-1.2.3-70.el6_8.1.x86_64

二、启动rpcbind服务

# /etc/init.d/rpcbind start
Starting rpcbind           [ OK ]
# /etc/init.d/rpcbind status
rpcbind (pid 60979) is running...

三、检查rpcbind服务状态
rpcbind 服务运行在tcp/udp的111端口

# lsof -i:111
COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
rpcbind 60979  rpc    6u  IPv4 300613      0t0  UDP *:sunrpc
rpcbind 60979  rpc    8u  IPv4 300616      0t0  TCP *:sunrpc (LISTEN)
rpcbind 60979  rpc    9u  IPv6 300618      0t0  UDP *:sunrpc
rpcbind 60979  rpc   11u  IPv6 300621      0t0  TCP *:sunrpc (LISTEN)

rpcinfo -p localhost  查看当前的资源池

# rpcinfo -p localhost
   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


四、启动nfs服务

Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

五、检查nfs服务状态

# /etc/init.d/nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 61035) is running...
nfsd (pid 61051 61050 61049 61048 61047 61046 61045 61044) is running...
rpc.rquotad (pid 61030) is running...

nfs的主端口号2049
# netstat -nltpu | grep 2049
tcp        0      0 0.0.0.0:2049                0.0.0.0:*                   LISTEN      -                  
tcp        0      0 :::2049                     :::*                        LISTEN      -                  
udp        0      0 0.0.0.0:2049                0.0.0.0:*                               -                  
udp        0      0 :::2049                     :::*                                    -

六、配置rpcbind及nfs服务开机自启动

# chkconfig rpcbind on
# chkconfig nfs on

七、配置服务端(/etc/exports 默认该文件为空)

NFS共享的目录        NFS客户端地址(参1, 2......)

实例:(共享目录 /nfs_data)

mkdir /nfs_data
chown -R nfsnobody.nfsnobody /nfs_data
vim /etc/exports
# share /nfs_data by oldboy for bingbing at 20161123
/nfs_data       172.16.10.0/24(rw,sync)

八、重启NFS服务

# /etc/init.d/nfs reload         # 平滑重启服务

九、检查配置是否成功

# showmount -e 172.16.10.150
Export list for 172.16.10.150:
/nfs_data 172.16.10.0/24             显示此行表示配置成功

十、查看共享配置参数

# cat /var/lib/nfs/etab
/nfs_data       172.16.10.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,
anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)

NFS客户端部署配置

一、安装nfs-utils和rpcbind服务,安装完后检查

# yum install -y nfs-utils rpcbind
# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-12.el6.x86_64
nfs-utils-1.2.3-70.el6_8.1.x86_64

二、启动rpcbind服务

# /etc/init.d/rpcbind start
Starting rpcbind:                                          [  OK  ]

三、检查是否能与nfs-server进行通信,并查看有那些共享目录。

# showmount -e 172.16.10.150
Export list for 172.16.10.150:
/nfs_data 172.16.10.0/24

四、将/nfs_data目录挂载到nfs_test的本地 /mnt目录

# mount -t nfs 172.16.10.150:/nfs_data /mnt
# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/sda3                      43G  4.9G   36G  13% /
tmpfs                         495M     0  495M   0% /dev/shm
/dev/sda1                     976M   27M  898M   3% /boot
172.16.10.150:/nfs_data    43G  5.7G   35G  15% /mnt

五、在/mnt目录下创建文件,然后到NFS服务端/nfs_data查看是否存在/mnt目录下创建的文件。

# ll /mnt/
-rw-r--r-- 1 nfsnobody nfsnobody 4 Nov 23 14:57 files.txt

# ll /nfs_data/
-rw-r--r-- 1 nfsnobody nfsnobody 4 Nov 23 14:57 files.txt

六、配置服务器重启自动挂载

方法一:(/etc/rc.local)
# cat /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
mount -t nfs 172.16.10.150:/nfs_data /mnt

方法二:(/etc/fstab)
172.16.1.31:/nfs_data    /mnt    nfs    defaults    0    0

使用方法二需要开启netfs服务:
chkconfig netfs on