shell腳本一鍵部署nginx

#!/bin/bash
systemctl stop firewalld && setenforce 0
#首先安裝nginx的依賴環境
yum -y install gcc pcre-devel zlib-devel net-tools wget
#解壓nginx的安裝包
if [ ! -d “/root/nginx-1.16.1” ]; then
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -zxf nginx-1.16.1.tar.gz
echo “壓縮包已解壓”
else
echo “此文件已存在”
continue
fi
#進去文件開始檢查環境 編譯安裝
if [ ! -d /usr/local/nginx ]; then
cd /root/nginx-1.16.1 && ./configure && make && make install
else
continue
fi
#判斷是否nginx的端口被佔用
pid_file="/usr/local/nginx/logs/nginx.pid"
if [ ! -e ${pid_file} ]; then
echo “被佔用的pid是:cat ${pid_file}
kill cat ${pid_file}
echo “服務被佔用,已刪掉”
else
echo “服務沒有被佔用”
continue
fi

nginx=/usr/local/nginx/sbin/nginx
#開始啓動nginx
read -p “請輸入你接下來要做的操作:” action
check(){
netstat -anptu | grep nginx
if [ $? -eq 0 ];then
continue
fi
}
case $action in
start)
netstat -anptu | grep nginx
if [ $? -eq 0 ]; then
continue
else
$nginx
fi
;;
stop)
netstat -anptu | grep nginx
if [ $? -eq 0 ]; then
echo “nginx-server is already running nginx-server begin stop”
$nginx -s stop
else
echo “nginx-server is not start”
fi
;;
reload)
netstat -anptu | grep nginx
if [ $? -eq 0 ]; then
echo “nginx-server is already running nginx-server begin reload”
$nginx -s reload
else
echo “nginx-server is not running now begin start nginx-server”
$nginx
$nginx -s reload
fi
;;
statue)
check
;;
*)
echo “please enter{start|stop|reload|statue}”
;;
esac
ip=/sbin/ifconfig -a|awk '{print $2}'|sed -n '2p'
code=curl -I -m 10 -o /dev/null -s -w %{http_code} http://${ip}
if [ $code -eq 200 ]; then
echo “nginx-server is ok”
else
echo “nginx-server is not ok”
fi

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章