nginx 一键安装

#!/bin/bash

#This was create by steven

#creat time 2017/04/06

#定义nginx软件安装所需要的软件包函数

nginx_dependency_install(){

echo "Wait a moment it need some time to install these software"

/usr/bin/yum install pcre pcre-devel openssl openssl-devel gcc gcc+ make -y &>/tmp/nginx_yum.log #通过yum安装依赖软件包

if [ $? -eq 0 ];then

echo "Nginx dependency package install succeed"

else

echo "Nginx dependency package install failed"

exit

fi

}

#定义安装路径变量

variable(){

v="1.10.2" #nginx version

p="/application/nginx-$v" #nginx install directory

}

#定义安装nginx的路径以及创建nginx用户

create_directory(){

variable

useradd nginx -s /sbin/nologin -M >>/tmp/nginx_yum.log#add service account

mkdir -p "$p" #create directory

cd /software/

tar xf nginx-$v.tar.gz

cd /software/nginx-$v&&

if [ $? -eq 0 ];then

echo "create directory succeed"

else

echo "create direcotry false"

fi

}

#编译安装nginx

make_install(){

echo "This install need about one minuts"

variable

cd /software/nginx-"$v"

if [ $? -eq 0 ];then

./configure --user=nginx --group=nginx --prefix=/application/nginx-"$v"/ --with-http_stub_status_module --with-http_ssl_module &>>/tmp/nginx_install.log

fi

if [ $? -eq 0 ];then

/usr/bin/make &>>/tmp/nginx_install.log

fi

if [ $? -eq 0 ];then

/usr/bin/make install &>>/tmp/nginx_install.log

fi

if [ $? -eq 0 ];then

echo "Nginx install succeed"

else

echo "Nginx install faild"

exit 1

fi

}

#定义测试nginx是否启动的变量

Testing(){

variable

$p/sbin/nginx

if [ $? -eq 0 ];then

echo "nginx start succeed"

else

echo "nginx start failed"

exit 0

fi

}

#执行上面所定义的变量

nginx_dependency_install

create_directory

make_install

Testing

原文地址:https://www.cnblogs.com/dianzixiaoming/p/6692589.html