如何编译安装Tengine?

Nginx

1 基础知识

– Tengine是Nginx的完美替代方案。
– Tengine是由淘宝网发起的Web服务器项目。
– Tengine在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。
– Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。
– Tengine的最终目标是打造一个高效、稳定、安全、易用的Web平台。
– Tengine从2011年12月开始成为一个开源项目。
– Tengine由其团队在积极地开发和维护。
– Tengine团队的核心成员来自于淘宝、搜狗等互联网企业。
– Tengine是社区合作的成果,我们欢迎大家参与其中,贡献自己的力量。

2 最佳实践

2.1 系统环境

2.1.1 系统信息

OS = CentOS 7.x x86_64
IP Addresses = 10.168.0.80
Host Name = www.cmdschool.org

2.1.2 配置防火墙

firewall-cmd --permanent --add-service http --add-service https
firewall-cmd --reload
firewall-cmd --list-all

2.1.3 关闭selinux

sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0

2.1.4 升级系统

yum update -y

2.2 准备工作

2.2.1 准备编译环境

yum install -y gcc gcc-c++ make expat-devel autoconf

2.2.2 备份当前配置并删除rpm安装包

cd ~
tar -cvzf nginx-conf.tar.bz /etc/nginx/
yum remove -y nginx

2.2.3 下载并解压安装包

cd ~/
wget https://github.com/alibaba/tengine/archive/refs/tags/2.4.0.tar.gz -O tengine-2.4.0.tar.gz
tar -xf tengine-2.4.0.tar.gz

2.2.4 创建运行用户

groupadd  -g 988 nginx
useradd -u 990 -g 988 -d /var/cache/nginx -s /bin/bash nginx -c "nginx user"

2.3 编译安装

2.3.1 预编译软件包

cd ~/tengine-2.4.0/
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' \
--with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

另外,如果你需要参考已经编译的Nginx编译参数,建议你可以使用如下命令,

nginx -V

如果遇到如下提示,

./configure: error: the HTTP rewrite module requires the PCRE library.

请使用如下命令解决依赖关系,

yum install -y pcre-devel

如果遇到如下提示,

./configure: error: SSL modules require the OpenSSL library.

请使用如下命令解决依赖关系,

yum install -y openssl-devel

2.3.2 编译软件包

cd ~/tengine-2.4.0/
make

2.3.3 安装软件包

cd ~/tengine-2.4.0/
make install

2.3.4 验证安装

nginx -v

可见如下输出,

Tengine version: Tengine/2.4.0
nginx version: nginx/1.22.1

2.4 配置软件

2.4.1 创建启动脚本

cat > /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=tengine - high performance web server
Documentation=https://tengine.taobao.org/documentation_cn.html
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPost=/bin/sleep 0.1
ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP \$(/bin/cat /var/run/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM \$(/bin/cat /var/run/nginx.pid)"

[Install]
WantedBy=multi-user.target
EOF

脚本创建后,你需要使用如下命令重载并使服务生效,

systemctl daemon-reload

2.4.2 启动服务并设置自启动

systemctl start nginx.service
systemctl enable nginx.service

另外,你可以使用如下命令查询服务状态,

systemctl status nginx.service

参阅文档
============================
官方首页
————–
https://tengine.taobao.org/

安装包下载
————–
https://github.com/alibaba/tengine/releases
https://tengine.taobao.org/download.html

安装教程
————-
https://tengine.taobao.org/document/install.html

没有评论

发表回复

Nginx
如何解决https请求不安全http页被阻止问题?

1 前言 一个问题,一篇文章,一出故事。 笔者最近代理公司应用,发现https的页面有请求不安全的h …

Nginx
如何Nginx代理上游的子项目或文件夹?

1 前言 一个问题,一篇文章,一出故事。 笔者接到任务需要把Tomcat的其中一个应用号使用Ngin …

Nginx
如何安装部署RHEL 9 Nignx?

1 前言 一个问题,一篇文章,一出故事。 笔者需要基于RHEL 9部署Nginx环境,于是整理此文。 …