nginx安装脚本

#!/bin/bash

#********************************************************************
#********************************************************************
clear
echo “Preparations before installation…”
##variabled
NGINX_VERSION=“nginx-1.16.0”
NGINX_INSTALL_DOC="/usr/local/nginx"
NGINX_USER=“nginx”
NGINX_GROUP=“nginx”
NGINX_CONFIGURE="–prefix= N G I N X I N S T A L L D O C − − u s e r = {NGINX_INSTALL_DOC} --user= NGINXINSTALLDOCuser={NGINX_USER} --group=${NGINX_GROUP} --with-http_ssl_module --with-http_stub_status_module"

##function
nginx_check(){

1、监测当前用户 要求为root

if [ “$USER” != ‘root’ ];then
echo “need to be root so that”
exit 5
fi

2、检查wget命令

WGET_CHECK=$(rpm -q wget)
if [ $? -ne 0 ];then
yum -y install wget &> /dev/null
fi
}

nginx_install_pre(){

1、安装依赖

if ! (yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel openssl openssl-devel elinks 1>/dev/null);then
echo “ERROR:YUM install error”
exit 5
fi

2、下载nginx源码包

if (wget http://nginx.org/download/${NGINX_VERSION}.tar.gz &>/dev/null);then
tar zxf ${NGINX_VERSION}.tar.gz
if [ ! -d ${NGINX_VERSION} ];then
echo “ERROR:not found ${NGINX_VERSION}”;exit 5
fi
else
echo “ERROR:wget download file ${NGINX_VERSION}.tar.gz fail”
fi
}

nginx_install_make(){
(groupadd ${NGINX_GROUP} ;useradd -s /sbin/nologin -r -M -g ${NGINX_GROUP} ${NGINX_USER}) &>/dev/null
cd ${NGINX_VERSION}
echo “nginx configure…”
if ./configure ${NGINX_CONFIGURE} 1>/dev/null;then
echo “nginx make …”
if make 1>/dev/null;then
echo “nginx make install …”
if make install 1>/dev/null;then
echo “nginx install success”
else
echo “ERROR: nginx install tail!”;exit 5
fi
else
echo “ERROR: nginx make tail!”;exit 5
fi
else
echo"ERROR: nginx configure tail!";exit 5
fi
}

配置nginx开机自启,使用systemctl 管理nginx服务

nginx_enable(){
cat > /usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart= N G I N X I N S T A L L D O C / s b i n / n g i n x E x e c R e l o a d = {NGINX_INSTALL_DOC}/sbin/nginx ExecReload= NGINXINSTALLDOC/sbin/nginxExecReload={NGINX_INSTALL_DOC}/sbin/nginx -s reload
ExecStop=${NGINX_INSTALL_DOC}/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
systemctl enable nginx.service 1>/dev/null
}

nginx_start(){
TEMP_NGINX= ( m k t e m p n g i n x . X X X ) i f s y s t e m c t l s t a r t n g i n x . s e r v i c e ; t h e n e c h o " n g i n x s t a r t S U C C E S S ! " c l e a r e l i n k s h t t p : / / l o c a l h o s t − d u m p > (mktemp nginx.XXX) if systemctl start nginx.service;then echo "nginx start SUCCESS!" clear elinks http://localhost -dump > (mktempnginx.XXX)ifsystemctlstartnginx.service;thenecho"nginxstartSUCCESS!"clearelinkshttp://localhostdump>{TEMP_NGINX}
head -n +11 ${TEMP_NGINX}
rm -f ${TEMP_NGINX}
echo -e “\e[1;36m Manager Nginx:\e[0m \e[0;32m systemctl start|stop|status|restart| nginx.service \e[0m”
else
echo “nginx stop FAIL”
fi

}

nginx_check
nginx_install_pre
nginx_install_make
nginx_enable
nginx_start

[root@50 ~]# chmod +x nginx_install.sh
[root@50 ~]# ./nginx_install.sh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值