nginx编译安装的shell脚本

#!/usr/bin/bash
#date 2020-04-09
nginx_package=nginx-1.16.0.tar.gz
nginx_version=nginx-1.16.0
//以下是关闭firewall、selinux
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld &> /dev/null
if [ $? -ne 0 ];then
        echo "防火墙已关闭"
fi
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
check_selinux=`getenforce`
if [[ $check_selinux -eq Permissive || $check_selinux -eq Disabled ]];then
        echo "selinux已关闭"
fi
//以下是检查网络
echo -e "\033[5;33m==========  开始检查网络 =========== \033[0m"
check_net_status()
{
    ping -c1 -w1 www.baidu.com &>/dev/null
    if [ $? -eq 0 ];then
        echo "网络正常"
    else
        echo -e "\033[31m 网络异常,请检查! \033[0m"
        exit 1
    fi
}
check_net_status
//以下是检查yun源
# 检查yum
echo -e "\033[5;33m==========  开始检查yum源 =========== \033[0m"
check_yum_status()
{
    # 检查yum是否正常
    yum clean all
    yum makecache fast
    if [ $? -eq 0 ];then
        echo "yum正常"
    else
        echo -e "\033[31m yum异常,请手动检查! \033[0m"
        exit 2
    fi
}
check_yum_status
//以下是安装常用工具
read -p "是否安装常用工具(y|n):" num
case $num in
y|Y)
        yum install -y lrzsz  sysstat  elinks wget net-tools bash-completion vim  //lrzsz是真机与虚拟机上传下载文件的安装包,bash-completion是自动补全的安装包
        echo "安装完成"
;;
n|N)
        break
;;
*)
        echo "请输入正确选项"
        exit
;;
esac
//以下是正式进行编译安装的命令
yum -y install gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel gd gd-devel //此处是安装编译环境
if [ $? -ne 0 ];then
	echo "编译环境安装失败"
fi
useradd -s /sbin/nologin nginx
wget http://nginx.org/download/$nginx_package	
tar -zxvf $nginx_package -C /usr/local/
cd /usr/local/$nginx_version && ./configure --prefix=/usr/local/nginx --group=nginx --user=nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --lock-path=/var/lock/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-pcre --with-http_realip_module --with-stream   //编译配置
if [ $? -ne 0 ];then
	echo "编译配置失败"
	exit
fi
cd /usr/local/$nginx_version && make && make install  //编译安装
if [ $? -ne 0 ];then
	echo "编译安装失败"
	exit
fi
mkdir /tmp/nginx/
/usr/local/nginx/sbin/nginx
if [ $? -eq 0 ];then
	echo "nginx启动成功"
else
	echo "nginx启动失败"
fi

以上是编译安装的脚本

你可能感兴趣的:(nginx编译安装的shell脚本)