迪龙网-迪拜华人房产投资指南

Tengine是由淘宝网发起的Web服务器项目。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。

安装Tengine/2.2.0

1.1 下载源码安装包

1.1.1 源码包pcre-8.40 (用于支持正则表达式)

[[email protected] ~] cd /usr/local/src/
[[email protected] src] wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz

1.1.2 源码包zlib-1.2.11(用于支持数据压缩)

[[email protected] src] wget http://zlib.net/zlib-1.2.11.tar.gz

1.1.3 源码包openssl-1.0.2(用于数据加密及支持SSL协议)

[[email protected] src] wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz

1.1.4 源码包jemalloc-4.4.0(用于优化内存管理)

[[email protected] src] wget https://github.com/jemalloc/jemalloc/archive/4.4.0.tar.gz

1.1.5 源码包tengine-2.2.0

[[email protected] src] wget http://tengine.taobao.org/download/tengine-2.2.0.tar.gz
[[email protected] src] ls
jemalloc-4.4.0.tar.gz  openssl-1.0.2k.tar.gz  pcre-8.40.tar.gz  tengine-2.2.0.tar.gz  zlib-1.2.11.tar.gz

1.2 编译安装依赖包

1.2.1 更新工具包

[[email protected] src] yum install openssl-devel zlib-devel -y

1.2.2 编译pcre

[[email protected] src] tar xf pcre-8.40.tar.gz
[[email protected] src] cd pcre-8.40
[[email protected] pcre-8.40] ./configure --prefix=/usr/local/pcre
[[email protected] pcre-8.40] make && make install

1.2.3 编译openssl

[[email protected] src] tar xf openssl-1.0.2k.tar.gz
[[email protected] src] cd openssl-1.0.2k
[[email protected] openssl-1.0.2k] ./config --prefix=/usr/local/openssl
[[email protected] openssl-1.0.2k] make && make install

1.2.4 编译zlib

[[email protected] src] tar xf zlib-1.2.11.tar.gz
[[email protected] src] cd zlib-1.2.11
[[email protected] zlib-1.2.11] ./configure --prefix=/usr/local/zlib
[[email protected] zlib-1.2.11] make && make install

1.2.5 编译jemalloc

[[email protected] src] tar xf jemalloc-4.4.0.tar.gz
[[email protected] src] cd jemalloc-4.4.0
[[email protected] jemalloc-4.4.0] ./autogen.sh
autoconf
./autogen.sh: line 5: autoconf: command not found
Error 0 in autoconf

1.2.6 安装autoconf包

[[email protected] jemalloc-4.4.0] yum install autoconf -y
[[email protected] jemalloc-4.4.0] ./autogen.sh
[[email protected] jemalloc-4.4.0] make
[[email protected] jemalloc-4.4.0] make install
/usr/bin/install: cannot stat ‘doc/jemalloc.html’: No such file or directory
make: *** [install_doc_html] Error 1
 这里只是说明文档和html页面没有,可以忽悠这个错误,可以直接touch
[[email protected] jemalloc-4.4.0] touch doc/jemalloc.html
[[email protected] jemalloc-4.4.0] make install
[[email protected] jemalloc-4.4.0] touch doc/jemalloc.3
[[email protected] jemalloc-4.4.0] make install 

1.2.7 加载库文件

[[email protected] tengine-2.2.0] echo ‘/usr/local/pcre/lib/‘ > /etc/ld.so.conf.d/pcre.conf
[[email protected] tengine-2.2.0] echo ‘/usr/local/zlib/lib/‘ > /etc/ld.so.conf.d/zlib.conf
[[email protected] tengine-2.2.0] echo ‘/usr/local/openssl/lib/‘ > /etc/ld.so.conf.d/openssl.conf
[[email protected] tengine-2.2.0] echo ‘/usr/local/lib/‘ > /etc/ld.so.conf.d/local.conf
[[email protected] tengine-2.2.0] ldconfig -v | less
/usr/local/lib:
        libjemalloc.so.2 -> libjemalloc.so.2
/usr/local/openssl/lib:
/usr/local/pcre/lib:
        libpcrecpp.so.0 -> libpcrecpp.so.0.0.1
        libpcreposix.so.0 -> libpcreposix.so.0.0.4
        libpcre.so.1 -> libpcre.so.1.2.8
/usr/local/zlib/lib:
        libz.so.1 -> libz.so.1.2.11
        ......
        ......

1.2.8 编译tengine

[[email protected] src] tar xf tengine-2.2.0.tar.gz
[[email protected] src] cd tengine-2.2.0

创建tengine运行用户
[[email protected] tengine-2.2.0] groupadd -g 80 www
[[email protected] tengine-2.2.0] useradd -u 80 -g 80 -s /sbin/nologin -M www

注意,在编译tengine时候,pcre, openssl, zlib必须指向源码目录,而jemalloc不能指向源码目录。切记!

[[email protected] tengine-2.2.0] ./configure --prefix=/usr/local/tengine --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.2k  --with-pcre=/usr/local/src/pcre-8.40  --with-zlib=/usr/local/src/zlib-1.2.11 --with-jemalloc

[[email protected] tengine-2.2.0] make
[[email protected] tengine-2.2.0] make install
[[email protected] tengine-2.2.0] cd /usr/local/tengine/
[[email protected] tengine] ls
conf  html  include  logs  modules  sbin
[[email protected] tengine] echo ‘PATH=$PATH:/usr/local/tengine/sbin/‘ > /etc/profile.d/tengine.sh
[[email protected] tengine] cat !$
cat /etc/profile.d/tengine.sh
PATH=$PATH:/usr/local/tengine/sbin/
[[email protected] tengine] source /etc/profile.d/tengine.sh
[[email protected] tengine] nginx
报错:nginx: error while loading shared libraries: libjemalloc.so.2: cannot open shared object file: No such file or directory

解决方法:    find / -name libjemalloc.so.2
                    /usr/local/lib/libjemalloc.so.2
                    /usr/src/jemalloc-4.4.0/lib/libjemalloc.so.2

vim /etc/ld.so.conf.d/ofter.conf
/usr/src/jemalloc-4.4.0/lib

让变量生效  /sbin/ldconfig


[[email protected] tengine] netstat -ntplu | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      53295/nginx: master

tengine编译成功!

验证jemalloc是否生效
[[email protected] tengine] yum install lsof -y
[[email protected] tengine] lsof -n | grep jemalloc
nginx     23371         root  mem       REG              253,0   2584161   34723136 /usr/local/lib/libjemalloc.so.2
            nginx     23372          www  mem       REG              253,0   2584161   34723136 /usr/local/lib/libjemalloc.so.2
jemalloc 已生效!

1.3 编写服务,实现开机启动

[[email protected] tengine-2.2.0] vim /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=/usr/local/tengine/logs/nginx.pid
ExecStartPre=/usr/local/tengine/sbin/nginx -t
ExecStart=/usr/local/tengine/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target    
[[email protected] tengine-2.2.0] nginx -s stop
[[email protected] tengine-2.2.0] systemctl status tengine
● tengine.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/tengine.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

启动服务

[[email protected] tengine-2.2.0] systemctl start tengine
[[email protected] tengine-2.2.0] netstat -ntplu | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      23429/nginx: master

设置开机启动

[[email protected] tengine-2.2.0] systemctl enable tengine
Created symlink from /etc/systemd/system/multi-user.target.wants/tengine.service to /usr/lib/systemd/system/tengine.service.
赞(0) 打赏
标签:

上一篇:

下一篇:

相关推荐

0 条评论关于"Centos7 源码编译安装Tengine"

表情

最新评论

    暂无留言哦~~

支付宝扫一扫打赏

微信扫一扫打赏