推荐
一键安装mysql8.0(Rocky Linux 9/CentOS Stream 9)(shell)
一键安装mongodb_4.2(Rocky Linux 9/CentOS Stream 9)(shell)
一键安装redis6.0(Rocky Linux 9/CentOS Stream 9)(shell)
CentOS 7.9服务器,一分钟部署完mysql8.0
一分钟部署完Prometheus+alertmanager+grafana
一小时带你学习完zabbix监控,生产全套详细学习教程
一/下载安装包
官网:https://nginx.org/en/download.html
下载:https://www.bing.com/search?form=MOZLBR&pc=MOZI&q=nginx-1.19.6.tar.gz
二/编写脚本
cat nginx_1_19_6_install.sh
#!/bin/bash
# -------------------------------------------------------------------------------
# Filename: 安装nginx_1_19_6
# Revision: 1.2.15
# Author
# Description: 解压安装
# Notes: Rocky Linux 9/CentOS Stream 9
# --------------------------------------------------------------------------------
nginx_1_19_6_install(){
local nginx_process=`find / -name "nginx" |wc -l`
if ! type nginx >/dev/null 2>&1 ;then
if [ $nginx_process -ge 2 ];then
echo "请nginx完全删除,再安装。"
echo -e "\n"
else
tar -zxvf nginx-1.19.6.tar.gz
mv nginx-1.19.6 nginx
yum -y install pcre-devel zlib zlib-devel openssl openssl-devel
cd $lj/nginx/
./configure --prefix=/data/nginx --pid-path=/data/nginx/nginx.pid --lock-path=/data/nginx/nginx.lock --error-log-path=/data/nginx/log/error.log --http-log-path=/data/nginx/log/access.log --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-http_gzip_static_module --with-stream_ssl_module --with-stream
cd $lj/nginx/objs
#echo "请输入Y/y"
sed -i '1,5 s/\-Werror/ /g' `grep -rl '\-Werror' Makefile`
#sed '1,5 s/-Werror//' Makefile > temp.txt && mv temp.txt Makefile
cd $lj/nginx/
make && make install
cd /data/nginx/conf/
cp nginx.conf nginx.conf_bak
/data/nginx/sbin/nginx
/data/nginx/sbin/nginx -s reload
ps -ef|grep nginx
cat > /etc/systemd/system/nginx.service << EOF
[Unit]
Description=Nginx HTTP Server
After=network.target
[Service]
Type=forking
PIDFile=/data/nginx/nginx.pid
ExecStartPre=/data/nginx/sbin/nginx -t -c /data/nginx/conf/nginx.conf
ExecStart=/data/nginx/sbin/nginx -c /data/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
EOF
chmod 644 /etc/systemd/system/nginx.service
systemctl restart nginx.service
local port_nginx=`netstat -tlnup |grep 'nginx'|wc -l`
if [ $port_nginx -ge 1 ];then
curl 127.0.0.1
echo "nginx启动成功。"
else
echo "nginx启动失败,请查找原因(yum安装pcre-devel zlib zlib-devel openssl openssl-devel是否成功)。"
fi
fi
else
echo "nginx已经安装了,如果需要重装请先把原来nginx卸载,再安装"
fi
main
}
nginx_1_19_6_install
#systemctl restart nginx.service && systemctl stop nginx.service