头图
cat > /tmp/nginx.sh << "EOF"
#!/bin/bash
#Nginx版本
NGINX_V=1.20.0
function install_nginx(){
#下载依赖
yum -y install gcc gcc-c++ make automake pcre pcre-devel zlib zlib-devel openssl openssl-devel
#下载Nginx
yum install -y wget && wget -P /tmp http://nginx.org/download/nginx-${NGINX_V}.tar.gz
#解压源码
tar -zxvf /tmp/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
#以服务启动
echo "
[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
Restart=on-failure
PrivateTmp=true

[Install]
WantedBy=multi-user.target
" > /usr/lib/systemd/system/nginx.service
systemctl restart firewalld;firewall-cmd --reload;
systemctl start nginx;systemctl enable nginx;
systemctl status nginx.service;
}
install_nginx
EOF
chmod +x /tmp/nginx.sh && /tmp/nginx.sh start

KentBryce
29 声望1 粉丝