@H_502_2@环境:
@H_502_2@系统硬件:vmware vsphere (cpu:2*4核,内存2G)
@H_502_2@系统版本:CentOS Linux release 7.0.1406
@H_502_2@安装步骤:
@H_502_2@1.系统环境
@H_502_2@1.1 更新系统
@H_502_2@[root@centos ~]# yum update -y
@H_502_2@
@H_502_2@1.2 查看环境
@H_502_2@[root@centos ~]# cat /etc/redhat-release
@H_502_2@CentOS Linux release 7.0.1406 (Core)
@H_502_2@[root@centos ~]# uname -a
@H_502_2@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
@H_502_2@2.安装tengine
@H_502_2@2.1.准备安装
@H_502_2@[root@centos ~]# cd /usr/local/src/
@H_502_2@下载 pcre-8.35.tar.gz到/usr/local/src
@H_502_2@[root@centos ~]# wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
@H_502_2@下载zlib-1.2.8.tar.gz到/usr/local/src
@H_502_2@[root@centos ~]#wgethttp://zlib.net/zlib-1.2.8.tar.gz
@H_502_2@下载 openssl-1.0.1h.tar.gz到/usr/local/src
@H_502_2@[root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
@H_502_2@下载jemalloc-3.6.0.tar.bz2到/usr/local/src
@H_502_2@[root@centos ~]#wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2
@H_502_2@下载 tengine-2.0.3.tar.gz到/usr/local/src
@H_502_2@[root@centos ~]# wgethttp://tengine.taobao.org/download/tengine-2.0.3.tar.gz
@H_502_2@
@H_502_2@2.2 更新包
@H_502_2@[root@centos ~]# yum install zlib-devel openssl-devel -y
@H_502_2@2.3 安装Pcre
@H_502_2@[root@centos ~]# cd /usr/local/src/
@H_502_2@[root@centos ~]# tar zvxf pcre-8.35.tar.gz
@H_502_2@[root@centos ~]# cd pcre-8.35
@H_502_2@[root@centos ~]#./configure
@H_502_2@[root@centos ~]# make && make install
@H_502_2@2.4 安装openssl
@H_502_2@[root@centos ~]# cd /usr/local/src/
@H_502_2@[root@centos ~]#tar zvxf openssl-1.0.1h.tar.gz
@H_502_2@[root@centos ~]# cdopenssl-1.0.1h
@H_502_2@[root@centos ~]#./config
@H_502_2@[root@centos ~]# make && make install
@H_502_2@2.5 安装zlib
@H_502_2@[root@centos ~]# cd /usr/local/src/
@H_502_2@[root@centos ~]# tarzlib-1.2.8.tar.gz
@H_502_2@[root@centos ~]# cdzlib-1.2.8
@H_502_2@[root@centos ~]#./configure
@H_502_2@[root@centos ~]# make && make install
@H_502_2@2.6 安装jemalloc
@H_502_2@[root@centos ~]# cd /usr/local/src/
@H_502_2@[root@centos ~]#tar zvxfjemalloc-3.6.0
@H_502_2@[root@centos ~]# cdjemalloc-3.6.0
@H_502_2@[root@centos ~]#./configure
@H_502_2@[root@centos ~]# make && make install
@H_502_2@[root@centos ~]#echo ‘/usr/local/lib‘ > /etc/ld.so.conf.d/local.conf
@H_502_2@[root@centos ~]# ldconfig
@H_502_2@4.4 创建www用户和组,创建www虚拟主机使用的目录,以及Nginx使用的日志目录,并且赋予他们适当的权限
@H_502_2@[root@centos ~]# groupadd www
@H_502_2@[root@centos ~]# useradd -g www www
@H_502_2@[root@centos ~]# mkdir -p /data/www
@H_502_2@[root@centos ~]# chmod +w /data/www
@H_502_2@[root@centos ~]# chown -R www:www /data/www
@H_502_2@4.5 安装tengine
@H_502_2@[root@centos ~]# cd /usr/local/src/
@H_502_2@[root@centos ~]# tar zvxftengine-2.0.3.tar.gz
@H_502_2@伪装服务器信息(可以不修改)
@H_502_2@[root@centos ~]# cd Nginx-1.6.0/src/core
@H_502_2@[root@centos ~]# vim ./src/core/Nginx.h
@H_502_2@修改Nginx_VERSION为你希望显示的版号
@H_502_2@修改Nginx_VER为你希望显示的名称
@H_502_2@修改Nginx_VAR 为你希望显示的名称
@H_502_2@保存
@H_502_2@
@H_502_2@开始安装Nginx
@H_502_2@./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
@H_502_2@[root@centos ~]# make && make install
@H_502_2@4.6 修改 Nginx.conf
@H_502_2@[root@centos ~]# vim /opt/Nginx/conf/Nginx.conf
@H_502_2@修改前面几行为:
@H_502_2@user www www;
worker_processes 4;
error_log logs/error.log crit;
pid logs/Nginx.pid;
events{
use epoll;
worker_connections 65535;
}
@H_502_2@4.7 测试和运行
@H_502_2@[root@centos ~]# cd /opt/Nginx
@H_502_2@[root@centos ~]# ldconfig
@H_502_2@[root@centos ~]# ./sbin/Nginx -t
@H_502_2@如果显示下面信息,即表示配置没问题
@H_502_2@Nginx: the configuration file /opt/Nginx/conf/Nginx.conf Syntax is ok
Nginx: configuration file /opt/Nginx/conf/Nginx.conf test is successful
@H_502_2@输入代码运行Nginx服务
@H_502_2@[root@centos ~]# ./sbin/Nginx
@H_502_2@[root@centos ~]# ps au|grep Nginx
@H_502_2@如果显以类似下面的信息,即表示Nginx已经启动
@H_502_2@root 2013 0.0 0.0 103156 856 pts/0 S+ 03:22 0:00 grep Nginx
@H_502_2@
@H_502_2@输入代码检测是否支持加速
@H_502_2@查看是否生效
@H_502_2@[root@centos ~]# lsof -n | grep jemalloc
@H_502_2@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
@H_502_2@[root@centos ~]# curl http://localhost
@H_502_2@4.8 打开防火墙80端口
@H_502_2@#停止firewall
@H_502_2@[root@centos ~]#systemctl stop firewalld.service
@H_502_2@#禁止firewall开机启动
@H_502_2@[root@centos ~]#systemctl disable firewalld.service
@H_502_2@安装iptables
@H_502_2@[root@centos ~]#yum install iptables-services
@H_502_2@设置防火墙规则 (增加80端口)
@H_502_2@[root@centos ~]#vim /etc/sysconfig/iptables
@H_502_2@打开文件,增加80端口那一行
@H_502_2@*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
@H_502_2@:wq #保存退出
@H_502_2@#重启防火墙使配置生效
@H_502_2@[root@centos ~]#systemctl restart iptables.service
@H_502_2@#设置防火墙开机启动
@H_502_2@[root@centos ~]#systemctl enable iptables.service
@H_502_2@4.9 作为服务,开机后启动
@H_502_2@[root@centos ~]# vim /usr/lib/systemd/system/tengine.service
@H_502_2@增加以下内容
@H_502_2@[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
@H_502_2@:wq 保存退出
@H_502_2@[root@centos ~]#systemctl stop tengine
@H_502_2@[root@centos ~]#systemctl start tengine
@H_502_2@[root@centos ~]#systemctl reload tengine
@H_502_2@[root@centos ~]#systemctl enabletengine
@H_502_2@[root@centos ~]# shutdown -r now