CentOS需使用7.*版本, 8.*版本因 OPENSSL_TLS_SECURITY_LEVEL=2 的問題暫沒有很好的解決辦法;
配置firewalld,iptables,關閉SELINUX
systemctl disable firewalld
1、安裝必要的編譯環境好
由於Tengine安裝需要使用源代碼自行編譯,所以在安裝前需要安裝必要的編譯工具:
yum -y install gcc gcc-c++ bzip2 perl curl curl-devel expat-devel gettext-devel libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel autoconf openssl openssl-devel
yum -y update //更新yum源
yum -y install libmcrypt libmcrypt-devel mcrypt mhash
wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz
wget http://zlib.net/zlib-1.2.11.tar.gz
wget https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2
wget https://www.openssl.org/source/openssl-1.1.1g.tar.gz
wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz
2、安裝需要的組件
A、PCRE
PCRE(Perl Compatible Regular Expressions)是一個Perl庫,包括 perl 兼容的正則表達式庫。nginx rewrite依賴於PCRE庫,所以在安裝Tengine前一定要先安裝PCRE
B、Zlib
Zlib是提供資料壓縮之用的函式庫,當Tengine想啟用GZIP壓縮的時候就需要使用到Zlib(http://www.zlib.net/)。
C、jemalloc
jemalloc(https://github.com/jemalloc/jemalloc/releases/)是一個更好的內存管理工具,使用jemalloc可以更好的優化Tengine的內存管理。
D、OpenSSL
OpenSSL 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及SSL協議,並提供豐富的應用程序供測試或其它目的使用。,安裝OpenSSL(http://www.openssl.org/source/)主要是為了讓tengine支持Https的訪問請求。
cd /mnt/wget && tar zxvf openssl-1.1.1g.tar.gz && cd openssl-1.1.1g && ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl --libdir=lib shared zlib-dynamic -Wl,-R,'$(LIBRPATH)' -Wl,--enable-new-dtags使用新版OpenSSL mv /usr/bin/openssl /usr/bin/openssl.bak mv /usr/include/openssl /usr/include/openssl.bak 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.1.1 /usr/lib64/libssl.so.1.1 ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
3、安裝Tengine
在主要核心的組件安裝完畢以后就可以安裝Tegine了,最新版本的Tegine可從官網(http://tengine.taobao.org/)獲取。
在編譯安裝前還需要做的一件事是添加一個專門的用戶來執行Tengine。當然你也可以用root(不建議)。
接下來才是進行安裝:
./configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre=/mnt/wget/pcre-8.43 \
--with-openssl=/mnt/wget/openssl-1.1.1g \
--with-jemalloc=/mnt/wget/jemalloc-5.2.1 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_ssl_module \
make && make install
注意配置的時候 –with-pcre 、–with-openssl、–with-jemalloc、–with-zlib的路徑為源文件的路徑。
4、配置Tengine,設置tengine自動啟動
如需要開機沒有登陸情況下就能運行的程序在系統目錄內/lib/systemd/system
我希望系統開機就啟動目錄,所以我把文件放在系統目錄內。
cd /lib/systemd/system
vi nginx.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=/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
修改文件權限 chmod 745 nginx.service
設置為開機啟動 systemctl enable nginx.service
啟動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
打開nscd服務,緩存dns,提高RDS響應
systemctl start nscd.service
systemctl enable nscd.service
vi /etc/hosts //注釋掉下面一行 #::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
禁止系統檢查郵件
echo "unset MAILCHECK" >> /etc/profile
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64 /usr/local/mysql/lib' >> /etc/ld.so.conf && ldconfig
姊妹篇:
編譯安裝PHP7: https://www.cnblogs.com/doseoer/p/5350944.html
日志:
Tengine-Nginx: /usr/local/nginx/logs/error.log notice;
PHP-fpm: /var/log/php-fpm/error.log
PHP: /var/log/php/php-error.log