【軟件安裝】CentOS7安裝Tengine_2_3_2(Nginx 1_17_0)


簡單比較一下Tengine 和Nginx

背景

使用最新的軟件,可以處理一些bug,文章對CentOS6不做介紹(不會用)

推薦使用Tengine,理由是淘寶再用,兼容 Nginx 可以隨時切換

Tengine-2.3.0+介紹

Github: Tengine: 【Star:9.2K】

https://github.com/alibaba/tengine

Tengine是由淘寶網發起的Web服務器項目。它在Nginx的基礎上,針對大訪問量網站的需求,添加了很多高級功能和特性。Tengine的性能和穩定性已經在大型的網站如淘寶網,天貓商城等得到了很好的檢驗。它的最終目標是打造一個高效、穩定、安全、易用的Web平台。

  • nginx-1.17.3的所有特性都是繼承的,即它與nginx 100%兼容。
  • 支持轉發代理的連接http方法。
  • 支持異步openssl,使用qat等硬件實現https加速。
  • 增強的操作監控,如異步日志回滾、DNS緩存、內存使用等。
  • 流模塊中支持服務器名。
  • 更多的負載平衡方法,例如一致的散列和會話持久性。
  • 輸入體過濾器支持。使用這個機制編寫Web應用防火牆非常方便。
  • 動態腳本語言(lua)支持,這是非常有效的,並使其易於擴展核心功能。
  • 限制上游服務器(proxy、memcached、fastcgi、scgi、uwsgi)的重試次數。
  • 包括支持獨立進程的機制。
  • 在系統負載或內存使用過多的情況下保護服務器。
  • 可以將多個CSS或JavaScript請求組合成一個請求,以減少下載時間。
  • 刪除不必要的空白和注釋以減小頁面大小。
  • 可以對上游服務器執行主動健康檢查。
  • 可以自動設置工作進程和CPU關聯的數量。
  • Limit_Req模塊通過白名單支持得到增強,在單個位置允許更多條件。
  • 增強的診斷信息使故障排除變得更容易。
  • 更多用戶友好的命令行,例如,顯示所有編譯的模塊和支持的指令。
  • 可以為某些MIME類型指定到期時間。
  • 錯誤頁可以重置為“默認”。

Nginx-1.17.3+介紹

Github: Nginx: 【Star:9.8K】

https://github.com/nginx/nginx

Nginx 是一個高性能的 Web 和反向代理服務器, 它具有有很多非常優越的特性:

  • 作為 Web 服務器:相比 Apache,Nginx 使用更少的資源,支持更多的並發連接,體現更高的效率,這點使 Nginx 尤其受到虛擬主機提供商的歡迎。能夠支持高達 50,000 個並發連接數的響應,感謝 Nginx 為我們選擇了 epoll and kqueue 作為開發模型.

  • 作為負載均衡服務器:Nginx 既可以在內部直接支持 Rails 和 PHP,也可以支持作為 HTTP代理服務器 對外進行服務。Nginx 用 C 編寫, 不論是系統資源開銷還是 CPU 使用效率都比 Perlbal 要好的多。

  • 作為郵件代理服務器: Nginx 同時也是一個非常優秀的郵件代理服務器(最早開發這個產品的目的之一也是作為郵件代理服務器),Last.fm 描述了成功並且美妙的使用經驗。

  • Nginx 安裝非常的簡單,配置文件 非常簡潔(還能夠支持perl語法),Bugs非常少的服務器: Nginx 啟動特別容易,並且幾乎可以做到7*24不間斷運行,即使運行數個月也不需要重新啟動。你還能夠在 不間斷服務的情況下進行軟件版本的升級。

安裝命令 ———#代表使用的root權限

檢查環境信息

[root@ip104 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core) 

1、下載安裝包(使用離線或者在線方式)

1.1【離線方式自己下載】

  • 下載安裝包安裝Tengine-2.3.0
  • 下載pcre-8.39.tar.gz【依賴】
  • 下載zlib-1.2.11.tar.gz【依賴】
  • 下載openssl-1.0.1h.tar.gz【依賴】
  • 下載jemalloc-3.6.0.tar.bz2 【依賴】
  • 下載 tengine-2.3.0.tar.gz
# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz 
# wget http://zlib.net/zlib-1.2.11.tar.gz 
# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
# wget http://tengine.taobao.org/download/tengine-2.3.0.tar.gz

1.2【在線方式】(推薦方式,配置Centos 7網絡自動下載)

yum install gcc-c++
yum -y install pcre pcre-devel 
yum -y install zlib zlib-devel
yum -y install openssl openssl-devel

1.3【操作日志預覽】

1.3.1 【yum install gcc-c++】 需要輸入一次y 繼續下載安裝

[root@ip104 ~]#  yum install gcc-c++
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
..............................等待,需要輸入一次y 繼續下載安裝............................
Total download size: 31 M
Is this ok [y/d/N]: y
Downloading packages:
..............................等待............................
Complete!

1.3.2 【yum -y install pcre pcre-devel 】

[root@ip104 ~]# yum -y install pcre pcre-devel 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
..............................等待............................
Complete!

1.3.3【yum -y install zlib zlib-devel】

[root@ip104 ~]#  yum -y install zlib zlib-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package zlib-1.2.7-18.el7.x86_64 already installed and latest version
.............................等待............................
Complete!

1.3.4【yum -y install openssl openssl-devel】

[root@ip104 ~]#  yum -y install openssl openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
..............................等待............................
Complete!

2、解壓安裝包並安裝軟件(使用離線或者在線方式)

2.1 下載Tengine

 cd /usr/local/src/
 
 wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
 
 ls

2.2 解壓壓縮生成編譯(一條一條來)

tar -zxvf tengine-2.3.2.tar.gz

cd /usr/local/src/tengine-2.3.2

./configure 

make

sudo make install

2.3 解壓安裝包

[root@ip104 ~]# cd /usr/local/src/
[root@ip104 src]#  wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
--2019-10-01 12:37:03--  http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
Resolving tengine.taobao.org (tengine.taobao.org)... 140.205.172.18
Connecting to tengine.taobao.org (tengine.taobao.org)|140.205.172.18|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2835884 (2.7M) [application/octet-stream]
Saving to: ‘tengine-2.3.2.tar.gz’

100%[==============================================>] 2,835,884    531KB/s   in 5.3s   

2019-10-01 12:37:08 (521 KB/s) - ‘tengine-2.3.2.tar.gz’ saved [2835884/2835884]

[root@ip104 src]# ls
tengine-2.3.2.tar.gz 

2.4 操作日志預覽

--------下載安裝包--------
[root@ip104 tengine-2.3.2]# cd /usr/local/src/
[root@ip104 src]# ls
rarlinux-x64-5.4.0.tar.gz  tengine-2.3.2  tengine-2.3.2.tar.gz
[root@ip104 src]# 
--------編譯安裝--------
[root@ip104 tengine-2.3.2]# cd /usr/local/src/tengine-2.3.2
[root@ip104 tengine-2.3.2]# ls
AUTHORS.te  CHANGES.cn  configure  html      man      packages         tests
auto        CHANGES.te  contrib    LICENSE   modules  README.markdown  THANKS.te
CHANGES     conf        docs       Makefile  objs     src
[root@ip104 tengine-2.3.2]# 

3、配置Tengine並運行

Tengine完全兼容Nginx,因此可以參照Nginx的方式來配置Tengine。我們在此只列出Tengine中值得注意的功能。關於詳細的Tengine的相對於Nginx的差別,可以訪問變更列表。

3.1 配置后台服務

  • 輸入以下命令
vi /lib/systemd/system/nginx.service 

  • 輸入以下編輯內容。按鍵:esc 輸入 :wq 保存配置文件
#配置 Tengine config
[Unit]

Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

------啟動nginx服務
systemctl start nginx.service
------設置開機自啟動
systemctl enable nginx.service
------停止開機自啟動
# systemctl disable nginx.service
------查看服務當前狀態
systemctl status nginx.service
------重新啟動服務
systemctl restart nginx.service
------查看所有已啟動的服務
systemctl list-units --type=service

3.2 操作日志

[root@ip104 src]# vi /lib/systemd/system/nginx.service 
[root@ip104 src]# systemctl start nginx.service
[root@ip104 src]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2019-10-01 13:09:43 CST; 7s ago
  Process: 8441 ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS)
  Process: 8439 ExecStartPre=/usr/local/nginx/sbin/nginx -t (code=exited, status=0/SUCCESS)
 Main PID: 8444 (nginx)
    Tasks: 2
   Memory: 1.5M
   CGroup: /system.slice/nginx.service
           ├─8444 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/ngi...
           └─8445 nginx: worker process

Oct 01 13:09:43 ip104 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 01 13:09:43 ip104 nginx[8439]: nginx: the configuration file /usr/local/nginx/... ok
Oct 01 13:09:43 ip104 nginx[8439]: nginx: configuration file /usr/local/nginx/conf...ful
Oct 01 13:09:43 ip104 systemd[1]: Started The nginx HTTP and reverse proxy server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@ip104 src]# 

至此結束,看到以下命令表示成功配置

                            Welcome to tengine!
              If you see this page, the tengine web server is successfully 
              installed and working. Further configuration is required.

              For online documentation and support please refer to tengine.taobao.org.

              Thank you for using tengine.

4、相關操作命令,擴展安裝Nginx

4.1 介紹 PCRE (http://www.pcre.org/)

PCRE 下載地址:
ftp://ftp.pcre.org/pub/pcre/

https://ftp.pcre.org/pub/pcre/

4.2 下載安裝包、解壓軟件、編譯安裝

[root@ip104 src]# cd /usr/local/src/
[root@ip104 src]# wget http://downloads.sourceforge.net/project/pcre/pcre/8.35/pcre-8.35.tar.gz
[root@ip104 src]# tar zxvf pcre-8.35.tar.gz
[root@ip104 src]# cd pcre-8.35
[root@ip104 pcre-8.35]# ./configure
[root@ip104 pcre-8.35]# make && make install

4.3 安裝Nginx

[root@ip104 src]# cd /usr/local/src/
[root@ip104 src]# wget http://nginx.org/download/nginx-1.6.2.tar.gz
[root@ip104 src]# tar zxvf nginx-1.6.2.tar.gz
[root@ip104 src]# cd nginx-1.6.2
[root@ip104 nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35
[root@ip104 nginx-1.6.2]# make
[root@ip104 nginx-1.6.2]# make install
 

4.3 Nginx 和 Tenginx 配置文件

vi /usr/local/nginx/conf/nginx.conf

server {
    listen        80;
    server_name   example.com *.example.com;
    location / {
        proxy_pass         http://localhost:5000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}


--重新啟動
systemctl restart nginx
--查看狀態
systemctl status nginx

4.4 Nginx 和 Tenginx 查詢配置

[root@ip104 ~]# cd /usr/local/nginx/sbin
[root@ip104 sbin]# ./nginx -V
Tengine version: Tengine/2.3.2
nginx version: nginx/1.17.3
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments:
[root@ip104 sbin]# 

其他說明

相關資源后續更新

Linux常用命令

touch .bash_profile。配置環境變量

java -verbose-查看jdk安裝路徑

java -version-查看jdk版本

vim-編輯

pwd-查看當前工作路徑

su root -切換到root下

netstat -ntlp //查看當前所有tcp端口

ps -ef | grep //查看進程號

ps命令將某個進程顯示出來


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM