shell腳本自動安裝nginx


寫一腳本,實現對nginx的自動化下載,安裝,啟動,停止

 

#!/bin/sh

###nginx install shell

SOFT_PATH=/data/soft
NGINX_FILE=nginx-1.14.2.tar.gz
DOWN_PATH=http://nginx.org/download/

if [ $# -ne 1 ];then

echo "USAAGE:$0{download or start or install or stop}"

exit 0

fi

if [ $UID -ne 0 ];then
echo this script must use administrator or root user.please exit!
sleep 2
exit 1
fi

if [ ! -d $SOFT_PATH ];then
mkdir -p $SOFT_PATH
mkdir -p /application/nginx1.14.2
fi

download()
{
cd $SOFT_PATH;wget $DOWN_PATH/$SOFT_FILE
}

install()
{
yum install -y pcre pcre-devel openssl openssl-devel
cd $SOFT_PATH;tar xf $NGINX_FILE;cd nginx-1.14.2/ && ./configure --with-http_stub_status_module --with-http_ssl_module --prefix=/application/nginx1.14.2
[ $? -eq 0 ] && make && make install
ln -s /application/nginx1.14.2/ /application/nginx
}

start()
{
`netstat -lntp|grep 80`[ $? -ne 0 ] && /application/nginx/sbin/nginx
}

stop()
{
ps -ef|grep nginx|grep -v grep|awk '{print $2}'|xargs kill -9
}

case $1 in
download)
download
;;

install)

install

;;

start)
start
;;
stop)
stop
;;
*)
echo "USAAGE:$0{download or start or install or stop}"
exit
esac


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM