系统硬件:vmware vsphere (CPU:2*4核,内存2G)
系统版本:CentOS Linux release 7.0.1406
安装步骤:
1.系统环境
1.1 更新系统
[root@centos ~]# yum update -y
2.安装tengine
2.1.下载文件准备安装
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
[root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz
[root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
[root@centos ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
[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
cd /usr/local/src
mkdir /usr/local/pcre
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure --prefix=/usr/local/pcre
make && make install
2.4 安装openssl
cd /usr/local/src
mkdir /usr/local/openssl
tar zxvf openssl-1.0.1h.tar.gz
cd openssl-1.0.1h
./config --prefix=/usr/local/openssl
make && make install
vi /etc/profile
export PATH=$PATH:/usr/local/openssl/bin
:wq!
source /etc/profile
2.5 安装zlib
cd /usr/local/src
mkdir /usr/local/zlib
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure --prefix=/usr/local/zlib
make && make install
2.6 安装jemalloc
cd /usr/local/src
mkdir /usr/local/jemalloc
tar xvf jemalloc-3.6.0.tar.bz2
cd jemalloc-3.6.0
./configure --prefix=/usr/local/jemalloc
make && make install
4.4 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限
groupadd www
useradd -g www www -s /bin/false
4.5 安装tengine
[root@centos ~]# cd /usr/local/src/
[root@centos ~]# tar zxvf tengine-2.1.2.tar.gz
[root@centos ~]# cd tengine-2.1.2
伪装服务器信息(可以不修改)
[root@centos ~]# vim ./src/core/nginx.h
修改NGINX_VERSION为你希望显示的版号
修改NGINX_VER为你希望显示的名称
修改NGINX_VAR 为你希望显示的名称
保存
开始安装NGINX
./configure --prefix=/usr/local/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=/usr/local/src/jemalloc-3.6.0
[root@centos ~]# make && make install
4.6 修改 nginx.conf
[root@centos ~]# vi /usr/local/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 ~]# ldconfig
[root@centos ~]# cd /usr/local/nginx
[root@centos ~]# ./sbin/nginx -t
如果显示下面信息,即表示配置没问题
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
输入代码运行nginx服务
[root@centos ~]# /usr/local/nginx/sbin/nginx
[root@centos ~]# ps au|grep nginx ps aux | grep tengine
如果显以类似下面的信息,即表示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 iptables防火墙开放80端口
4.9 作为服务,开机后启动
[root@centos ~]# vi /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/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
:wq 保存退出
chkconfig tengine on
[root@centos ~]# systemctl stop tengine
[root@centos ~]# systemctl start tengine
[root@centos ~]# systemctl reload tengine
[root@centos ~]# reboot
[root@centos ~]# mkdir -p /_htdocs
[root@centos ~]# chmod +w /_htdocs
[root@centos ~]# chown -R www:www /_htdocs