源碼包編譯安裝
下載
從下載頁Download下載最新的 OpenResty?源碼包岩榆,并且像下面的示例一樣將其解壓:
wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
安裝前的準備
必須將這些庫 perl 5.6.1+, libpcre, libssl安裝在您的電腦之中赖条。 對于 Linux來說, 您需要確認使用 ldconfig 命令,讓其在您的系統(tǒng)環(huán)境路徑中能找到它們岁诉。
推薦您使用yum安裝以下的開發(fā)庫:
yum install pcre-devel openssl-devel gcc curl -y
安裝
tar -zxvf openresty-1.13.6.2.tar.gz
cd openresty-1.13.6.2
./configure
make
make install
測試性能
安裝壓力測試工具ab
yum -y install httpd-tools
壓力測試
-c:每次并發(fā)數(shù)為10個
-n:共發(fā)送50000個請求
ab -c10 -n50000 http://localhost:8080/
測試報詳解
Server Software: Apache #服務(wù)器軟件
Server Hostname:? ? ? ? localhost? ? ? #域名
Server Port:? ? ? ? ? ? 80? ? ? ? ? ? ? #請求端口號
Document Path:? ? ? ? ? /? ? ? ? ? ? ? #文件路徑
Document Length:? ? ? ? 40888 bytes? ? #頁面字節(jié)數(shù)
Concurrency Level:? ? ? 10? ? ? ? ? ? ? #請求的并發(fā)數(shù)
Time taken for tests:? 27.300 seconds? #總訪問時間
Complete requests:? ? ? 1000? ? ? ? ? ? #請求成功數(shù)量
Failed requests:? ? ? ? 0? ? ? ? ? ? ? #請求失敗數(shù)量
Write errors:? ? ? ? ? 0Total transferred:? ? ? 41054242 bytes? #請求總數(shù)據(jù)大小(包括header頭信息)
HTML transferred:? ? ? 40888000 bytes? #html頁面實際總字節(jié)數(shù)
Requests per second:? ? 36.63 [#/sec] (mean)? #每秒多少請求跋选,這個是非常重要的參數(shù)數(shù)值涕癣,服務(wù)器的吞吐量
Time per request:? ? ? 272.998 [ms] (mean)? ? #用戶平均請求等待時間
Time per request:? ? ? 27.300 [ms] (mean, across all concurrent requests)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? # 服務(wù)器平均處理時間,也就是服務(wù)器吞吐量的倒數(shù)
Transfer rate:? ? ? ? ? 1468.58 [Kbytes/sec] received? #每秒獲取的數(shù)據(jù)長度
Connection Times (ms)
? ? ? ? ? ? ? min? mean[+/-sd] median? maxConnect:? ? ? 43? 47? 2.4? ? 47? ? ? 53Processing:? 189? 224? 40.7? ? 215? ? 895Waiting:? ? ? 102? 128? 38.6? ? 118? ? 794Total:? ? ? ? 233? 270? 41.3? ? 263? ? 945Percentage of the requests served within a certain time (ms)
? 50%? ? 263? ? #50%用戶請求在263ms內(nèi)返回
? 66%? ? 271? ? #66%用戶請求在271ms內(nèi)返回
? 75%? ? 279? ? #75%用戶請求在279ms內(nèi)返回
? 80%? ? 285? ? #80%用戶請求在285ms內(nèi)返回
? 90%? ? 303? ? #90%用戶請求在303ms內(nèi)返回
? 95%? ? 320? ? #95%用戶請求在320ms內(nèi)返回
? 98%? ? 341? ? #98%用戶請求在341ms內(nèi)返回
? 99%? ? 373? ? #99%用戶請求在373ms內(nèi)返回
100%? ? 945 (longest request)
添加nginx到服務(wù)加入開機啟動
vi /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/app/services/openresty/nginx/sbin/nginx
ExecReload=/app/services/openresty/nginx/sbin/nginx -s reload
ExecStop=/app/services/openresty/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
啟動并加入開機啟動
systemctl start nginx.service
systemctl enable nginx.service
將nginx加入到環(huán)境變量
vi /etc/profile,加入
# nginx
export NGINX_HOME=/app/services/openresty/nginx
export PATH=$PATH:$NGINX_HOME/sbin
刷新:source /etc/profile