Nginx是当下最流行的WEB服务器,但nginx的安装是源码包安装并且需要安装一些库文件以保证程序正确运行。该脚本还支持Nginc平滑升级。
源码包:nginx-1.7.10.tar.gz nginx-1.8.0.tar.gz
#!bin/bash
#检查YUM库是否正常
yum clean all >/dev/null
yum repolist &>/tmp/yum.tmp
NUM=`tail -1 /tmp/yum.tmp | awk '{;print $NF}' | sed 's/,//' `
if [ $NUM -eq 0 ];then
yum repolist >/tmp/Install.log
echo "Yum is ERROR , you can read /tmp/Install.log"
exit 0
else
echo "Yum is OK!"
rm -rf /tmp/Install.log
fi
#安装nginx所需的开发环境
yum -y install gcc pcre-devel openssl-devel &>/dev/null
#配置安装路径和安装配置
CONF="./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module"
#检查80端口是否被占用
check-port80(){
LISTEN=`netstat -anptu | grep 80 | awk '{print $6}'`
if [ "$LISTN" == "LISTEN" ];then
echo "80端口被占用,请关闭80端口"
exit 1
elif [ -f "/usr/local/nginx/sbin/nginx" ];then
echo "nginx 已存在"
exit 2
fi
}
#nginx安装函数
nginx-install(){
check-port80
$CONF >Install.log
make &>/dev/null
make install &>/dev/null
echo "安装完成!"
}
#nginx升级函数
nginx-upgrade(){
$CONF >Upgrade.log
make &>/dev/null
mv /usr/local/nginx/sbin/nginx{,old}
cd objs/
cp nginx /usr/local/nginx/sbin/
make upgrade >>Upgrade.log
nginx -v
echo "升级完成!"
}
#创建nginx用户和安装目录
useradd -s /sbin/nologin nginx &>/dev/null
mkdir /usr/local/nginx &>/dev/null
#配置安装选项 -i 安装; -u 升级;
case $1 in
-i)
tar -xf nginx-1.7.10.tar.gz
cd nginx-1.7.10
nginx-install
ln -s /usr/local/nginx/sbin/nginx /usr/sbin
exit 4
;;
-u)
tar -xf nginx-1.8.0.tar.gz
cd nginx-1.8.0
nginx-upgrade
exit 5
;;
*)
echo "Input -i Install;-u upgrade"
esac
转载于:https://blog.51cto.com/ltmwcc/1773388