Centos7.8 编译安装 Nginx (Tengine/2.3.2)启动配置


tengine 安装配置
Tengine 是淘宝的一个非常重要的开源项目,它是基于Nginx二次开发的。它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性。Tengine的性能和稳定性已经在大型的网站如淘宝网,天猫商城等得到了很好的检验。它的最终目标是打造一个高效、稳定、安全、易用的Web平台。更多信息请参阅 http://tengine.taobao.org

1.依赖包安装

yum -y install gcc gcc-c++ bzip2
cd /usr/local/src
# 下载安装 jemalloc
wget https://xmyunwei.com/jemalloc-5.2.1.tar.bz2
tar jxvf jemalloc-5.2.1.tar.bz2 && mv jemalloc-5.2.1 jemalloc
cd jemalloc
./configure
make && make install
echo '/usr/local/lib/' >> /etc/ld.so.conf.d/local_lib.conf
ldconfig -v

#检查环境变量
echo $PKG_CONFIG_PATH

#如果变量返回值为空:
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/

#如果变量返回有库链接
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:$PKG_CONFIG_PATH

#永久写入:
sed -i '$ a\PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/' /etc/profile
sed -i '$ a\export PKG_CONFIG_PATH' /etc/profile

source /etc/profile

#检查环境变量
echo $PKG_CONFIG_PATH

# 下载安装 OpenSSL
wget https://xmyunwei.com/openssl-1.1.1h.tar.gz
tar zxvf openssl-1.1.1h.tar.gz && mv openssl-1.1.1h openssl
cd openssl
./config --prefix=/server/openssl/11
make && make install

#链接库
echo '/server/openssl/11/lib/' >> /etc/ld.so.conf.d/local_lib.conf

ldconfig -v

export PKG_CONFIG_PATH=/server/openssl/11/lib/pkgconfig/:$PKG_CONFIG_PATH

#永久写入:
vim /etc/profile

PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/:/server/openssl/11/lib/pkgconfig/
export PKG_CONFIG_PATH

#保存退出

#使配置生效
source /etc/profile


# 下载安装 pcre
wget https://xmyunwei.com/pcre-8.44.tar.gz
tar zxvf pcre-8.44.tar.gz && mv pcre-8.44 pcre
cd pcre
./configure
make && make install
# 下载安装 zlib
wget https://xmyunwei.com/zlib-1.2.11.tar.gz
tar zxvf zlib-1.2.11.tar.gz && mv zlib-1.2.11 zlib
cd zlib
./configure
make && make install
# 创建www用户和组,创建www虚拟主机使用的目录
groupadd www
useradd -g www www -s /sbin/nologin
mkdir -p /data/www
chmod +w /data/www
chown -R www:www /data/www

##编译安装Tengine

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=/server/nginx \
--user=www --group=www \
--conf-path=/server/nginx/conf/nginx.conf \
--error-log-path=/server/nginx/var/log/nginx_error.log \
--http-log-path=/server/nginx/var/log/nginx_access.log \
--pid-path=/server/nginx/var/run/nginx.pid \
--lock-path=/server/nginx/var/lock/nginx.lock \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_addition_module \
--with-jemalloc \
--with-openssl=/usr/local/src/openssl/ \
--with-zlib=/usr/local/src/zlib \
--with-pcre=/usr/local/src/pcre \
--http-client-body-temp-path=/server/nginx/tmp/client_body_temp \
--http-proxy-temp-path=/server/nginx/tmp/proxy_temp \
--http-fastcgi-temp-path=/server/nginx/tmp/fcgi_temp \
--http-uwsgi-temp-path=/server/nginx/tmp/uwsgi_temp \
--http-scgi-temp-path=/server/nginx/tmp/scgi_temp

编译过程略……

make && make install

2.创建 /etc/init.d/nginx文件

vim /etc/init.d/nginx
#! /bin/sh
# chkconfig: 2345 55 25
# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and
# run 'update-rc.d -f nginx defaults', or use the appropriate command on your
# distro. For CentOS/Redhat run: 'chkconfig --add nginx'

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

# Author:   PandaMan
# website:  https://xmyunwei.com

### 请注意NGINX目录位置!
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=nginx
NGINX_BIN=/server/nginx/sbin/$NAME
CONFIGFILE=/server/nginx/conf/$NAME.conf
PIDFILE=/server/nginx/var/run/$NAME.pid

case "$1" in
    start)
        echo -n "Starting $NAME... "
        if [ -f $PIDFILE ];then
            mPID=`cat $PIDFILE`
            isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
            if [ "$isStart" != '' ];then
                echo "$NAME (pid `pidof $NAME`) already running."
                exit 1
            fi
        fi

        $NGINX_BIN -c $CONFIGFILE

        if [ "$?" != 0 ] ; then
            echo " failed"
            exit 1
        else
            echo " done"
        fi
        ;;

    stop)
        echo -n "Stoping $NAME... "
        if [ -f $PIDFILE ];then
            mPID=`cat $PIDFILE`
            isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
            if [ "$isStart" = '' ];then
                echo "$NAME is not running."
                exit 1
            fi
        else
            echo "$NAME is not running."
            exit 1
        fi
        $NGINX_BIN -s stop

        if [ "$?" != 0 ] ; then
            echo " failed. Use force-quit"
            exit 1
        else
            echo " done"
        fi
        ;;

    status)
        if [ -f $PIDFILE ];then
            mPID=`cat $PIDFILE`
            isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
            if [ "$isStart" != '' ];then
                echo "$NAME (pid `pidof $NAME`) already running."
                exit 1
            else
                echo "$NAME is stopped"
                exit 0
            fi
        else
            echo "$NAME is stopped"
            exit 0
        fi
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    reload)
        echo -n "Reload service $NAME... "
        if [ -f $PIDFILE ];then
            mPID=`cat $PIDFILE`
            isStart=`ps ax | awk '{ print $1 }' | grep -e "^${mPID}$"`
            if [ "$isStart" != '' ];then
                $NGINX_BIN -s reload
                echo " done"
            else
                echo "$NAME is not running, can't reload."
                exit 1
            fi
        else
            echo "$NAME is not running, can't reload."
            exit 1
        fi
        ;;

    configtest)
        echo -n "Test $NAME configure files... "
        $NGINX_BIN -t
        ;;

    *)
        echo "Usage: $0 {start|stop|restart|reload|status|configtest}"
        exit 1
        ;;
esac

注:以上代码红色部分修改为自己安装Tengine路径

# 修改ngxin文件执行权限

chmod 755 /etc/init.d/nginx

# 添加开机启动

systemctl enable nginx

# 启动nginx

systemctl start nginx

出现 Starting nginx: nginx: [emerg] mkdir() “/var/tmp/nginx/client/” failed (2: No such file or directory) [FAILED]
创建文件目录即可

mkdir -p /server/nginx/tmp/client_body_temp

出现 Starting nginx: [ OK ] 正常

# 查看是否正常启动(nginx端口默认80)

netstat -anpt | grep 80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1525/nginx: master
 

# 防火墙添加端口

firewall-cmd --premanent --add-service=http 

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注