天天看點

Nginx自動安裝腳本

如下腳本為nginx自動安裝腳本,僅供參考,可以根據實際情況修改,這裡使用case方式,真實環境安裝可以去掉case這種模式,全自動安裝。

#!/bin/sh

###nginx install shell

###wugk 2012-12-12

###define path  定義變量

soft_path=/data/soft/

nginx_file=nginx-1.2.4.tar.gz

down_path=http://nginx.org/download/

#define dir and mkdir soft dir  建立軟體目錄

if

   [ ! -d $soft_path ];then

   mkdir -p $soft_path

fi

#define download function  定義download函數

download ()

{

   cd $soft_path ;wget $down_path/$nginx_file

}

#define install function   定義install函數

install ()

   yum install pcre-devel -y

   cd $soft_path ;tar xzf $nginx_file  

   cd nginx-1.2.4/ &&./configure --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module

   [ $? -eq 0 ]&&make &&make install

#start nginx server define start function 定義start函數

start ()

   lsof -i :80

  [ $? -ne 0 ]&&/usr/local/nginx/sbin/nginx

#stop nginx server define stop function   定義stop函數

stop ()

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

#config case menu install  配置case 安裝菜單

case  $1  in

   download )

   download

;;

   install )

   install

   start )

   start

   stop )

   stop

     * )

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

   exit $?

esac

繼續閱讀