架構篇 7 Nginx優化 ab壓測

2021-10-09 13:27:53 字數 2717 閱讀 1918

安裝nginx

#配置nginx官方yum源

vim /etc/yum.repos.d/nginx.repo

新增:[nginx-stable]

name=nginx stable repo

baseurl=

gpgcheck=0

enabled=1

儲存退出

yum -y install nginx

更改nginx配置檔案進行優化
vim /etc/nginx/nginx.conf

user nginx;

worker_processes 16; // 調至cpu核心數

worker_cpu_affinity auto; //乙個work分配乙個cpu,需要配合上面worker_processes

error_log /var/log/nginx/error.log warn;

pid /var/run/nginx.pid;

work_rlimit_nofile 35535; //nginx程序檔案控制代碼,建議調整到1萬以上

events

http

ab壓測
yum  -y  install  httpd-tools    #安裝ab測試工具

[root@zh ~]# ab -c 10 -n1000

this is apachebench, version 2.3 <$revision: 1430300 $>

licensed to the apache software foundation,

benchmarking zh.benet.com (be patient)

completed 100 requests

completed 200 requests

completed 300 requests

completed 400 requests

completed 500 requests

completed 600 requests

completed 700 requests

completed 800 requests

completed 900 requests

completed 1000 requests

finished 1000 requests

server software: nginx/1.18.0

server hostname: zh.benet.com

server port: 80

document path: /

document length: 12430 bytes

concurrency level: 10

time taken for tests: 7.785 seconds

complete requests: 1000 //完成的請求數量

failed requests: 184 //失敗的請求數量

(connect: 0, receive: 0, length: 184, exceptions: 0)

write errors: 0

total transferred: 12769797 bytes //整個場景中的網路傳輸量

html transferred: 12429797 bytes //整個場景中的html內容傳輸量

requests per second: 128.46 [#/sec] (mean) //lr 中的 每秒事務數 ,後面括號中的 mean 表示這是乙個平均值

time per request: 77.846 [ms] (mean) //lr 中的 平均事務響應時間 ,後面括號中的 mean 表示這是乙個平均值

time per request: 7.785 [ms] (mean, across all concurrent requests) //每個請求實際執行時間的平均值

transfer rate: 1601.94 [kbytes/sec] received

connection times (ms)

min mean[+/-sd] median max

connect: 0 0 0.0 0 0

processing: 13 78 30.5 75 480

waiting: 13 71 30.2 70 479

total: 13 78 30.5 75 480

percentage of the requests served within a certain time (ms)

50% 75

66% 85

75% 91

80% 95

90% 109

95% 124

98% 161

99% 186

100% 480 (longest request)

-n 總的請求數 -c 併發數

ps:根據需求配置

7 Nginx負載均衡深入實踐

locatiaon跳轉 lb01與win10的hosts檔案加上 web01 10.0.0.7 模擬靜態伺服器 web02 10.0.0.8 動態 web03 預設,這裡我們在02上做臨時ip模擬就行 建立臨時ip模擬預設伺服器web03 server server server autoindex...

Nginx 高階 架構基礎篇

1 nginx的請求處理流程 http狀態機 等待上游epoll請求,當記憶體滿額時,使用執行緒池磁碟阻塞呼叫。2 nginx的程序結構 ps aux grep nginxmaster作為父程序,有很多子程序,nginx的父子程序是通過訊號管理的。kill signup 9170signup與rel...

分布式架構 Nginx優化

nginx介紹 優化思路 常見配置檔案如下 nginx.conf配置講解,常用核心模組指令可以參考如下 nginx.conf配置 error log logs error.log crit user root worker processes 2 worker rlimit nofile 15360...