共计 1130 个字符,预计需要花费 3 分钟才能阅读完成。
#!/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;
}
正文完