構建高併發網站架構

構建高併發網站架構

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

特色:併發數高、訪問量大、數據量大、用戶分佈普遍、網絡環境複雜、穩定性高、易於擴展、安全性高html

基礎設施

服務器介紹:塔式服務器、機架式服務器、刀片式服務器、虛擬主機、虛擬機、服務器、雲主機python

網絡設備介紹:交換機、防火牆、路由器mysql

存儲設備:san、nas、daslinux

IDC:機房、機櫃、網絡、電源、空調nginx

基本概念

head詳解:kb.cnblogs.com/page/92320/web

http協議:超文本傳輸協議,http1.0是沒有辦法保持鏈接,http1.1能夠保持鏈接,http1.1支持host請求頭(一個服務器上配置多個域名)redis

linux查看headsql

[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文件找不到會報50二、503常出如今代理服務器、504訪問超時docker

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

相關文章
相關標籤/搜索