推薦
一鍵安裝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