centos6 NFS网络共享服务部署

服务器系统 角色 IP 
CentOS6.8 x86_64 NFS服务器端(NFS-server) 192.168.1.14 
Centos6.8 x86_64 NFS客户端(Web-lamp01) 192.168.1.15 
Centos6.8 x86_64 NFS客户端(Web-lnmp02) 192.168.1.16

 

10.3.2 NFS服务部署架构图

 wKiom1i5dVPgOnYjAABWvQkoKLY475.jpg-wh_50

 

检查安装包是否已安装

 [[email protected] ~]# rpm -qa nfs-utils rpcbind
 rpcbind-0.2.0-11.el6_7.x86_64
 nfs-utils-1.2.3-64.el6.x86_64

代表安装过了,无需安装,如上面没有输出信息则执行下面命令安装

 

安装NFS软件:

yum -y install nfs-utils rpcbind

 wKioL1i5dTKCMk4PAABUBZqMLsY030.jpg-wh_50

检查安装包是否安装上

[[email protected] ~]# rpm -qa nfs-utils rpcbind
rpcbind-0.2.0-11.el6_7.x86_64
nfs-utils-1.2.3-64.el6.x86_64

接下来启动相应的服务

[[email protected] ~]# /etc/init.d/rpcbind status  <==检查rpcbind服务状态
rpcbind is stopped
[[email protected] ~]# rpcinfo -p localhost  <==rpcbind服务未启动检查 rpcinfo信息报错
rpcinfo: can't contact portmapper: RPC: Remote system error - Connection refused
[[email protected] ~]# /etc/init.d/rpcbind start  <==启动rpcbind服务
Starting rpcbind:                                          [  OK  ]
[[email protected] ~]# /etc/init.d/rpcbind status
rpcbind (pid  2083) is running...
[[email protected] ~]# /etc/init.d/nfs status  <==查看nfs服务状态
rpc.svcgssd is stopped
rpc.mountd is stopped
nfsd is stopped
rpc.rquotad is stopped
[[email protected] ~]# /etc/init.d/nfs start  <==启动nfs服务
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

设置开机自启动

[[email protected] ~]# chkconfig --level 35  nfs on  <==设置nfs服务开机自启动
[[email protected] ~]# chkconfig --list nfs
 nfs             0:off   1:off   2:off   3:on    4:off   5:on    6:off
[[email protected] ~]# chkconfig --level 35 rpcbind on
[[email protected] ~]# chkconfig --list rpcbind     <==<==设置rpcbind服务开机自启动
 rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off

10.5 配置NFS服务端

10.5.1 NFS服务端配置文件路径

NFS服务配置文件路径为:/etc/exports,并且默认是为空。

1 [[email protected] ~]# ll /etc/exports
2 -rw-r--r--. 1 root root 0 Jan 12  2010 /etc/exports
3 [[email protected] ~]# cat /etc/exports
4 [[email protected] ~]#

10.5.2 编辑NFS服务端配置文件

1 [[email protected] ~]# vim /etc/exports
2 /data 192.168.1.0/24(rw,sync,all_squash)  <==添加如下内容
3 [[email protected] ~]# mkdir -p /data  <==创建共享目录/data
4 [[email protected] ~]# ls -ld /data
5 drwxr-xr-x. 3 root root 4096 Nov 26 15:19 /data  <==当前共享目录的属主属组分别为root
6 [[email protected] ~]# chown -R nfsnobody.nfsnobody /data  <==修改/data及子文件属主属组为nfsnobody
7 [[email protected] ~]# ls -ld /data                      
8 drwxr-xr-x. 3 nfsnobody nfsnobody 4096 Nov 26 15:19 /data

10.5.3 重新加载NFS服务(优雅重启)

1 [[email protected] ~]# /etc/init.d/nfs reload ===exportfs -r
2 [[email protected] ~]# cat /var/lib/nfs/etab                
3 /data   192.168.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,all_squash)
4 [[email protected] ~]# showmount -e 192.168.1.14 <==挂载前首先检查有权限需要挂载的信息
5 Export list for 192.168.1.14:
6 /data 192.168.1.0/24 <---可以看到共享/data目录

10.5.4 检查或测试挂载

1 [[email protected] test]# mount -t nfs 192.168.1.14:/data /mnt  ##将/data共享目录挂载到/mnt目录
2 [[email protected] test]# df -h
3 Filesystem          Size  Used Avail Use% Mounted on
4 /dev/sda3           7.1G  1.5G  5.3G  22% /
5 tmpfs               279M     0  279M   0% /dev/shm
6 /dev/sda1           190M   36M  145M  20% /boot
7 192.168.1.14:/data  7.1G  1.5G  5.3G  22% /mnt

注意:

大型企业工作场景统一按照运维规范将服务的启动写到/etc/rc.local文件里,而不用chkconfig管理。把/etc/rc.local文件作为本机的重要档案,所有服务的开机自启动都必须放入/etc/rc.local。这样规范的好处是,一旦有运维人员离职,或者业务迁移时都通过/etc/rc.local很容易查看服务器相关的服务,可以方便运维管理。并且把启动命令放入到/etc/rc.local文件中一定要加上启动服务的注释。

 1 [[email protected] test]# vim /etc/rc.local 
 2 #!/bin/sh
 3 #
 4 # This script will be executed *after* all the other init scripts.
 5 # You can put your own initialization stuff in here if you don't
 6 # want to do the full Sys V style init stuff.
 7 
 8 touch /var/lock/subsys/local
 9 #start up nfs services by zhurui at 20160226
10 /etc/init.d/rpcbind start <==开机自启rpcbind服务
11 /etc/init.d/nfs start  <==开机自启nfs服务

Web-lamp01客户端部署:

 1 1.安装软件
 2 [[email protected] ~]# yum -y install nfs-utils rpcbind   
 3 Loaded plugins: fastestmirror, security
 4 Setting up Install Process
 5 Loading mirror speeds from cached hostfile
 6  * base: mirrors.sina.cn
 7  * extras: mirrors.opencas.cn
 8  * updates: centos.ustc.edu.cn
 9 base                                             | 3.7 kB     00:00     
10 extras                                           | 3.4 kB     00:00     
11 extras/primary_db                                |  34 kB     00:00     
12 updates                                          | 3.4 kB     00:00 
13 2.启动rpcbind
14 [[email protected] ~]# /etc/init.d/rpcbind start
15 Starting rpcbind:                                          [  OK  ]
16 [[email protected] ~]# 
17 3.配置开机自启动
18 [[email protected] ~]# chkconfig --level 35 rpcbind on
19 [[email protected] ~]# chkconfig --list rpcbind
20 rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
21 [[email protected] ~]# 
22 4.测试服务端共享
23 [[email protected] ~]# showmount -e 192.168.1.14
24 Export list for 192.168.1.14:
25 /data 192.168.1.0/24
26 5.挂载
27 [[email protected] ~]# mount -t nfs 192.168.1.14:/data /mnt
28 [[email protected] ~]# df -h
29 Filesystem          Size  Used Avail Use% Mounted on
30 /dev/sda3           7.1G  1.5G  5.3G  22% /
31 tmpfs               279M     0  279M   0% /dev/shm
32 /dev/sda1           190M   36M  145M  20% /boot
33 192.168.1.14:/data  7.1G  1.5G  5.3G  22% /mnt
34 6.测试读,写
35 服务器端:
36 [[email protected] test]# cd /data/
37 [[email protected] data]# ll
38 total 8
39 -rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
40 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
41 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
42 [[email protected] data]# mkdir zhurui1
43 [[email protected] data]# ll
44 total 12
45 -rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
46 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
47 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
48 drwxr-xr-x. 2 root      root      4096 Nov 28 12:21 zhurui1
49 客户端:
50 [[email protected] ~]# cd /mnt/
51 [[email protected] mnt]# ll
52 total 4
53 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
54 [[email protected] mnt]# touch fs.sf
55 [[email protected] mnt]# ll
56 total 4
57 -rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
58 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
59 [[email protected] mnt]# mkdir zhurui
60 [[email protected] mnt]# ls -ld zhurui/
61 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui/
62 [[email protected] mnt]# ll
63 total 12
64 -rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
65 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
66 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui
67 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:21 zhurui1
68 7.开机自启动
69 [[email protected] mnt]# vim /etc/rc.local 
70 #start  up rpcbind services by zhurui 20160226
71 
72 /etc/init.d/rpcbind start
73 
74 /bin/mount -t nfs 192.168.1.14:/data /mnt

Web-lnmp02客户端部署跟Web-lamp01部署步骤相同,这里就不多加说明

1.安装软件
2 [[email protected] ~]# yum -y install nfs-utils rpcbind   
3 Loaded plugins: fastestmirror, security
4 Setting up Install Process
5 Loading mirror speeds from cached hostfile
6  * base: mirrors.sina.cn
7  * extras: mirrors.opencas.cn
8  * updates: centos.ustc.edu.cn
9 base                                             | 3.7 kB     00:00     
10 extras                                           | 3.4 kB     00:00     
11 extras/primary_db                                |  34 kB     00:00     
12 updates                                          | 3.4 kB     00:00 
13 2.启动rpcbind
14 [[email protected] ~]# /etc/init.d/rpcbind start
15 Starting rpcbind:                                          [  OK  ]
16 [[email protected] ~]# 
3.配置开机自启动
[[email protected] ~]# chkconfig --level 35 rpcbind on
[[email protected] ~]# chkconfig --list rpcbind
rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
[[email protected] ~]# 
4.测试服务端共享
[[email protected] ~]# showmount -e 192.168.1.14
Export list for 192.168.1.14:
/data 192.168.1.0/24
5.挂载
[[email protected] ~]# mount -t nfs 192.168.1.14:/data /mnt
[[email protected] ~]# df -h
Filesystem          Size  Used Avail Use% Mounted on
/dev/sda3           7.1G  1.5G  5.3G  22% /
tmpfs               279M     0  279M   0% /dev/shm
/dev/sda1           190M   36M  145M  20% /boot
192.168.1.14:/data  7.1G  1.5G  5.3G  22% /mnt
6.测试读,写
服务器端:
[[email protected] test]# cd /data/
[[email protected] data]# ll
total 8
-rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
[[email protected] data]# mkdir zhurui1
[[email protected] data]# ll
total 12
-rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
drwxr-xr-x. 2 root      root      4096 Nov 28 12:21 zhurui1
客户端:
[[email protected] ~]# cd /mnt/
[[email protected] mnt]# ll
total 4
drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
[[email protected] mnt]# touch fs.sf
[[email protected] mnt]# ll
total 4
-rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
[[email protected] mnt]# mkdir zhurui
[[email protected] mnt]# ls -ld zhurui/
drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui/
[[email protected] mnt]# ll
total 12
-rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui
drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:21 zhurui1
7.开机自启动
[[email protected] mnt]# vim /etc/rc.local 
#start  up rpcbind services by zhurui 20160226
/etc/init.d/rpcbind start
/bin/mount -t nfs 192.168.1.14:/data /mnt

mount挂载性能优化参数选项

(1)禁止更新目录及文件时间戳挂载

 mount -t nfs -o noatime,nodiratime 192.168.1.14:/data

(2)安全加优化的挂载方式

 mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 192.168.1.14:/data /mnt

wKioL1i5daSjStVtAAD9GVWTmFw581.jpg-wh_50

(3)默认的挂载方式

 mount -t nfs 192.168.1.14:/data /mnt

10.7 NFS内核优化

对应的具体内核优化命令:

cat >>/etc/sysctl.conf<<EOF
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
EOF

执行sysctl -p生效
















本文转自younger00851CTO博客,原文链接: http://blog.51cto.com/younger008/1903107,如需转载请自行联系原作者