共計 3234 個字符,預計需要花費 9 分鐘才能閱讀完成。
本篇文章給大家分享的是有關(guān)如何編譯一個高性能 OpenResty,丸趣 TV 小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著丸趣 TV 小編一起來看看吧。
介紹
下面將介紹如何一步一步手動編譯 OpenResty,OpenResty 是一個基于 Nginx 與 Lua 的高性能 Web 平臺,擁有非常好的拓展性讓服務器發(fā)揮更好性能。全部依賴 Linux 發(fā)行版組建中的依賴,而免除編譯帶來的后期維護成本。
準備設(shè)置安全組(重要)
如果不設(shè)置好安全組,究竟是無法訪問還是編譯失敗會分不清的。
需要開放: 80 和 443 端口
教程
本教程以,Ubuntu 16.04 LTS 64 位版 為例。
設(shè)定版本變量
如果軟件版本更新后,為了方便起見,后續(xù)修改版本號只需修改下面的變量即可。在 SSH 終端 中輸入:
# VersionOpenSSLVersion= openssl-1.0.2l NginxCTVersion= 1.3.2 PageSpeedVersion= 1.12.34.2 SystemBit= X64 OpenRestyVersion= openresty-1.11.2.5
注: 截止本次更新,OpenResty 1.11.2 版本最高只能搭配 OpenSSL 1.0.2。
上述軟件版本更新查看: OpenSSL、Nginx-CT、PageSpeed、OpenResty
安裝依賴
更新系統(tǒng)軟件源緩存順便升級組件:
apt updateapt upgrade -y
安裝依賴組件:
apt install build-essential libreadline-dev libncurses5-dev libpcre3 libpcre3-dev libssl-dev zlib1g-dev unzip git perl make libjemalloc1 libjemalloc-dev
下載源碼
這里將 OpenResty 所需的源代碼均放置在 /root/src 目錄下,方便管理。
cd /rootmkdir srccd src
下載 OpenResty 和其拓展的源代碼:
# 下載 OpenSSL,Ubuntu 16.04(不包括)以下版本請刪除下面的 # 以下載 #wget https://www.openssl.org/source/$OpenSSLVersion.tar.gz#tar xzf $OpenSSLVersion.tar.gzwget https://github.com/grahamedgecombe/nginx-ct/archive/v$NginxCTVersion.tar.gz
tar xzf v$NginxCTVersion.tar.gz
git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
git submodule update --init
cd ../
wget https://github.com/pagespeed/ngx_pagespeed/archive/v$PageSpeedVersion-beta.zip
unzip v$PageSpeedVersion-beta.zip
cd ngx_pagespeed-$PageSpeedVersion-beta/
wget https://dl.google.com/dl/page-speed/psol/$PageSpeedVersion-$SystemBit.tar.gz
tar -xzvf $PageSpeedVersion-$SystemBit.tar.gz
cd ../
wget -c https://openresty.org/download/$OpenRestyVersion.tar.gz
tar zxf $OpenRestyVersion.tar.gz
查看更多
編譯 OpenResty
cd $OpenRestyVersion
./configure --prefix=/usr/local/openresty \
--user=www-data --group=www-data \--add-module=../ngx_brotli \--add-module=../nginx-ct-$NginxCTVersion \--add-module=../ngx_pagespeed-$PageSpeedVersion-beta \--with-http_v2_module \--with-http_ssl_module \--with-http_gzip_static_module \--with-ld-opt= -ljemalloc make make install
Ubuntu 16.04(不包括)以下版本請在倒數(shù)第二行添加:
--with-openssl=../$OpenSSLVersion \
設(shè)置變量
[ -z `grep ^ export PATH= /etc/profile` ] echo export PATH=/usr/local/openresty/nginx/sbin:\$PATH /etc/profile
[ -n `grep ^ export PATH= /etc/profile` -a -z `grep /usr/local/openresty/ /etc/profile` ] sed -i s@^export PATH=\(.*\)@export PATH=/usr/local/openresty/nginx/sbin:\1@ /etc/profile
. /etc/profile
后面就可以用,nginx -t 檢測配置是否正確,nginx -s reload 重載 Nginx 了。
創(chuàng)建相關(guān)目錄
mkdir /data/wwwlogs/ -p
mkdir /data/wwwroot/default/ -p
cp /usr/local/openresty/nginx/html/index.html /data/wwwroot/default/
設(shè)置服務和開機啟動
創(chuàng)建 /etc/systemd/system/openresty.service 文件,內(nèi)容:
cd /etc/systemd/system/wget https://gist.githubusercontent.com/ivmm/dbf03e6c7970488652878bb8ddc3a775/raw/48436d911d08e57774c759bdb50548dec31dc86f/openresty.service
編輯 /usr/local/openresty/nginx/conf/nginx.conf 文件為:
cd /usr/local/openresty/nginx/conf/rm nginx.conf -rf
wget https://gist.githubusercontent.com/ivmm/ab81dee184b64036bd4b8d5abe676264/raw/1cbfbc387aa956f6d9afe39d60e2b8c988a10688/nginx.conf
重新加載 systemd 服務,以便它可以找到我們的文件:
systemctl daemon-reload
通過 systemd 重啟 OpenResty:
systemctl restart openresty
設(shè)置開機啟動:
systemctl enable openresty
打開你的服務器 IP,就能看到安裝好的 OpenResty 提示頁了 https://pics.mf8.biz/mf8/awxi3.png
以上就是如何編譯一個高性能 OpenResty,丸趣 TV 小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學到更多知識。更多詳情敬請關(guān)注丸趣 TV 行業(yè)資訊頻道。