Shell script one-click deployment-source code compilation and installation of Nginx website service

This script is suitable for environments where local yum sources or online sources have been built
Toolkit download link: nginx-1.12.0.tar.gz Before
use, drag the toolkit to the /opt directory to
write a script file, copy the following content into it, use source or. To execute the script

#!/bin/bash

echo "---正在关闭防火墙及安全机制---"
   systemctl stop firewalld
   systemctl disable firewalld >> /dev/null
   setenforce 0 
echo "---正在挂载镜像---"
   mount /dev/cdrom /mnt &> /dev/null
echo "---正在安装依赖包---"
   yum -y install pcre-devel zlib-devel gcc gcc-c++ make >> /dev/null
echo "---创建运行用户---"
   useradd -M -s /bin/nologin nginx
echo "---编译安装---"
   cd /opt
   tar zxvf nginx-1.12.0.tar.gz -C /opt >> /dev/null

cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-http_stub_status_module >> /dev/null

 make >> /dev/null 
 make install >> /dev/null
echo "---正在优化路径---"
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx >> /dev/null
echo "---添加 Nginx 系统服务---"
echo "[Unit]
Description=nginx
After=network.target
[Service]
Type=forkin
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecrReload=/bin/kill -s HUP $MAINPID
ExecrStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[install]
WantedBy=multi-user.target" > /lib/systemd/system/nginx.service

chmod 754 /lib/systemd/system/nginx.service
echo "---启动 Nginx 服务---"
systemctl start nginx.service
systemctl enable nginx.service

Guess you like

Origin blog.csdn.net/weixin_51613313/article/details/113643809