#!/bin/sh
###nginx install shell
SOFT_PATH=/opt/nginx/ #设定安装路径
NGINX_FILE=nginx-1.2.0.tar.gz #设定安装的源文件,这里没有选择rpm就是因为好操作
DOWN_PATH=http://nginx.org/download/ #设定网页
if [ $UID -ne 0 ];then #判断是否是root用户
echo This script must use administrator or root user ,please exit!
sleep 2
exit 0
fi
if [ ! -d $SOFT_PATH ];then #如果安装路径不存在就mkdir一个
mkdir -p $SOFT_PATH
fi
download () #下载
{
cd $SOFT_PATH ;wget $DOWN_PATH/$NGINX_FILE
}
install () #安装
{
yum install pcre-devel -y
cd $SOFT_PATH ;tar xzf $NGINX_FILE ;cd nginx-1.2.0/ &&./configure --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module
[ $? -eq 0 ]&&make &&make install
}
start () #显示所有打开80端口的进程
{
/usr/local/nginx/sbin/nginx
}
stop ()
{
ps -ef |grep nginx |grep -v grep |awk '{print $2}' |xargs kill -9
}
exit ()
{
echo $? ;exit
}
###case menu #####
case $1 in
download )
download
;;
install )
install
;;
start )
start
;;
stop )
stop
;;
* )
echo “USAGE:$0 {download or install or start or stop}”
exit
esac