LNMP 平滑升級 Tengine 筆記

Tengine是阿里的一項開源 Web 服務器項目 是基於 Nginx 的,針對大訪問量的網站和性能都有比較好的優化!

爲了配合LNMP的https,升級加入了http2的配置,要開啓HTTP/2協議支持,需要在nginx 1.10以上版本並且需要openssl庫的版本在1.0.2以上編譯,那麼開始吧

查看OpenSSL版本

openssl version

版本低於1.0.2的話就需要升級

一、升級OpenSSL

1、下載最新版的OpenSSL庫編譯安裝,(這裏我openssl-1.1.0f 做案例)

wget https://www.openssl.org/source/openssl-1.1.0f.tar.gz
#git clone https://github.com/openssl/openssl.git  #或者從這裏獲取
tar zxvf openssl-1.1.0f.tar.gz
cd openssl-1.1.0f
./config --prefix=/usr/local/openssl
make && make install

2、替換舊版本庫

mv /usr/bin/openssl  /usr/bin/openssl.old
mv /usr/include/openssl /usr/include/openssl.old
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
#鏈接新庫文件
ln -s /usr/local/openssl/lib/libssl.so /usr/local/lib64/libssl.so
ln -s /usr/local/openssl/lib/libcrypto.so /usr/local/lib64/libcrypto.so
#檢查更新後的openssl依賴庫是否是1.1.0f
strings /usr/local/lib64/libssl.so | grep OpenSSL
#顯示結果表明已升級到最新版本鏈接庫
OpenSSL 1.1.0f  25 May 2017
#配置openssl庫文件的搜索路徑
echo '/usr/local/openssl/lib' >> /etc/ld.so.conf
#使修改後的搜索路徑生效
ldconfig -v
#查看openssl版本,結果顯示升級成功
openssl version
OpenSSL 1.1.0f  25 May 2017

如果第一步執行權限不夠的話就手動吧

二、升級Tengine

1、安裝/編譯,整理好了 目前版本是2.3.2,2019-08-20 更新的

wget -c http://tengine.taobao.org/download/tengine-2.3.2.tar.gz && tar zxvf tengine-2.3.2.tar.gz && cd tengine-2.3.2/ && ./configure --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_v2_module --with-http_stub_status_module --with-http_sub_module --with-openssl=/root/openssl-1.1.0f && make && mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old && cp -r objs/nginx /usr/local/nginx/sbin/nginx && vi /usr/local/nginx/conf/nginx.conf

2、刪除配置,執行完 會打開/usr/local/nginx/conf/nginx.conf,i進入找到並刪除一下代碼 這個是監控模塊 根據需求來配置

location /status {
    stub_status on;
    access_log   off;
}

3、查看狀態,找到上面代碼之後果斷刪除,找不到就看看 Nginx 是否正常:

/usr/local/nginx/sbin/nginx -t
#或者
nginx -t

如果有“ Successful ”結尾那就是沒問題,最後收尾就好了!

4、收尾工作:停止 Nginx 並重啓然後查看目前版本:

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid` && kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin` && /etc/init.d/nginx restart && /usr/local/nginx/sbin/nginx -v

如果你看到了 Tengine/2.3.2的話那就是成功升級了!

代碼詳細講解

#下載壓縮包
wget -c http://tengine.taobao.org/download/tengine-2.3.2.tar.gz 
#git clone https://github.com/alibaba/tengine.git  或者從這裏獲取
#解壓
tar zxvf tengine-2.3.2.tar.gz
#進入目錄
cd tengine-2.3.2/
#執行安裝腳本
./configure --prefix=/usr/local/nginx \
--conf-path=/usr/local/nginx/conf/nginx.conf \
--sbin-path=/usr/local/nginx/sbin/nginx \
--pid-path=/usr/local/nginx/nginx.pid \
--error-log-path=/home/wwwlogs/nginx-error.log \
--http-log-path=/home/wwwlogs/access.log \
--user=nginx \
--group=nginx \
#使支持https請求,需已安裝openssl
--with-http_ssl_module \        
#獲取真實IP模塊,默認爲關
--with-http_realip_module \                            
#提供尋求內存使用基於時間的偏移量文件
--with-http_flv_module \
#對具有.mp4, .m4v, and .m4a.擴展名的H.264/AAC格式文件提供服務器端的僞流支持
--with-http_mp4_module \
#模塊將文件解壓縮後並在響應頭加上 "Content-Encoding: gzip" 返回給客戶端。爲了解決客戶端不支持gzip壓縮
--with-http_gunzip_module \ 
#預讀gzip功能          
--with-http_gzip_static_module \
#nginx安全下載模塊
--with-http_secure_link_module \
#HTTP/2 模塊
--with-http_v2_module \
#模塊監控 
--with-http_stub_status_module \
#替換網站響應內容
--with-http_sub_module \
#這個就是升級的那個openssl 的路徑
--with-openssl=/root/openssl-1.1.0f                    

#編譯                                                 
make
#備份配置                                   
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
#複製配置粘貼
cp -r objs/nginx /usr/local/nginx/sbin/nginx
#配置 Nginx
vi /usr/local/nginx/conf/nginx.conf
#查看狀態
/usr/local/nginx/sbin/nginx -t
#殺進程             
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
#殺進程              
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
#重啓Nginx
/etc/init.d/nginx restart
#查看Nginx版本
/usr/local/nginx/sbin/nginx -v                                  

這些模塊也只是nginx的一部分,需要的話自己去查相關模塊及用法吧

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章