共计 5277 个字符,预计需要花费 14 分钟才能阅读完成。
环境:
系统硬件:VMware vsphere (CPU:2* 4 核,内存 2G)
系统版本:CentOS Linux release 7.0.1406
安装步骤:
1. 系统环境
1.1 更新系统
[root@centos ~]# yum update -y
1.2 查看环境
[root@centos ~]# cat /etc/RedHat-release
CentOS Linux release 7.0.1406 (Core)
[root@centos ~]# uname -a
Linux tengine 3.10.0-123.4.2.el7.x86_64 #1 SMP Mon Jun 30 16:09:14 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
2. 安装 tengine
2.1. 准备安装
[root@centos ~]# cd /usr/local/src/
下载 pcre-8.35.tar.gz 到 /usr/local/src
[root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
下载 zlib-1.2.8.tar.gz 到 /usr/local/src
[root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz
下载 openssl-1.0.1h.tar.gz 到 /usr/local/src
[root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
下载 jemalloc-3.6.0.tar.bz2 到 /usr/local/src
[root@centos ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
下载 tengine-2.0.3.tar.gz 到 /usr/local/src
[root@centos ~]# wget http://tengine.taobao.org/download/tengine-2.0.3.tar.gz
2.2 更新包
[root@centos ~]# yum install zlib-devel openssl-devel -y
2.3 安装 Pcre
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf pcre-8.35.tar.gz
[root@centos ~]# cd pcre-8.35
[root@centos ~]# ./configure
[root@centos ~]# make && make install
2.4 安装 openssl
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf openssl-1.0.1h.tar.gz
[root@centos ~]# cd openssl-1.0.1h
[root@centos ~]# ./config
[root@centos ~]# make && make install
2.5 安装 zlib
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zlib-1.2.8.tar.gz
[root@centos ~]# cd zlib-1.2.8
[root@centos ~]# ./configure
[root@centos ~]# make && make install
2.6 安装 jemalloc
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf jemalloc-3.6.0
[root@centos ~]# cd jemalloc-3.6.0
[root@centos ~]# ./configure
[root@centos ~]# make && make install
[root@centos ~]# echo‘/usr/local/lib‘> /etc/ld.so.conf.d/local.conf
[root@centos ~]# ldconfig
4.4 创建 www 用户和组,创建 www 虚拟主机使用的目录,以及 Nginx 使用的日志目录,并且赋予他们适当的权限
[root@centos ~]# groupadd www
[root@centos ~]# useradd -g www www
[root@centos ~]# mkdir -p /data/www
[root@centos ~]# chmod +w /data/www
[root@centos ~]# chown -R www:www /data/www
4.5 安装 tengine
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zvxf tengine-2.0.3.tar.gz
伪装服务器信息(可以不修改)
[root@centos ~]# cd nginx-1.6.0/src/core
[root@centos ~]# vim ./src/core/nginx.h
修改 NGINX_VERSION 为你希望显示的版号
修改 NGINX_VER 为你希望显示的名称
修改 NGINX_VAR 为你希望显示的名称
保存
开始安装 NGINX
./configure –prefix=/opt/nginx –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.1h –with-zlib=/usr/local/src/zlib-1.2.8 –with-pcre=/usr/local/src/pcre-8.35 –with-jemalloc
[root@centos ~]# make && make install
4.6 修改 nginx.conf
[root@centos ~]# vim /opt/nginx/conf/nginx.conf
修改前面几行为:
user www www;
worker_processes 4;
error_log logs/error.log crit;
pid logs/nginx.pid;
events{
use epoll;
worker_connections 65535;
}
4.7 测试和运行
[root@centos ~]# cd /opt/nginx
[root@centos ~]# ldconfig
[root@centos ~]# ./sbin/nginx -t
如果显示下面信息,即表示配置没问题
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
输入代码运行 nginx 服务
[root@centos ~]# ./sbin/nginx
[root@centos ~]# ps au|grep nginx
如果显以类似下面的信息,即表示 nginx 已经启动
root 2013 0.0 0.0 103156 856 pts/0 S+ 03:22 0:00 grep nginx
输入代码检测是否支持加速
查看是否生效
[root@centos ~]# lsof -n | grep jemalloc
ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2347 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2348 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2349 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2350 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
[root@centos ~]# curl http://localhost
4.8 打开防火墙 80 端口
# 停止 firewall
[root@centos ~]# systemctl stop firewalld.service
# 禁止 firewall 开机启动
[root@centos ~]# systemctl disable firewalld.service
安装 iptables
[root@centos ~]# yum install iptables-services
设置防火墙规则 (增加 80 端口)
[root@centos ~]# vim /etc/sysconfig/iptables
打开文件,增加 80 端口那一行
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 22 -j ACCEPT
-A INPUT -p tcp -m state –state NEW -m tcp –dport 80 -j ACCEPT
-A INPUT -j REJECT –reject-with icmp-host-prohibited
-A FORWARD -j REJECT –reject-with icmp-host-prohibited
COMMIT
:wq #保存退出
# 重启防火墙使配置生效
[root@centos ~]# systemctl restart iptables.service
# 设置防火墙开机启动
[root@centos ~]# systemctl enable iptables.service
4.9 作为服务,开机后启动
[root@centos ~]# 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=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
:wq 保存退出
[root@centos ~]# systemctl stop tengine
[root@centos ~]# systemctl start tengine
[root@centos ~]# systemctl reload tengine
[root@centos ~]# systemctl enable tengine
[root@centos ~]# shutdown -r now
相关阅读 :
CentOS 6.4 制作 Tengine 的 rpm 包 http://www.linuxidc.com/Linux/2013-12/93786.htm
Tengine 动态开启模块试用 http://www.linuxidc.com/Linux/2012-12/75849.htm
CentOS 6.3 用 ICC 编译 PHP5.4.8+Percona5.5.27+Tengine1.4.1 http://www.linuxidc.com/Linux/2012-12/76636.htm
基于淘宝 Tengine 和 Scribe 的 WEB 日志收集方案 http://www.linuxidc.com/Linux/2012-02/52997.htm
基于 Tengine 部署 LNMP 环境 http://www.linuxidc.com/Linux/2014-01/95148.htm
Tengine 的详细介绍 :请点这里
Tengine 的下载地址 :请点这里
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-09/123050.htm