最详细的NFS服务端+客户端配置

NFS服务企业级配置实战

1、服务器信息

由于我的是在虚拟机中实战的,服务器信息如下

[root@localhost~]# cat /etc/redhat-release

CentOSrelease 6.6 (Final)

[root@localhost~]# uname -r

2.6.32-504.el6.x86_64

[root@localhost~]# uname -m

x86_64

2、查看并启动rpcbind以及NFS服务,然后加入开机自启

[root@localhost~]# /etc/init.d/rpcbind status

rpcbind 已停

开启rpcbind服务

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

正在启动 rpcbind:                                        [确定]

[root@localhost~]# /etc/init.d/rpcbind status

rpcbind(pid  3746) 正在运行...

查看NFS服务,并启动

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

rpc.svcgssd已停

rpc.mountd已停

nfsd 已停

rpc.rquotad已停

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

启动 NFS 服务:                                            [确定]

关掉 NFS 配额:                                            [确定]

启动 NFS mountd:                                          [确定]

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

正在启动 RPC idmapd:                                     [确定]

加入开机自启动

[root@localhost~]# chkconfig --list rpcbind

rpcbind             0:关闭      1:关闭      2:启用      3:启用      4:启用      5:启用      6:关闭

[root@localhost~]# chkconfig --list nfs

nfs                0:关闭      1:关闭      2:关闭      3:关闭      4:关闭      5:关闭      6:关闭

[root@localhost~]# chkconfig nfs on

[root@localhost~]# chkconfig --list nfs

nfs                0:关闭      1:关闭      2:启用      3:启用      4:启用      5:启用      6:关闭

3、创建要共享的文件并授权

[root@localhost~]# mkdir /sharedata

[root@localhost~]# ls -ld /sharedata/

drwxr-xr-x2 root root 4096 9月  18 09:52 /sharedata/

[root@localhost~]# touch /sharedata/wu.txt

[root@localhost~]# echo "This is a test NFS">/sharedata/wu.txt

[root@localhost~]# chown -R nfsnobody.nfsnobody /sharedata/

[root@localhost~]# ls -ld /sharedata/

drwxr-xr-x2 nfsnobody nfsnobody 4096 9月  1809:52 /sharedata/

检测nfsnobody是否存存在

[root@localhost~]# grep nfsnobody /etc/passwd

nfsnobody:x:65534:65534:AnonymousNFS User:/var/lib/nfs:/sbin/nologin

注意:由于在NFS服务器端要把共享的NFS目录赋予NFS默认用户nfsnobody用户和用户组权限,如果不设置这个权限,会导致NFS客户端访问时无法通过NFS本地共享目录权限写入数据。

4、在服务端配置文件,并在本地查看挂载信息

##写入配置文件

[root@localhost~]#echo "/sharedata 172.16.30.0/24(rw,sync)" /etc/exports

##查看配置文件

[root@localhost~]# tail  /etc/exports

/sharedata172.16.30.0/24(rw,sync)

##重新加载

[root@localhost~]# exportfs -rv

exporting172.16.30.0/24:/sharedata

##在服务器端检测挂载情况

[root@localhostlog]# showmount -e localhost

Exportlist for localhost:

/sharedata172.16.30.0/24

##查看NFS Server配置文件的参数

[root@localhostlog]# cat /var/lib/nfs/etab

/sharedata 172.16.30.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)

5、把共享的软件挂载在本地服务端

[root@localhostlog]# mount -t nfs 172.16.30.91:/sharedata /mnt

[root@localhostlog]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              18G  3.9G  13G  24% /

tmpfs                 491M     0 491M   0% /dev/shm

/dev/sda1             190M   27M 153M  15% /boot

172.16.30.91:/sharedata

                       18G  3.9G  13G  24% /mnt

 

 

服务器端NFS配置已经完成。

 

6、客户端配置:

 

##安装rpcbind和NFS

 

[root@localhost~]# yum install rpcbind -y

[root@localhost~]# rpm -qa rpcbind

rpcbind-0.2.0-12.el6.x86_64

 

[root@localhost~]# yum install nfs-utils -y

[root@localhost~]# rpm -qa nfs-utils

nfs-utils-1.2.3-70.el6_8.1.x86_64

启动RPC服务(无须启动NFS服务)

##查看服务器共享的文件

[root@localhost~]# showmount -e 172.16.30.91

Exportlist for 172.16.30.91:

/sharedata172.16.30.0/24

##挂载到客户机上

 [root@localhost ~]# mount -t nfs172.16.30.91:/sharedata /mnt/

##查看磁盘

[root@localhost~]# df -h

Filesystem            Size  Used Avail Use% Mounted on

/dev/sda3              18G 3.2G   14G  19% /

tmpfs                 491M     0 491M   0% /dev/shm

/dev/sda1             190M   27M 153M  15% /boot

172.16.30.91:/sharedata

                       18G  3.9G  13G  24% /mnt

7、测试读写数据:

##查看服务端共享的文件

[root@localhost~]# ls /mnt/

wu.txt

[root@localhost~]# cat /mnt/wu.txt

This is atest NFS

##客户端新建文件

[root@localhost~]# mkdir /mnt/userwu

[root@localhost~]# tree /mnt/

/mnt/

├── userwu

└── wu.txt

 

1directory, 1 file

8、将rpcbind服务和挂载加入开机自启动

[root@localhost~]# echo "/etc/init.d/rpcbind start" >>/etc/rc.local

[root@localhost~]# echo "/bin/mount -t nfs 172.16.30.91:/sharedata /mnt">>/etc/rc.local

[root@localhost~]# tail -2 /etc/rc.local

/etc/init.d/rpcbindstart

/bin/mount-t nfs 172.16.30.91:/sharedata /mnt

至此,NFS服务端和客户端配置完成

 

你可能感兴趣的:(Linux运维)