#!/usr/bin/bash
#Description: Nginx install script from Marc
#Author: Marc
#Created Time: 2021/02/07 12:00
#安装用户 root
#安装前准备 依赖包 源码获取
#安装
#启动 测试
#定义变量 variables
nginx_pkg="nginx-1.18.0.tar.gz"
#这里自定义安装版本
nginx_source_dir=`echo $nginx_pkg |cut -d "." -f1-3`
nginx_install_dir="/usr/local/nginx"
nginx_usr="www"
nginx_group="www"
check() {
if [ "$USER"!='root' ];then
#env |grep USER |awk -F'=' '{ print $2 }'
#不知道为什么我电脑 USER 不出 root
echo "Need to be root user"
exit 1
fi
#检测 wget 命令
if [ ! -X /usr/bin/wget ];then
echo "Not found command /usr/bin/wget"
exit 1
fi
# [ ! -x /usr/bin/wget ]&&echo "Not found command /usr/bin/wget" &&exit 1
}
install_pre() {
#安装依赖
#yum -y install gcc-* pcre-devel zlib-devel make 1>/dev/null
if !(yum -y install gcc-* pcre-devel zlib-devel 1>/dev/null);then
echo "ERROR: yum install error"
exit 1
fi
#下载源码包
if wget http://nginx.org/download/$nginx_pkg 1>/dev/null;then
tar xf $nginx_pkg
if [ ! -d $nginx_install_dir ];then
ehco "ERRO:not found nginx-1.18.0"
exit 1
else
cd $nginx_install_dir
fi
else
echo "Error : wget file nginx-1.18.0 failed"
fi
}
install(){
#创建管理用户
useradd -r -s /sbin/nologin www
echo "Nginx configure..."
if ./configure --prefix=$nginx_install_dir &>/dev/null;then
echo "nginx make..."
if make 1>/dev/null;then
echo "make install "
if make install &>/dev/null;then
echo "Nginx install success"
else
echo "Error :make install failed";exit 1
fi
else
echo "Error :make fail";exit 1
fi
else
echo "Error :configure fail";exit 1
fi
}
nginx_test(){
if $nginx_install_dir/sbin/nginx;then
echo "nginx start success"
else
echo "Nginx start failed"
fi
}
#调用函数
check
install_pre
install
nginx_test