构建高并发网站架构

构建高并发网站架构

https://www.cnblogs.com/leefreeman/p/3993449.html

特点:并发数高、访问量大、数据量大、用户分布广泛、网络环境复杂、稳定性高、易于扩展、安全性高

基础设施

服务器介绍:塔式服务器、机架式服务器、刀片式服务器、虚拟主机、虚拟机、服务器、云主机

网络设备介绍:交换机、防火墙、路由器

存储设备:san、nas、das

IDC:机房、机柜、网络、电源、空调

基本概念

head详解:kb.cnblogs.com/page/92320/

http协议:超文本传输协议,http1.0是没有办法保持连接,http1.1可以保持连接,http1.1支持host请求头(一个服务器上配置多个域名)

linux查看head

[root@centos-01 kvm_data]# curl -I http://www.baidu.com
HTTP/1.1 200 OK
Accept-Ranges: bytes
Cache-Control: private, no-cache, no-store, proxy-revalidate, no-transform
Connection: Keep-Alive
Content-Length: 277
Content-Type: text/html
Date: Thu, 12 Jul 2018 01:35:20 GMT
Etag: "575e1f5d-115"
Last-Modified: Mon, 13 Jun 2016 02:50:05 GMT
Pragma: no-cache
Server: bfe/1.0.8.18

[root@centos-01 kvm_data]# 

http状态码:200正常请求、301永久跳转、302临时跳转、304从缓存中取、401需要认证、403无权限、404图片或网页找不到、500服务器问题、502nginx服务器+php-fpm中常见,nginx请求php发现php文件找不到会报502、503常出现在代理服务器、504访问超时

url和uri:uri包含url 

常用服务器

apache、nginx、iis、tomcat

awstat日志分析

http://blog.51cto.com/freeloda/1346412

Apache服务器下查看服务器吞吐量

loadrunner

临时测试工具ab(如果没有ab命令yum安装httpd包)

ab -c 100 -n 1000  http://www.baidu.com/index.php

-c指定并发送 -n指定访问多少次

[root@centos-04 src]# ab -c 10 -n 100  http://www.qq.com/index.php   
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking www.qq.com (be patient).....done


Server Software:        stgw/1.3.6.2_1.13.5
Server Hostname:        www.qq.com
Server Port:            80

Document Path:          /index.php
Document Length:        168 bytes

Concurrency Level:      10
Time taken for tests:   0.275 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      100
Total transferred:      37300 bytes
HTML transferred:       16800 bytes
Requests per second:    364.20 [#/sec] (mean) (吞吐量、并发送)
Time per request:       27.457 [ms] (mean) (每个请求花费的时间,不超过3秒就没问题)
Time per request:       2.746 [ms] (mean, across all concurrent requests)
Transfer rate:          132.66 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        6   11   2.8     11      21
Processing:     6   12   4.7     11      29
Waiting:        5    9   2.5      9      18
Total:         13   23   5.7     21      39

Percentage of the requests served within a certain time (ms)
  50%     21
  66%     24
  75%     26
  80%     28
  90%     30
  95%     32
  98%     38
  99%     39
 100%     39 (longest request)
[root@centos-04 src]# 

网站架构角色web

第一种:client-》web-》db

第二种:client-》cdn-》代理-》web-》缓存-》db

cdn:加速器,解决由于网络带宽小、用户访问量大、网点分布不均而产生的用户访问网站响应速度慢的根本原因,CDN目的是通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络“边缘”,使用户可以就近取得所需的内容,解决 Internet 网络拥塞状况,提高用户访问网站的响应速度。

web:iis、Apache、nginx+php-fpm、tomcat+jdk nginx+uwsgi+python

db:mysql/maridb/、postgresql、oracle、mangodb

nosql:memcached、redis

代理:squid和varnish(不仅仅可以做代理还可以缓存)、nginx

cdn就是一个带缓存的代理,

存储:fastdfs  gfs hdfs tfs glusterfs

架构

 

网站架构演变 - 小型网站

 

网站架构演变 - 小型网站

 

网站架构演变 - 中小型网站

网站架构演变 - 中型网站

架构优化-CDNnginx调优

架构优化-硬件优化

架构优化-CDNnginx调优

架构优化-使用nosql

架构优化-业务调优

架构优化-内核调优

架构优化-使用异步通信

架构优化-案例分析

减少 http请求

记录慢执行慢查询日志

将动态内容静态化

图片延迟加载

动静分离

应用无状态

查看当前系统运行进程

[root@centos-04 nginx-1.14.0]# pstree
systemd─┬─NetworkManager─┬─dhclient
        │                └─2*[{NetworkManager}]
        ├─auditd───{auditd}
        ├─crond
        ├─dbus-daemon
        ├─dockerd-current─┬─docker-containe─┬─docker-containe─┬─mysqld───29*[{mysqld}]
        │                 │                 │                 └─7*[{docker-containe}]
        │                 │                 ├─docker-containe─┬─php-fpm───2*[php-fpm]
        │                 │                 │                 └─7*[{docker-containe}]
        │                 │                 ├─docker-containe─┬─nginx───nginx
        │                 │                 │                 └─7*[{docker-containe}]
        │                 │                 └─10*[{docker-containe}]
        │                 ├─3*[docker-proxy-cu───3*[{docker-proxy-cu}]]
        │                 └─9*[{dockerd-current}]
        ├─gssproxy───5*[{gssproxy}]
        ├─login───bash
        ├─lvmetad
        ├─master─┬─pickup
        │        └─qmgr
        ├─polkitd───6*[{polkitd}]
        ├─rpc.idmapd
        ├─rpc.mountd
        ├─rpc.statd
        ├─rpcbind
        ├─rsyslogd───2*[{rsyslogd}]
        ├─sshd─┬─sshd───bash───pstree
        │      ├─sshd───9*[sftp-server]
        │      └─2*[sshd───sftp-server]
        ├─systemd-journal
        ├─systemd-logind
        ├─systemd-udevd
        └─tuned───4*[{tuned}]
[root@centos-04 nginx-1.14.0]# 

文件倒序排列

[root@centos-04 nginx-1.14.0]# ls -lt|head
总用量 740
drwxr-xr-x 2 1001 1001   4096 12月 25 15:53 conf
drwxr-xr-x 4 root root   4096 7月  30 05:59 objs
-rw-r--r-- 1 root root    376 7月  30 05:57 Makefile
drwxr-xr-x 9 1001 1001     84 7月  25 00:14 src
drwxr-xr-x 2 1001 1001     20 7月  25 00:12 man
drwxr-xr-x 6 1001 1001   4096 7月  25 00:06 auto
drwxr-xr-x 4 1001 1001     68 7月  25 00:06 contrib
drwxr-xr-x 2 1001 1001     38 7月  25 00:06 html
-rw-r--r-- 1 1001 1001 286953 4月  17 2018 CHANGES
[root@centos-04 nginx-1.14.0]# 

 php-fpm配置文件

配置php慢程序日志

https://www.cmhello.com/php-fpm.html

安装xhprof

http://blog.chinaunix.net/uid-20622737-id-3820457.html

原文地址:https://www.cnblogs.com/sunyujun/p/9297069.html