CentOS 7.6 编译安装tengine
安装依赖包
yum -y install gcc gcc-c++ bzip2 perl curl curl-devel wget expat-devel gettext-devel openssl-devel libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel autoconf
配置扩展包安装源
yum -y install epel*
yum -y install libmcrypt libmcrypt-devel mcrypt mhash
###安装编译所需要的核心组件:
1 pcre
一个Perl库,包括 perl 兼容的正则表达式库。nginx rewrite依赖于PCRE库,所以在安装Tengine前一定要先安装PCRE
cd /usr/local/src && wget https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz && tar zxvf pcre-8.42.tar.gz && cd pcre-8.42 && ./configure --prefix=/usr/local/pcre && make && make install
2 zlib
Zlib是提供资料压缩之用的函式库,当Tengine想启用GZIP压缩的时候就需要使用到Zlib
cd /usr/local/src && wget http://zlib.net/zlib-1.2.11.tar.gz && tar zxvf zlib-1.2.11.tar.gz && cd zlib-1.2.11 && ./configure --prefix=/usr/local/zlib && make && make install
3 jemalloc
jemalloc是一个更好的内存管理工具,使用jemalloc可以更好的优化Tengine的内存管理
cd /usr/local/src && wget https://github.com/jemalloc/jemalloc/releases/download/5.1.0/jemalloc-5.1.0.tar.bz2 && tar xvf jemalloc-5.1.0.tar.bz2 && cd jemalloc-5.1.0 && ./configure --prefix=/usr/local/jemalloc && make && make install
4 OpenSSL
OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。主要是为了让tengine支持Https的访问请求
cd /usr/local/src && wget https://www.openssl.org/source/openssl-1.1.1.tar.gz && tar zxvf openssl-1.1.1.tar.gz && cd openssl-1.1.1 && ./config --prefix=/usr/local/openssl && make && make install
5 安装Tengine
从官网下载 http://tengine.taobao.org/
cd /usr/local/src && wget 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 --prefix=/usr/local/tengine \
--with-pcre=/usr/local/src/pcre-8.42 \
--with-openssl=/usr/local/src/openssl-1.1.1 \
--with-jemalloc=/usr/local/src/jemalloc-5.1.0 \
--with-http_gzip_static_module \
--with-http_addition_module \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--add-module=./modules/ngx_http_upstream_check_module \
--add-module=./modules/ngx_http_upstream_vnswrr_module \
--add-module=./modules/ngx_http_upstream_session_sticky_module \
--add-module=./modules/ngx_http_upstream_consistent_hash_module \
--add-module=./modules/ngx_http_proxy_connect_module
make -j 4&&make install
# 为了设置成开机自启动,我们需要创建tengine.service文件
cd /lib/systemd/system
vim 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=/usr/local/tengine/logs/nginx.pid
ExecStartPre=/usr/local/tengine/sbin/nginx -t
ExecStart=/usr/local/tengine/sbin/nginx -c /usr/local/tengine/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 755 tengine.service
systemctl enable tengine.service
systemctl start tengine.service
6 tengine主配置文件
user nobody ;
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 10240;
}
http {
server_tokens off;
server_tag off;
autoindex off;
access_log off;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log off ;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 10m;
client_body_buffer_size 256k;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
proxy_connect_timeout 600;
proxy_read_timeout 600;
proxy_send_timeout 600;
proxy_buffer_size 128k;
proxy_buffers 4 128k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
proxy_headers_hash_max_size 1024;
proxy_headers_hash_bucket_size 128;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
upstream backend{
session_sticky ;
server 192.168.1.11:80;
server 192.168.1.12:80;
check interval=3000 rise=2 fall=5 timeout=1000 type=http;
check_http_send "HEAD / HTTP/1.0\r\n\r\n";
check_http_expect_alive http_2xx http_3xx;
}
# refuse request server by ipaddr
server {
server_name _;
return 404;
}
include vhost/*.conf;
}