环境: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 "