nginx编译安装脚本-亲测可用

环境:centos7.9的系统

网络:外网通,需使用wget下载包

其他:无

直接上脚本:

#!/bin/bash
#function:nginx
#author:tommypeng 20220714 final version
##########################################
 if
  [  "$USER"  != "root"   ]
then
   echo "错误:非root用户,权限不足!"
  exit  0
fi
###############防火墙及SElinux############
systemctl stop firewalld && systemctl disable firewalld  && echo "防火墙已经关闭"
sed -i 's/SELINUX=.*/SELINUX=disabled/g'  /etc/selinux/config  && echo "关闭selinux"
###############网络############
ping -c 3   www.baidu.com
if
   [ $? -eq 0 ]
   then
   echo -e "\n\033[32m-----------------------------------------------\033[0m"
                	echo -e "\033[32m网络畅通,即将安装依赖包\033[0m"
   else 
     echo -e "\n\033[32m-----------------------------------------------\033[0m"
                	echo -e "\033[32m即将退出,请检查外网通讯 !\033[0m"
        exit  0
fi
#######################依赖包###################
yum -y install  gcc gcc-c++ autoconf automake libtool make openssl openssl-devel pcre pcre-devel  wget
#############下载安装包##############
cd  /usr/local/src/    &&   wget  http://nginx.org/download/nginx-1.8.1.tar.gz 
if
   [ $? -eq 0 ]
   then
   echo -e "\n\033[32m-----------------------------------------------\033[0m"
                	echo -e "\033[32m安装包已经下载成功\033[0m"
   else 
     echo -e "\n\033[32m-----------------------------------------------\033[0m"
                	echo -e "\033[32m哟吼,滚犊子的下载失败了,即将退出 !\033[0m"
        exit  0
fi
###############编译及安装#############
    cd  /usr/local/src/  &&  	tar -zxvf nginx-1.8.1.tar.gz
if [ $? -eq 0 ];then
cd  /usr/local/src/nginx-1.8.1
./configure \
--prefix=/usr/local/nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre
make  && make install
             if  [ $? -eq 0 ];then
                	echo -e "\n\033[32m-----------------------------------------------\033[0m"
                	echo -e "\033[32m nginx编译安装成功 !\033[0m"
        	 else
                	echo -e "\033[32m nginx编译安装失败,请检查! \033[0m"
                	exit 1
        	 fi
	fi
echo "
常用命令:
# 进入生成目录
cd  /usr/local/nginx
# 测试
/usr/local/nginx/sbin/nginx -t
# 查看编译模块信息
/usr/local/nginx/sbin/nginx -V
# 启动
/usr/local/nginx/sbin/nginx
# 重新载入配置文件
/usr/local/nginx/sbin/nginx  -s reload
# 重启
/usr/local/nginx/sbin/nginx  -s reopen
# 停止
/usr/local/nginx/sbin/nginx  -s stop  "

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

IT大白鼠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值