nginx源码安装脚本

脚本如下:

源码包 版本 nginx-1.12.2.tar.gz

#!/bin/bash

NGINXDIR=/usr/local/nginx

NGINX=nginx-1.12.2

TAR=.tar.gz

NGINXMBER=81

NGINXUN=82

NGINXPROT=`lsof -i :80 | awk 'NR==2{print $1}'`


setenforce 0

netstat -nl | grep :80

if [ $? -eq 0 ];then

pkill -9 $NGINXPROT

else

echo "80 prot alredy release"

fi

for WARP in {gcc,gcc-c++,pcre,pcre-devel,openssl,openssl-devel,lsof}

 

do

rpm -q $WARP

if [ $? != 0 ];then

yum -y install $WARP

else

echo "$WARP already install"

fi

done

sleep 3

 

echo "----------------------install nginx-------------------"

 

id nginx &>/dev/null

if [ $? != 0 ];then

useradd nginx

else

echo "user nginx already be"

fi

#####################下载nginx源码包##################

echo "-----------------------------------------------------"

wget https://nginx.org/download/nginx-1.12.2.tar.gz

cd /root

tar -zxf /root/$NGINX$TAR

cd /root/$NGINX

./configure --prefix=$NGINXDIR --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --without-http_rewrite_module --with-stream

if [ $? != 0 ];then

echo "nginx configure failed "

exit $NGINXMBER

else

make && make install

fi

sed -i '26a upstream web {' $NGINXDIR/conf/nginx.conf

sed -i '27a server 200.1.1.10:80;' $NGINXDIR/conf/nginx.conf

sed -i '28a server 200.1.1.20:80;' $NGINXDIR/conf/nginx.conf

sed -i '29a }' $NGINXDIR/conf/nginx.conf

sed -i '30a server {' $NGINXDIR/conf/nginx.conf

sed -i '31a listen 80;' $NGINXDIR/conf/nginx.conf

sed -i '32a server_name www.tarena.com;' $NGINXDIR/conf/nginx.conf

sed -i '33a location / {' $NGINXDIR/conf/nginx.conf

sed -i '34a root html;' $NGINXDIR/conf/nginx.conf

sed -i '35a index index.html;' $NGINXDIR/conf/nginx.conf

sed -i '36a proxy_pass http://web;' $NGINXDIR/conf/nginx.conf

sed -i '37a } ' $NGINXDIR/conf/nginx.conf

sed -i '38a }' $NGINXDIR/conf/nginx.conf

 

ln -s $NGINXDIR/sbin/* /usr/sbin/

nginx -t

if [ $? -eq 0 ];then

nginx

else

echo "nginx configure file failed"

fi

posted @ 2021-02-23 11:58  woaibaobei  阅读(79)  评论(0编辑  收藏  举报