CentOS 7.4 编译安装 Tengine

本贴最后更新于 1898 天前,其中的信息可能已经时移世易

CentOS 7.1 编译安装 Tengine

Tengine 官网上有个非常简单的教程,中间并未涉及到一些常用的设置,所以仅供参考。一下午为本人的安装步骤及过程。

配置 firewalld,iptables,关闭 SELINUX

下载安装包

image

1、安装必要的编译环境好

由于 Tengine 安装需要使用源代码自行编译,所以在安装前需要安装必要的编译工具:

yum -y update
yum -y install gcc gcc-c++ bzip2 perl curl curl-devel expat-devel gettext-devel openssl-devel libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel autoconf
yum -y install epel-release  //扩展包更新包
yum -y update //更新yum源
yum -y install libmcrypt libmcrypt-devel mcrypt mhash

2、安装需要的组件

A、PCRE

PCRE(Perl Compatible Regular Expressions)是一个 Perl 库,包括 perl 兼容的正则表达式库。nginx rewrite 依赖于 PCRE 库,所以在安装 Tengine 前一定要先安装 PCRE

cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
tar zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/pcre
make && make install

B、Zlib

Zlib 是提供资料压缩之用的函式库,当 Tengine 想启用 GZIP 压缩的时候就需要使用到 Zlib(https://www.zlib.net/)。

cd /usr/local/src
wget https://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

C、jemalloc

jemalloc(https://www.canonware.com/jemalloc/)是一个更好的内存管理工具,使用 jemalloc 可以更好的优化 Tengine 的内存管理。

cd /usr/local/src
wget https://github.com/jemalloc/jemalloc/releases/download/4.4.0/jemalloc-4.4.0.tar.bz2
tar xvf jemalloc-4.4.0.tar.bz2
cd jemalloc-4.4.0
./configure --prefix=/usr/local/jemalloc
make && make install

D、OpenSSL

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及 SSL 协议,并提供丰富的应用程序供测试或其它目的使用。,安装 OpenSSL(https://www.openssl.org/source/)主要是为了让 tengine 支持 Https 的访问请求。

cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.2j.tar.gz
tar zxvf openssl-1.1.0c.tar.gz
cd openssl-1.1.0c
./config --prefix=/usr/local/openssl

make && make install

tengine2.*使用 openssl1.1 为编译出错

3、安装 Tengine

在主要核心的组件安装完毕以后就可以安装 Tegine 了,最新版本的 Tegine 可从官网(https://tengine.taobao.org/)获取。
在编译安装前还需要做的一件事是添加一个专门的用户来执行 Tengine。当然你也可以用 root(不建议)。

groupadd www
useradd -s /sbin/nologin -g www www

接下来才是进行安装:

cd /usr/local/src
wget https://tengine.taobao.org/download/tengine-2.2.2.tar.gz
tar -zxvf tengine-2.2.2.tar.gz
cd tengine-2.2.2
./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.39 --with-openssl=/usr/local/src/openssl-1.1.0c --with-jemalloc=/usr/local/src/jemalloc-4.4.0 --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_concat_module --with-zlib=/usr/local/src/zlib-1.2.11 --with-ipv6 --with-mail --with-http_ssl_module  --with-http_v2_module
make && make install

注意配置的时候 –with-pcre 、–with-openssl、–with-jemalloc、–with-zlib 的路径为源文件的路径。

4、配置 Tengine,设置 tengine 自动启动

系统用户登录系统后启动的服务 的目录 /usr/lib/systemd/system
如需要开机没有登陆情况下就能运行的程序在系统目录内/lib/systemd/system
我希望系统开机就启动目录,所以我把文件放在系统目录内。

vim /lib/systemd/system/nginx.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/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

修改文件权限 chmod 745 nginx.service
设置为开机启动 systemctl enable nginx.service

启动 nginx 服务 systemctl start nginx.service
设置开机自启动 systemctl enable nginx.service
停止开机自启动 systemctl disable nginx.service
查看服务当前状态 systemctl status nginx.service
重新启动服务 systemctl restart nginx.service

查看所有已启动的服务 systemctl list-units --type=service

打开 nscd 服务,缓存 dns,提高 RDS 响应

systemctl start nscd.service
systemctl enable nscd.service
  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖 • 1 关注
  • Tengine
    2 引用 • 1 回帖
  • 安装

    你若安好,便是晴天。

    128 引用 • 1183 回帖

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...
  • someone

    ./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.39 --with-openssl=/usr/local/src/openssl-1.1.0c --with-jemalloc=/usr/local/src/jemalloc-4.4.0 --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_concat_module --with-zlib=/usr/local/src/zlib-1.2.11 --with-ipv6 --with-mail --with-http_ssl_module --with-http_v2_module