文章目录

  • NFS共享存储(用于内网)
  • 什么是NFS
  • 为什么使用NFS
  • 常见的数据存储方式
  • NFS的作用
  • 测试:nginx页面展示
  • NFS原理
  • NFS配置详解
  • 开机自动挂载
  • 案例(nginx上传)
  • backup
  • nfs
  • web01,web02
  • 访问并查看两个服务器
  • pv uv QPS
  • (httpd协议上传)
  • 部署backup环境
  • 部署nfs环境
  • web01 和 web 2
  • 上传案例--httpd
  • 区别

NFS共享存储(用于内网)

什么是NFS

NFS是Network File System的缩写,中文意思是网络文件共享系统
它的主要功能是通过网络(一般是局域网)让不同的主机系统之间可以共享文件或目录,只支持Linux与Linux之间数据传输。共享存储,⽂件服务器

为什么使用NFS

1.为了实现多台服务器之间数据共享
2.实现多台服务器之间数据一致

常见的数据存储方式

网络存储:glusterfs(大文件)、ceph、OSS
分布式:将多台机器,组成像一台机器一样使用
微服务:将一台机器,拆分成多台机器使用

NFS的作用

如果没有NFS会有什么影响?

测试:nginx页面展示

下载nginx

# 准备两台机器
web1  192.168.15.7
web2  192.168.15.8# 两台机器分别添加nginx.repo : http://nginx.org/en/linux_packages.html#RHEL-CentOS[root@web1 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[root@web1 ~]# yum clean all
[root@web1 ~]# yum makecache
[root@web1 ~]# yum install nginx -y
[root@web1 ~]# systemctl start nginx

编辑nginx网页页面内容

cd /usr/share/nginx/html/                nginx网页页面显示指定的目录文件位置/usr/share/nginx/html/index.html
echo 111 > index.html我们在网页输入web01的网址192.168.15.7,页面是可以显示我们输入的内容111的。
我们只有再次对web02服务器操作命令:echo 111 > /usr/share/nginx/html/index.html才可以实现两台服务器的数据同步。
那怎样才能让web01和web02数据同步显示呢

存储服务器的作用

NFS原理

1.用户进程访问NFS客户端,使用不同的函数对数据进行处理
2.NFS客户端通过TCP/IP连接服务端;
3.NFS服务端接受请求后,会先调用portmap进程进行端口映射;
4.Rpc.nfsd进程用于判断NFS客户端能否连接服务端;
5.Rpc.mount进程用于判断客户端可以对服务端进行哪些操作;
6.最后如果允许操作,客户端可以对服务端磁盘进行修改。#注意:rpcbind是一个远程调用,使用NFS时必须有rpcbind
  • nfs服务端配置
1、关闭防火墙
[root@nfs ~]# systemctl disable --now firewalld2、关闭seLinux
[root@nfs ~]#  sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
[root@nfs ~]# setenforce 03、安装nfs
[root@nfs ~]#  yum install -y nfs-utils rpcbind4、修改配置文件
[root@nfs ~]# vim /etc/exports
[nfs存储目录(挂载点)]   [监听的IP](权限)
/data 172.16.1.0/24(rw,sync,all_squash)5、启动NFS
[root@nfs ~]# systemctl start nfs-server6、查看
[root@nfs ~]# showmount -e
Export list for nfs:
/mnt/data 172.16.1.0/24
[root@nfs ~]# cat /var/lib/nfs/etab
/mnt/data   172.16.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=65534,anongid=65534,sec=sys,rw,secure,root_squash,all_squash)
  • nfs客户端配置
1、关闭防火墙
[root@nfs ~]# systemctl disable --now firewalld2、关闭seLinux
[root@nfs ~]#  sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
[root@nfs ~]# setenforce 0查看挂载点
[root@nfs ~]# showmount -e
Export list for nfs:
/mnt/data 172.16.1.0/163、挂载
[root@nfs ~]# mount -t nfs 172.16.1.31:/mnt/data  /usr/share/nginx/html4、查看挂载详情
[root@web1 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
172.16.1.31:/mnt/data     99G  2.7G   97G   3% /usr/share/nginx/html

NFS配置详解

NFS共享参数 参数作用
rw 读写权限
ro 只读权限
all_squash 当NFS客户端以任意用户访问时,修改权限为NFS服务器的匿名用户(常用
anongid 配合all_squash,指定匿名用户的gid
anonuid 配合all_squash,指定匿名用户的uid,用户为系统用户,必须存在
sync 同时将数据写入内存和磁盘(保证数据不丢失)

开机自动挂载

# 修改/etc/fstab
172.16.1.31:/mnt/data     /usr/share/nginx/html     nfs    defaults  0 0

============================================================================

案例(nginx上传)

1、web服务器访问的页面能够实时的备份到backup服务器
2、web服务器的数据是要共享

backup

用于备份nfs服务器中的/data目录,是rsync的服务端

1、#关闭防火墙
[root@nfs ~]# systemctl disable --now firewalld2、#关闭seLinux
[root@nfs ~]# sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
[root@nfs ~]# setenforce 03、#安装rsync
[root@backup ~]# yum install rsync -y4、#编写rsync的服务端配置文件
[root@backup ~]# vim /etc/rsyncd.conf
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 600
ignore errors
read only = false
list = false
auth users = yeg
secrets file = /etc/rsync.passwd
log file = /var/log/rsyncd.log[backup]
comment = welcome to my backup!
path = /backup
[bak]
comment = "hello world"
path = /bak5、#添加用户  不能登录  没有家目录
[root@backup ~]# useradd rsync -s /sbin/nologin -M6、#创建密码文件并授权
[root@backup ~]# vim /etc/rsync.passwd
yeg:1
[root@backup ~]# chmod -R 600 /etc/rsync.passwd7、#创建备份目录并授权
[root@backup ~]# mkdir /bak
[root@backup ~]# chown -R rsync.rsync /bak8、#启动服务并端口验证
[root@backup ~]# systemctl start rsyncd
[root@backup ~]# netstat -nutlp
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:873             0.0.0.0:*               LISTEN      6986/rsync      tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      6075/rpcbind    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      6651/sshd

nfs

用于存放共享的文件,通过inotify+rsync推送给backup,是rsync的服务端

1、#关闭防火墙
[root@nfs ~]# systemctl disable --now firewalld2、#关闭seLinux
[root@nfs ~]# sed -i '/^SELINUX=/c SELINUX=disabled' /etc/selinux/config
[root@nfs ~]# setenforce 03、#安装nfs rpcbind
[root@nfs data]# yum install nfs-utils rpcbind -y4、#编辑密码文件
[root@nfs ~]# vim /etc/profile.d/YEG.sh
export RSYNC_PASSWORD=15、#重启客户端让文件生效
[root@nfs ~]# source /etc/profile.d/YEG.sh 6、#创建/data目录并统一www用户
[root@nfs ~]# mkdir /data
[root@nfs ~]# groupadd www -g 888
[root@nfs ~]# useradd www -u 888 -g 888
[root@nfs ~]# chown -R www.www /data7、#编写inotify监控脚本
[root@nfs ~]# cat inotify.sh
#!/bin/bash #实时推送备份文件脚本
export RSYNC_PASSWORD=1
dir=/data
#监控的文件
inotifywait -mrq --format '%Xe %w %f' -e create,modify,delete,attrib,close_write ${dir} | while read line; do rsync -avz /data yeg@192.168.15.41::bak; done &>/dev/null &#测试
#nfs端
[root@nfs ~]# bash inotify.sh
[root@nfs ~]# cd /data/
[root@nfs data]# touch q.txt
#backup端
[root@backup /]# cd /bak/
[root@backup bak]# ll
total 0
drwxr-xr-x 2 rsync rsync 19 Apr 21 20:58 data
[root@backup bak]# cd data/
[root@backup data]# ll
total 0
-rw-r--r-- 1 rsync rsync 0 Apr 21 20:58 q.txt
==========================rsync配置完毕,可以同步。以下是NFS当做服务端========================编写配置文件
[root@nfs ~]# vim /etc/exports
/data 192.168.15.0/24(rw,sync,all_squash,anonuid=888,anongid=888)重启后检查配置
[root@nfs data]# systemctl restart  nfs-server rpcbind
[root@nfs ~]# cat /var/lib/nfs/etab
/data   192.168.15.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,all_squash,no_subtree_check,secure_locks,acl,no_pnfs,anonuid=888,anongid=888,sec=sys,rw,secure,root_squash,all_squash)

web01,web02

服务器,是NFS的客户端,两个操作一样

[root@web01 ~]# cd /etc/yum.repos.d/
[root@web01 yum.repos.d]# vim nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@web01 ~]# yum clean all && yum makecache#安装nginx和nfs rpcbind
yum install nginx nfs-utils rpcbind -y#启动rpcbind和nfs
[root@web01 ~]# systemctl start rpcbind nfs#查看挂载点
[root@web01 ~]# showmount -e
Export list for 192.168.15.31:
/data 192.168.15.0/24#统一用户权限
[root@web01 ~]# groupadd www -g 888
[root@web01 ~]# useradd www -u 888 -g 888
[root@web01 ~]# chown -R www.www /usr/share/nginx/html#挂载
[root@web01 ~]# mount -t nfs 192.168.15.31:/data /usr/share/nginx/html#检查挂载
[root@web01 ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   99G  1.9G   98G   2% /
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.6M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/sda1               1014M  133M  882M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
192.168.15.31:/data       99G  2.1G   97G   3% /usr/share/nginx/html#测试权限是否满足
#拉取代码到/usr/share/nginx/html下,并解压
[root@web01 ~]# cd /usr/share/nginx/html/
[root@web01 html]# rz
[root@web01 html]# unzip kaoshi\(1\).zip
Archive:  kaoshi(1).zipinflating: info.php                inflating: bg.jpg                  inflating: index.html              inflating: upload_file.php
[root@web01 html]# ll
total 80
-rw-r--r-- 1 www  www  38772 Apr 27  2018 bg.jpg
-rw-r--r-- 1 www  www   2633 May  4  2018 index.html
-rw-r--r-- 1 www  www     52 May 10  2018 info.php
-rw-r--r-- 1 www  www  26995 Apr 21 16:59 kaoshi(1).zip
-rw-r--r-- 1 root root     0 Apr 21 20:58 q.txt
-rw-r--r-- 1 www  www   1192 Jan 10  2020 upload_file.php

web02只需要重复上述步骤到挂载即可

访问并查看两个服务器

=================================================================================

pv uv QPS

pv : 页面浏览量 6千万

uv : 独立用户浏览量 2千

QPS :每秒查询率 10w - 20w

中型公司流量水平

(httpd协议上传)

基于以上web01和web02是通的

部署backup环境

[root@backup ~]# vim /etc/rsyncd.conf
[sersync]
comment="实时同步"
path=/sersync[root@backup ~]# cat /etc/rsync.passwd
yeg:1[root@backup ~]# mkdir /sersync[root@backup ~]# groupadd www -g1000
[root@backup ~]# useradd www -u1000 -g1000
[root@backup ~]# id www
uid=1000(www) gid=1000(www) groups=1000(www)

部署nfs环境

[root@nfs ~]# vim /etc/exports/sersync    172.16.1.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)[root@nfs ~]# mkdir /sersync[root@nfs ~]# groupadd www -g 1000
[root@nfs ~]# useradd www -g 1000 -u 1000[root@nfs ~]# chown www.www /sersync/[root@nfs ~]# systemctl restart nfs-server rpcbind

web01 和 web 2

#挂载mount -t nfs 172.16.1.31:/sersync /root/web2/
mount -t nfs 172.16.1.31:/sersync /root/web1/#注:挂载之前web01和web02下的文件内容,在挂载之后不会被覆盖,只有在卸载后才能看到挂载后显示的内容是/sersync目录下的内容

上传案例–httpd

#安装web服务器(web01和web02两台机器上全需要执行)[root@web1 ~]# yum install httpd php -y[root@web1 ~]# systemctl start httpd[root@web1 ~]# mount -t nfs 172.16.1.31:/sersync /var/www/html/# 将kaoshi.zip解压至/var/www/html目录(只需要在一台服务器上执行)
[root@web1 ~]# mv kaoshi.zip /var/www/html/
[root@web1 ~]# cd /var/www/html/
[root@web1 html]# unzip kaoshi.zip[root@web1 ~]# chown -R www.www /var/www/html/

出现以上界面上传视频(不能大于8M)web02上传web01查看验证

[root@web01 ~]# ll /var/www/html/upload
total 220
-rw-r--r-- 1 www www 222097 Apr 22 18:52 4_chenyang_test.mp4

区别

rsync : 但是无法实时传输innotfy + rsync : 适用于文件比较少的情况sersync + innotfy + rsync : 大批量文件同步

NFS共享存储(用于内网) httpd协议 nginx 两种上传方式 区别相关推荐

  1. 内网xshell传输文件命令_Xshell 上传文件到服务器 以及常用的lunix 命令

    Xshell 上传文件到服务器 1:输入rz命令,看是否已经安装了lrzsz,如果没有安装则执行 yum -y install lrzsz命令进行安装. 2:安装成功后查看是否安装成功 3:输入rz ...

  2. Vite内网ip访问,两种配置方式

    问题 使用vite运行项目的时候,控制台会只出现127.0.0.1(localhost)本地地址访问项目.不可以通过公司内网ip访问,其他团队成员无法访问,这是因为没有将服务暴露在局域网中: 两种解决 ...

  3. Linux内网离线安装nginx(rpm包安装方式)

    1.下载RPM离线安装包: 首先,先下载nginx的rpm包,下载地址:http://nginx.org/packages/centos/7/x86_64/RPMS/ 下载nginx-1.18.0-2 ...

  4. Docker基于容器制作httpd镜像(使用nfs共享存储部署一个网站)

    Docker基于容器制作httpd镜像 1 编译安装httpd 2 安装nfs共享存储 3 使用nfs共享存储提供httpd网页服务 4 在浏览器上进行测试访问 1 编译安装httpd [root@d ...

  5. Linux架构之NFS共享存储1

    第35章 NFS共享存储 35.1 NFS基本概述 NFS是Network File System的缩写及网络文件系统.NFS主要功能是通过局域网络让不同的主机系统之间可以共享文件或目录. 常见的文件 ...

  6. NFS共享存储服务介绍与案例详细配置过程

    目录 1,什么是NFS? 2,NFS工作原理 3,使用NFS发布共享资源 4,NFS 挂载原理 5,NFS服务所需软件及主要配置文件 安装NFS服务,需要安装两个软件,分别是: 6, NFS的相关文件 ...

  7. Windows/Linux客户端挂载NFS共享存储

    Windows/Linux客户端挂载NFS共享存储 1. Linux搭建NFS共享存储 1.1. NFS概述 1.2. 安装并配置NFS Server 1.3. 启动并验证NFS Server 2. ...

  8. Linux YUM扩展NFS共享存储服务(配置图解)

    NFS共享存储服务 一.YUM 1.YUM (Yellow dog Updater Modified) 2.软件仓库的提供方法 3.RPM软件包的来源 4.构建CentOS 7 软件仓库 5.在软件仓 ...

  9. centos 7.6 ——NFS共享存储服务

    NFS共享存储服务 文章目录 NFS共享存储服务 nfs 原理 一.实验准备 三.实验步骤 服务端192.168.75.137配置 客户机192.168.75.134配置 查看服务端文件 注意 FTP ...

最新文章

  1. 关于visualizer的setEnabled()方法何时进行设置成false?
  2. 简单的java rpc_Java 简单的rpc 一
  3. python操作Elasticsearch7.17.0
  4. java并发编程实践(1)intro
  5. 滚动字幕Marquee
  6. 解决安装IIS时提示找不到zClientm.exe文件的问题
  7. 手机端开发深度学习应用
  8. 关于如何控制一个页面的Ajax读数据只读一次的简单解决办法!
  9. 《三国演义》人物数据分析
  10. 干掉MySQL:他们的MySQL分库分表架构,搞得太棒了!
  11. bzoj 4653: [Noi2016]区间(尺取+线段树)
  12. 在PHP中怎么判断字符串中没有,在php中搜索字符串中没有的字符
  13. 明解c语言入门篇有用吗,各位初学者在用明解C语言(入门篇)的时候花费了多长时间?...
  14. STM32 DMA2D技术
  15. go语言中的type关键字
  16. 系统登录页面短信验证码方式登录实现
  17. ERP中各种乱码处理
  18. 盛世昊通:数字汽车的未来由谁来书写
  19. HTML+CSS学习笔记整理-七七八八
  20. .NET Framework 概述

热门文章

  1. linux 动态密码,LINUX使用一次性密码配置
  2. Java【多线程】笔记总结
  3. 基于egret引擎、P2物理库的搭积木游戏
  4. 新手的疑惑,动力取决于三点
  5. 2021年山东大学程序设计精英挑战赛 真题
  6. 【Scrapy框架实战】爬取网易严选-苹果12手机热评
  7. kafka消费者如何才能从头开始消费某个topic的全量
  8. JAVA简单实现坦克对战(只有坦克和子弹)
  9. 举安全之盾,防事故之患
  10. 计算机组成原理中LD,计算机组成原理课件第三章计算机中的数据表示.ppt