设为首页 收藏本站
查看: 918|回复: 0

[经验分享] NFS网络共享服务部署

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-3-6 13:40:47 | 显示全部楼层 |阅读模式
                      10.3 NFS服务端部署环境准备
10.3.1 NFS服务部署服务器准备
服务器系统 角色 IP
CentOS6.7 x86_64 NFS服务器端(NFS-server) 192.168.1.14
Centos6.7 x86_64 NFS客户端(Web-lamp01) 192.168.1.15
Centos6.7 x86_64 NFS客户端(Web-lnmp02) 192.168.1.16

10.3.2 NFS服务部署架构图
QQ截图20170306133938.png

10.3.3 NFS服务器端操作系统及内核版本
1 [iyunv@NFS-server ~]# cat /etc/RedHat-release
2 CentOS release 6.7 (Final)
3 [iyunv@NFS-server ~]# username -r
4 [iyunv@NFS-server ~]# uname -r
5 2.6.32-573.el6.x86_64
6 [iyunv@NFS-server ~]# uname -m
7 x86_64
10.4 NFS服务安装前准备
10.4.1 查询nfs-utils和rpcbind包是否安装
1 [iyunv@NFS-server ~]# rpm -qa nfs-utils rpcbind   ##查询结果为两个安装包都未安装
2 [iyunv@NFS-server ~]#
知识扩展:
安装NFS软件安装的3种方法:
检查:rpm -qa nfs-utils rpcbind ←最佳
1)方法1:yum -y install nfs-utils rpcbind

2)方法2:通过系统光盘里的rpm包安装,命令如:rpm -ivh nfs-utils-1.2.3-36.e16.x86_64.rpm
3)方法3:LANG=en
yum grouplist|grep -i nfs
yum groupinstall "NFS file server" -y

10.4.2使用方法1安装所需软件包
QQ截图20170306134008.png
10.4.3检查安装包是否安装上
1 [iyunv@NFS-server ~]# rpm -qa nfs-utils rpcbind
2 rpcbind-0.2.0-11.el6_7.x86_64
3 nfs-utils-1.2.3-64.el6.x86_64
10.4.4 接下来启动相应的服务
1 [iyunv@NFS-server ~]# /etc/init.d/rpcbind status  <==检查rpcbind服务状态
2 rpcbind is stopped
3 [iyunv@NFS-server ~]# rpcinfo -p localhost  <==rpcbind服务未启动检查 rpcinfo信息报错
4 rpcinfo: can't contact portmapper: RPC: Remote system error - Connection refused
5 [iyunv@NFS-server ~]# /etc/init.d/rpcbind start  <==启动rpcbind服务
6 Starting rpcbind:                                          [  OK  ]
7 [iyunv@NFS-server ~]# /etc/init.d/rpcbind status
8 rpcbind (pid  2083) is running...
9 [iyunv@NFS-server ~]# /etc/init.d/nfs status  <==查看nfs服务状态
10 rpc.svcgssd is stopped
11 rpc.mountd is stopped
12 nfsd is stopped
13 rpc.rquotad is stopped
14 [iyunv@NFS-server ~]# /etc/init.d/nfs start  <==启动nfs服务
15 Starting NFS services:                                     [  OK  ]
16 Starting NFS quotas:                                       [  OK  ]
17 Starting NFS mountd:                                       [  OK  ]
18 Starting NFS daemon:                                       [  OK  ]
19 Starting RPC idmapd:                                       [  OK  ]
10.4.5 设置开机自启动
1 [iyunv@NFS-server ~]# chkconfig --level 35  nfs on  <==设置nfs服务开机自启动
2 [iyunv@NFS-server ~]# chkconfig --list nfs
3 nfs             0:off   1:off   2:off   3:on    4:off   5:on    6:off
4 [iyunv@NFS-server ~]# chkconfig --level 35 rpcbind on
5 [iyunv@NFS-server ~]# chkconfig --list rpcbind     <==<==设置rpcbind服务开机自启动
6 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 [iyunv@NFS-server ~]# ll /etc/exports
2 -rw-r--r--. 1 root root 0 Jan 12  2010 /etc/exports
3 [iyunv@NFS-server ~]# cat /etc/exports
4 [iyunv@NFS-server ~]#
10.5.2 编辑NFS服务端配置文件
1 [iyunv@NFS-server ~]# vim /etc/exports
2 /data 192.168.1.0/24(rw,sync,all_squash)  <==添加如下内容


1 [iyunv@NFS-server ~]# vim /etc/exports
2 /data 192.168.1.0/24(rw,sync,all_squash)  <==添加如下内容
3 [iyunv@NFS-server ~]# mkdir -p /data  <==创建共享目录/data
4 [iyunv@NFS-server ~]# ls -ld /data
5 drwxr-xr-x. 3 root root 4096 Nov 26 15:19 /data  <==当前共享目录的属主属组分别为root
6 [iyunv@NFS-server ~]# chown -R nfsnobody.nfsnobody /data  <==修改/data及子文件属主属组为nfsnobody
7 [iyunv@NFS-server ~]# ls -ld /data                     
8 drwxr-xr-x. 3 nfsnobody nfsnobody 4096 Nov 26 15:19 /data
10.5.3 重新加载NFS服务(优雅重启)
1 [iyunv@NFS-server ~]# /etc/init.d/nfs reload ===exportfs -r
2 [iyunv@NFS-server ~]# 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 [iyunv@NFS-server ~]# 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 [iyunv@NFS-server test]# mount -t nfs 192.168.1.14:/data /mnt  ##将/data共享目录挂载到/mnt目录
2 [iyunv@NFS-server 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 [iyunv@NFS-server 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 [iyunv@Web-lamp01 ~]# 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 [iyunv@Web-lamp01 ~]# /etc/init.d/rpcbind start
15 Starting rpcbind:                                          [  OK  ]
16 [iyunv@Web-lamp01 ~]#
17 3.配置开机自启动
18 [iyunv@Web-lamp01 ~]# chkconfig --level 35 rpcbind on
19 [iyunv@Web-lamp01 ~]# chkconfig --list rpcbind
20 rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
21 [iyunv@Web-lamp01 ~]#
22 4.测试服务端共享
23 [iyunv@Web-lamp01 ~]# showmount -e 192.168.1.14
24 Export list for 192.168.1.14:
25 /data 192.168.1.0/24
26 5.挂载
27 [iyunv@Web-lamp01 ~]# mount -t nfs 192.168.1.14:/data /mnt
28 [iyunv@Web-lamp01 ~]# 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 [iyunv@NFS-server test]# cd /data/
37 [iyunv@NFS-server 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 [iyunv@NFS-server data]# mkdir zhurui1
43 [iyunv@NFS-server 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 [iyunv@Web-lamp01 ~]# cd /mnt/
51 [iyunv@Web-lamp01 mnt]# ll
52 total 4
53 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
54 [iyunv@Web-lamp01 mnt]# touch fs.sf
55 [iyunv@Web-lamp01 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 [iyunv@Web-lamp01 mnt]# mkdir zhurui
60 [iyunv@Web-lamp01 mnt]# ls -ld zhurui/
61 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui/
62 [iyunv@Web-lamp01 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 [iyunv@Web-lamp01 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部署步骤相同,这里就不多加说明
14  1 1.安装软件
15  2 [iyunv@Web-lnmp02 ~]# yum -y install nfs-utils rpcbind   
16  3 Loaded plugins: fastestmirror, security
17  4 Setting up Install Process
18  5 Loading mirror speeds from cached hostfile
19  6  * base: mirrors.sina.cn
20  7  * extras: mirrors.opencas.cn
21  8  * updates: centos.ustc.edu.cn
22  9 base                                             | 3.7 kB     00:00     
23 10 extras                                           | 3.4 kB     00:00     
24 11 extras/primary_db                                |  34 kB     00:00     
25 12 updates                                          | 3.4 kB     00:00
26 13 2.启动rpcbind
27 14 [iyunv@Web-lnmp02 ~]# /etc/init.d/rpcbind start
28 15 Starting rpcbind:                                          [  OK  ]
29 16 [iyunv@Web-lnmp02 ~]#
30 17 3.配置开机自启动
31 18 [iyunv@Web-lnmp02 ~]# chkconfig --level 35 rpcbind on
32 19 [iyunv@Web-lnmp02 ~]# chkconfig --list rpcbind
33 20 rpcbind         0:off   1:off   2:on    3:on    4:on    5:on    6:off
34 21 [iyunv@Web-lnmp02 ~]#
35 22 4.测试服务端共享
36 23 [iyunv@Web-lnmp02 ~]# showmount -e 192.168.1.14
37 24 Export list for 192.168.1.14:
38 25 /data 192.168.1.0/24
39 26 5.挂载
40 27 [iyunv@Web-lnmp02 ~]# mount -t nfs 192.168.1.14:/data /mnt
41 28 [iyunv@Web-lnmp02 ~]# df -h
42 29 Filesystem          Size  Used Avail Use% Mounted on
43 30 /dev/sda3           7.1G  1.5G  5.3G  22% /
44 31 tmpfs               279M     0  279M   0% /dev/shm
45 32 /dev/sda1           190M   36M  145M  20% /boot
46 33 192.168.1.14:/data  7.1G  1.5G  5.3G  22% /mnt
47 34 6.测试读,写
48 35 服务器端:
49 36 [iyunv@NFS-server test]# cd /data/
50 37 [iyunv@NFS-server data]# ll
51 38 total 8
52 39 -rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
53 40 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
54 41 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
55 42 [iyunv@NFS-server data]# mkdir zhurui1
56 43 [iyunv@NFS-server data]# ll
57 44 total 12
58 45 -rw-r--r--. 1 nfsnobody nfsnobody    0 Nov 28 12:20 fs.sf
59 46 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 26 15:19 test
60 47 drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Nov 28 12:20 zhurui
61 48 drwxr-xr-x. 2 root      root      4096 Nov 28 12:21 zhurui1
62 49 客户端:
63 50 [iyunv@Web-lnmp02 ~]# cd /mnt/
64 51 [iyunv@Web-lnmp02 mnt]# ll
65 52 total 4
66 53 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
67 54 [iyunv@Web-lnmp02 mnt]# touch fs.sf
68 55 [iyunv@Web-lnmp02 mnt]# ll
69 56 total 4
70 57 -rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
71 58 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
72 59 [iyunv@Web-lnmp02 mnt]# mkdir zhurui
73 60 [iyunv@Web-lnmp02 mnt]# ls -ld zhurui/
74 61 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui/
75 62 [iyunv@Web-lnmp02 mnt]# ll
76 63 total 12
77 64 -rw-r--r--. 1 nobody nobody    0 Nov 28 12:20 fs.sf
78 65 drwxr-xr-x. 2 nobody nobody 4096 Nov 26 15:19 test
79 66 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:20 zhurui
80 67 drwxr-xr-x. 2 nobody nobody 4096 Nov 28 12:21 zhurui1
81 68 7.开机自启动
82 69 [iyunv@Web-lnmp02 mnt]# vim /etc/rc.local
83 70 #start  up rpcbind services by zhurui 20160226
84 71
85 72 /etc/init.d/rpcbind start
86 73
87 74 /bin/mount -t nfs 192.168.1.14:/data /mnt
10.6 mount挂载性能优化参数选项
(1)禁止更新目录及文件时间戳挂载
1 mount -t nfs -o noatime,nodiratime 192.168.1.14:/data
(2)安全加优化的挂载方式
1 mount -t nfs -o nosuid,noexec,nodev,noatime,nodiratime,intr,rsize=131072,wsize=131072 192.168.1.14:/data /mnt
QQ截图20170306134017.png
(3)默认的挂载方式
1 mount -t nfs 192.168.1.14:/data /mnt
10.7 NFS内核优化
对应的具体内核优化命令:
1 cat >>/etc/sysctl.conf<<EOF
2 net.core.wmem_default = 8388608
3 net.core.rmem_default = 8388608
4 net.core.rmem_max = 16777216
5 net.core.wmem_max = 16777216
6 EOF
执行sysctl -p生效
                  


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-350379-1-1.html 上篇帖子: CentOS Samba服务器的搭建与配置(share共享模式) 下篇帖子: RHEL 6.5 安装 grid 报错:CRS-4124 网络
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表