#!/bin/bash
#关闭防火墙和安全机制
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i '7d' /etc/selinux/config
sed -i '7i SELINUX=disabled' /etc/selinux/config
rm -f /var/run/yum.pid
#创建用户组
useradd -M -s /sbin/nologin nginx
#安装依赖软件
yum install -y wget gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel gd gd-devel
echo -e "\033[32m 依赖软件安装完成 \033[0m"
#下载 nginx 安装包
cd /usr/local/src
if [ ! -f "/usr/local/src/nginx-1.14.2.tar.gz" ];
then
wget 'http://nginx.org/download/nginx-1.14.2.tar.gz'
else
echo -e "\033[32m Nginx 安装包已下载 \033[0m"
fi
# 解压安装包
tar -zxvf nginx-1.14.2.tar.gz
cd nginx-1.14.2
#编译安装
./configure --prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--without-http_access_module \
--without-http_auth_basic_module \
--with-http_stub_status_module \
--with-debug \
--without-http_gzip_module \
--with-http_ssl_module \
--without-http_rewrite_module \
--without-http_referer_module \
--without-http_upstream_hash_module \
--without-http_access_module \
--without-stream_return_module \
--with-http_image_filter_module \
--with-http_image_filter_module=dynamic \
--with-http_gzip_static_module
make
make install
sleep 10
if
[ $? = 0 ];
then echo -e "\033[32m Nginx编译完成 \033[0m"
else echo -e "\033[41;33m Nginx编译失败 \033[0m"
exit 2
fi
#添加环境变量
echo 'export PATH=$PATH:/usr/local/nginx/sbin/' >> /etc/profile
# 使用 systemctl 管理 nginx
cat >/usr/lib/systemd/system/nginx.service <<EOF
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
[Install]
WantedBy=multi-user.target
EOF
source /etc/profile
systemctl daemon-reload
systemctl restart nginx
reset (){
read -p "请输入 y 或 n: " T
case $T in
y)
bash ./nginx_install.sh
;;
n)
echo 123
exit
;;
*)
echo "请输入 y 或 n"
reset
;;
esac
}
ss=`systemctl status nginx | awk 'NR==3 {print $3}' | sed 's/[()]//g'`
if [ $ss == running ];
then
systemctl status nginx
echo -e "\033[32m Nginx启动成功 \033[0m"
printf "%-60s\n" "*********************************************************"
printf "%-60s\n" "* 部署完成 *"
printf "%-60s\n" "* 安装目录:/usr/local/nginx/ *"
printf "%-60s\n" "*********************************************************"
exit 0
else
systemctl status nginx
echo " "
echo -e "\033[41;33m Nginx启动失败,是否执行重装 \033[0m"
echo " "
reset
sleep 10
fi
Nginx 1.14.2 编译安装脚本
于 2023-06-20 22:11:55 首次发布