CentOS 7.2编译安装Tengine

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

 

配置firewalld,iptables,关闭SELINUXhtml

 

一、安装必要的编译环境好nginx

因为Tengine安装须要使用源代码自行编译,因此在安装前须要安装必要的编译工具:c++

yum -y update
yum -y install gcc gcc-c++ bzip2 perl curl curl-devel expat-devel gettext-devel libxml2 libxml2-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel autoconf
(不安装openssl openssl-devel)

yum -y install epel-release  //扩展包更新包
yum -y update //更新yum源
yum -y install libmcrypt libmcrypt-devel mcrypt mhash
 
 
 

二、安装须要的组件git

A、PCREgithub

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.42.tar.gz && tar zxvf pcre-8.42.tar.gz && cd pcre-8.42 && ./configure --prefix=/usr/local/pcre && make && make install
 

B、Zlib算法

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

cd /usr/local/src && wget http://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://github.com/jemalloc/jemalloc/releases/)是一个更好的内存管理工具,使用jemalloc能够更好的优化Tengine的内存管理。

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

D、OpenSSL

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

cd /usr/local/src && wget https://www.openssl.org/source/openssl-1.1.1.tar.gz && tar zxvf openssl-1.1.1.tar.gz && cd openssl-1.1.1
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl --libdir=lib shared zlib-dynamic -Wl,-R,'$(LIBRPATH)' -Wl,--enable-new-dtags
make distclean && make && make install
 
cp /etc/pki/tls/cert.pem /usr/local/openssl/cert.pem
 
 
 
 

三、安装Tengine

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

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

接下来才是进行安装:

cd /usr/local/src && wget http://tengine.taobao.org/download/tengine-2.3.2.tar.gz && tar -zxvf tengine-2.3.2.tar.gz && cd tengine-2.3.2
. /configure --prefix=/usr/local/nginx \
--user=www \
--group=www \
--with-pcre=/usr/local/src/pcre-8.42 \
--with-openssl=/usr/local/src/openssl-1.1.1 \
--with-jemalloc=/usr/local/src/jemalloc-5.1.0 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-openssl=/usr/local/openssl \
--with-http_ssl_module \
--with-http_v2_module

make && make install

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

 

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

系统用户登陆系统后启动的服务 的目录 /usr/lib/systemd/system
如须要开机没有登录状况下就能运行的程序在系统目录内/lib/systemd/system

我但愿系统开机就启动目录,因此我把文件放在系统目录内。

cd /lib/systemd/system
vi 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

 

vi /etc/hosts     //注释掉下面一行
#::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

 

禁止系统检查邮件
echo "unset MAILCHECK" >> /etc/profile

 

姊妹篇:

编译安装PHP7: http://www.javashuo.com/article/p-cwujonsk-e.html

 

日志:

Tengine-Nginx: /usr/local/nginx/logs/error.log notice;
PHP-fpm: /var/log/php-fpm/error.log
PHP: /var/log/php/php-error.log

相关文章
相关标签/搜索