将nginx替换为tengine 笔记

Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。从2011年12月开始,Tengine成为一个开源项目。现在,它由Tengine团队开发和维护。Tengine团队的核心成员来自于淘宝、搜狗等互联网企业。

tengine简单来说就是淘宝自己基于nginx优化的网页引擎,在nginx原先基础上继续保持兼容,同时功能扩展,效率提高,可以看到目前淘宝网在这么多人同时使用的情况下依然稳定,我们足以相信tengine,由于它是nginx的一个分生版本,所以几乎完全兼容nginx,所以我认为tengine是搭建lnmp环境的不二之选。

废话不多说,我已经升级完毕,下面贴出我的过程。

我用的是amh4.2面板,基于lnmp架构,所以这里我直接讲解如何替换nginx变成tengine,部分安装路径和大家的不一定一样,但是过程是一样的。

首先访问tengine官方网站,获取最新的下载地址。http://tengine.taobao.org/

目前最新的版本是:tengine-2.1.1,我们首先wget

1
wget http://tengine.taobao.org/download/tengine-2.1.1.tar.gz

然后解压缩

1
2
tar -xvzf tengine-2.1.1.tar.gz
cd tengine-2.1.1/

获取nginx编译参数

1
nginx -V

得到如下文本

1
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module

在最后加上

1
--with-http_concat_module

我们得到了预编译指令:

1
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_uwsgi_module --without-http_scgi_module --with-http_concat_module

执行完毕后,输入

1
make -j 3

这里只需要make,不需要make install,make后的-j是表示使用多核,我的服务器是4核的,于是我使用三核编译,为何不用四核,因为cpu爆满后ssh容易掉线。

下面我们到objs目录

1
cd objs/

停止旧的nginx

1
service nginx stop

备份旧的nginx,换上tengine

1
2
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp nginx /usr/local/nginx/sbin/

大功告成~下面测试下能否正常运行

1
nginx -t

如果出现

1
2
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful

那么恭喜,已经完成替换。

1
service nginx start

启动tengine,完成更新。

最后,随便打开一个不存在的页面,看看错误提示是否显示是tengine,一般是不会有误啦~