Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

CentOS 上 Tengine 的源碼安裝與設定完整實作

Tengine 是基於 Nginx 的高性能 Web 伺服器。本文以 CentOS 7 為例,示範從準備相依元件到編譯安裝、設定服務的整套流程。

1. 系統環境

[root@centos ~]# yum update -y
[root@centos ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)

2. 安裝 Tengine

2.1 準備安裝,下載 pcre、zlib、openssl、jemalloc 與 tengine:

[root@centos ~]# cd /usr/local/src/
[root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
[root@centos ~]# wget https://zlib.net/zlib-1.2.8.tar.gz
[root@centos ~]# wget https://www.openssl.org/source/openssl-1.0.1h.tar.gz
[root@centos ~]# wget https://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
[root@centos ~]# wget https://tengine.taobao.org/download/tengine-2.1.2.tar.gz

2.2 更新套件:yum install zlib-devel openssl-devel -y

2.3 安裝 Pcre:

cd /usr/local/src/ && tar zvxf pcre-8.39.tar.gz
cd pcre-8.39 && ./configure && make && make install

2.4 安裝 openssl:

cd /usr/local/src/ && tar zvxf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h && ./config && make && make install

2.5 安裝 zlib:

cd /usr/local/src/ && tar zvxf zlib-1.2.8.tar.gz
cd zlib-1.2.8 && ./configure && make && make install

2.6 安裝 jemalloc:

cd /usr/local/src/ && tar jvxf jemalloc-3.6.0.tar.bz2
cd jemalloc-3.6.0 && ./configure && make && make install
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig

4.4 建立 www 用戶與群組、網站目錄與日誌目錄並授權:

groupadd www
useradd -g www www
mkdir -p /data/www
chmod +w /data/www
chown -R www:www /data/www

4.5 安裝 Tengine:

cd /usr/local/src/ && tar zvxf tengine-2.1.2.tar.gz
cd /usr/local/src/tengine-2.1.2/src/core
# 可修改 nginx.h 偽裝伺服器資訊(選做)
./configure --prefix=/opt/nginx --user=www --group=www \
  --with-http_stub_status_module --with-http_ssl_module \
  --with-http_gzip_static_module \
  --with-openssl=/usr/local/src/openssl-1.0.1h \
  --with-zlib=/usr/local/src/zlib-1.2.8 \
  --with-pcre=/usr/local/src/pcre-8.35 --with-jemalloc
make && make install

4.6 修改 /opt/nginx/conf/nginx.conf:

user www www;
worker_processes 4;
error_log logs/error.log crit;
pid logs/nginx.pid;
events {
    use epoll;
    worker_connections 65535;
}

4.7 測試與運行:

cd /opt/nginx && ldconfig
./sbin/nginx -t     # 顯示 syntax is ok / test is successful 即可
./sbin/nginx        # 啟動
ps au | grep nginx

可用 ps -n | grep jemalloc 確認加速是否生效,再用 curl https://localhost 測試。

4.8 開啟防火牆 80 埠:

systemctl stop firewalld.service
systemctl disable firewalld.service
yum install iptables-services

編輯 /etc/sysconfig/iptables 加入 80 埠規則:

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

接著 systemctl restart iptables.service 並 systemctl enable iptables.service。

4.9 設為服務、開機自啟,建立 /usr/lib/systemd/system/tengine.service:

[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

最後以 systemctl enable/start tengine 啟動,並 shutdown -r now 重啟驗證。

Copyright © Linux教程網 All Rights Reserved