#!/bin/bash
#Nginx版本
NGINX_V=1.20.0
#Nginx下载目录
TMP_DIR=/tmp
#Nginx安装目录
INSTALL_DIR=/usr/local

function install_nginx() {
#下载依赖
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel
#下载Nginx
cd ${TMP_DIR}
yum install -y wget && wget -c wget http://nginx.org/download/nginx-${NGINX_V}.tar.gz
#解压源码
tar -zxvf ${TMP_DIR}/nginx-${NGINX_V}.tar.gz
mv nginx-${NGINX_V} nginx;cd nginx;
#预编译配置
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
sleep 2s
#编译安装
make && make install
#以服务启动
cd /usr/lib/systemd/system;
cat > nginx.service <<EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
EOF
systemctl restart firewalld;firewall-cmd --reload;
systemctl start nginx;systemctl enable nginx;
systemctl status nginx.service;
}
install_nginx
03-05 23:51