shell脚本自动安装nginx
Posted 绿小肥
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
以上是关于shell脚本自动安装nginx的主要内容,如果未能解决你的问题,请参考以下文章