小菜菜博客
当前位置: Devops运维 > Centos7 源码编译安装Tengine

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

安装Tengine/2.2.0

1.1 下载源码安装包

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

1
2
[[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(用于支持数据压缩)

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

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

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

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

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

1.1.5 源码包tengine-2.2.0

1
2
3
[[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 更新工具包

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

1.2.2 编译pcre

1
2
3
4
[[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

1
2
3
4
[[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

1
2
3
4
[[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

1
2
3
4
5
6
[[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包

1
2
3
4
5
6
7
8
9
10
11
[[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 加载库文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[[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

1
2
3
4
5
6
7
8
9
10
11
12
13
[[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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
[[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编译成功!
1
2
3
4
5
6
验证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 编写服务,实现开机启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[[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
1
2
3
4
5
[[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)

启动服务

1
2
3
[[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

设置开机启动

1
2
[[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"

最新评论

    暂无留言哦~~

博客简介

学海无涯,唯勤是舟 我是生活在中东的 一条咸鱼,这是我记录学习笔记的博客,目前在学习Devops Golang Vue。

精彩评论

友情链接

他们同样是一群网虫,却不是每天泡在网上游走在淘宝和网游之间、刷着本来就快要透支的信用卡。他们或许没有踏出国门一步,但同学却不局限在一国一校,而是遍及全球!申请交换友链

站点统计

  • 文章总数: 69 篇
  • 草稿数目: 1 篇
  • 分类数目: 12 个
  • 独立页面: 2 个
  • 评论总数: 3 条
  • 链接总数: 4 个
  • 标签总数: 42 个
  • 注册用户: 1 人
  • 访问总量: 8,670,021 次
  • 最近更新: 2021年10月17日
服务热线:
 18888888889

 QQ在线交流

 旺旺在线