#!/bin/bash
################
#2018/06/11
###############
yum install -y gcc gcc-c++  libtool   git  wget

groupadd www -g 503
useradd -s /sbin/nologin -M www -u 503 -g 503


soft_path=/root/software

if [ ! -d $soft_path ];then
        mkdir $soft_path
        cd $soft_path
else
        cd $soft_path
fi


if [ ! -f jemalloc-4.2.1.tar.bz2 ];then

wget http://47.90.101.26/linux/nginx/tengine/jemalloc-4.2.1.tar.bz2
tar jxf jemalloc-4.2.1.tar.bz2
fi

if [ ! -f tengine-2.1.2.tar.gz ];then
wget http://47.90.101.26/linux/nginx/tengine/tengine-2.1.2.tar.gz
tar zxf tengine-2.1.2.tar.gz
fi

if [ ! -f pcre-8.34.tar.gz ];then

wget http://47.90.101.26/linux/nginx/pcre-8.34.tar.gz
tar zxf pcre-8.34.tar.gz 

fi
if [ ! -f zlib-1.2.8.tar.gz ];then
wget http://47.90.101.26/linux/nginx/zlib-1.2.8.tar.gz
tar zxf zlib-1.2.8.tar.gz 
fi

if [ ! -f lua-5.3.3.tar.gz ];then
wget http://47.90.101.26/linux/nginx/tengine/lua-5.3.3.tar.gz
tar zxf lua-5.3.3.tar.gz
fi


if [ ! -f LuaJIT-2.0.4.tar.gz ];then
wget http://47.90.101.26/linux/nginx/tengine/LuaJIT-2.0.4.tar.gz
tar zxf LuaJIT-2.0.4.tar.gz
fi
if [ ! -f openssl-1.0.2h.tar.gz ];then
wget http://47.90.101.26/linux/nginx/tengine/openssl-1.0.2h.tar.gz
tar zxf openssl-1.0.2h.tar.gz
fi



#编译安装组件

cd lua-5.3.3/

make linux
make install

cd $soft_path

cd LuaJIT-2.0.4/

make

make install

cd $soft_path
cd jemalloc-4.2.1/

./configure

make
make install

#设置全局变量

env_stats=`cat /etc/profile |grep LUAJIT_LIB |grep -v grep |wc -l`

if [ $env_stats == 0 ];then
echo "export LUAJIT_LIB=/usr/local/lib" >>/etc/profile
echo "export LUAJIT_INC=/usr/local/include/luajit-2.0" >>/etc/profile
echo "export JEMALLOC_INCLUDEDIR=/usr/local/include/jemalloc" >>/etc/profile
echo "export JEMALLOC_LIBDIR=/usr/local/lib" >>/etc/profile
fi

source /etc/profile



###编译tengine

cd $soft_path
cd tengine-2.1.2

./configure --prefix=/opt/tengine \
--dso-path=/opt/tengine/dso-path \
--with-rtsig_module \
--with-select_module \
--with-file-aio \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_dyups_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_auth_request_module \
--with-http_concat_module \
--with-http_sysguard_module \
--with-http_lua_module \
--with-pcre=../pcre-8.34 \
--with-zlib=../zlib-1.2.8 \
--with-jemalloc \
--with-openssl=../openssl-1.0.2h \



make

make install

##增加库路径
echo "/usr/local/lib/" >>/etc/ld.so.conf
ldconfig
##
cd /opt/tengine/conf/
rm -f nginx.conf
wget http://47.90.101.26/linux/nginx/tengine/nginx.conf
wget http://47.90.101.26/linux/nginx/tengine/waf0925.tar.gz
tar zxf waf.tar.gz

wget http://47.90.101.26/linux/nginx/tengine/nginx.txt
cp nginx.txt  /etc/init.d/nginx 
chmod +x /etc/init.d/nginx




