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

扫描二维码关注公众号,回复: 5056961 查看本文章

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

猜你喜欢

转载自www.cnblogs.com/liuhui-xzz/p/10317586.html