天天看点

linux下nginx自动部署脚本

请保证系统可以使用yum源,可以访问外网.

变量NGINX_PATH     修改nginx安装路径,默认为/opt/nginx

变量NGINX_VERSION    修改nginx的安装版本,默认为1.10.0

#!/bin/bash

# The nginx installation script automatically

# author:startuppp

LOCATION=$(pwd)

NGINX_PATH=/opt/nginx

NGINX_VERSION=1.10.0

echo -e "\n-----------------------------------------"

echo "Are performing installation, please wait a moment"

groupadd  nginx &>  /dev/null

useradd -M -s /sbin/nologin -g nginx  nginx &>  /dev/null

echo -e "Is downloading, please wait\n"

yum -y install wget  gcc gcc-c++ automake autoconf libtool make pcre*  zlib*  openssl*  lsof  &>  /dev/null 

#wget http://118.144.79.137/download/nginx-1.10.0.tar.gz &>  /dev/null

wget http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz  

echo -e "Is installation, please wait\n"

tar zxf nginx-$NGINX_VERSION.tar.gz

cd nginx-$NGINX_VERSION

./configure  --prefix=$NGINX_PATH --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module &>  /dev/null

make &>  /dev/null

make install &>  /dev/null

if [ $? -eq 0 ]

then

echo -e  "\nnginx安装成功\n"

else

echo -e  "\nnginx安装失败\n"

echo error 10 && exit 10

fi

cd /opt

if [ ! -d tools ]

        mkdir tools

netstat -npult|grep nginx

if [  $? -eq 0 ]

echo -e "\n\n80端口已被占用\n请修改nginx端口"

$NGINX_PATH/sbin/nginx 

echo -e "\n\nnginx已启动\n监听端口为80"

    echo -e "nginx安装路径为$NGINX_PATH"

cd $LOCATION

mv nginx-1.10.0.tar.gz  nginx-1.10.0  /opt/tools   &>  /dev/null