使用環境:redhat/centos 7系,可復制粘貼使用,此腳本是在外網環境下使用
如無外網需下載nginx原始碼包、gcc、pcre-devel、zlib-devel、openssl-devel等安裝包,
此腳本也同樣適用于國產麒麟v10系統,只是需要將nginx-1.14.0/src/os/unix/ngx_user.c檔案26行注釋掉,即可安裝,

#!/bin/bash
#Author:hejing
#Date:2021-7-21
#Description:一鍵原始碼安裝nginx
#定義不同顏色屬性
setcolor_failure="echo -en \\033[91m" #echo選項 -n 回顯資料后不按回車即可換行;-e轉義
setcolor_success="echo -ne \\033[32m"
setcolor_normal="echo -e \\033[0m"
#判斷是否以管理員方式執行腳本
if [[ $UID -ne 0 ]];then
$setcolor_failure
echo -n "請以管理員身份運行該腳本."
$setcolor_normal
exit
fi
#判斷系統中是否存在wget下載工具
#wget使用-c選項可以開啟斷點續傳功能
if rpm --quiet -q wget;then
wget -c http://nginx.org/download/nginx-1.14.0.tar.gz
else
$setcolor_failure
echo -n "未找到wget,請先安裝該軟體."
$setcolot_normal
exit
fi
#如果沒有nginx賬戶,則該腳本自動創建該賬戶
if ! id nginx &>/dev/null;then
adduser -s /sbin/nologin nginx
fi
#測驗是否存在正確的原始碼包軟體
#在原始碼安裝前,先安裝相關依賴包
#gcc:C語言編輯器,pcre-devel:Perl兼容的正則運算式庫
#zlib-devel:gzip壓縮庫,openssl-devel:Openssl加密庫
if [[ ! -f nginx-1.14.0.tar.gz ]];then
$setcolor_failure
echo -n "未找到nginx原始碼包,請先正確下載該軟體..."
$setcolor_normal
exit
else
yum -y install gcc pcre-devel zlib-devel openssl-devel
clear
$setcolor_success
echo -n "接下來,需要花費幾分鐘的時間編譯原始碼安裝..."
$setcolor_normal
sleep 6
tar -xf nginx-1.14.0.tar.gz
#編譯原始碼安裝nginx,指定賬戶和組,指定安裝路徑,開啟需要的模塊,禁用不需要的模塊
cd nginx-1.14.0/
./configure \
--user=nginx \
--group=nginx \
--prefix=/data/server/nginx \
--with-stream \
--with-http_ssl_module \
--with-http_stub_status_module \
--without-http_autoindex_module \
--without-http_ssi_module
make
make install
fi
if [[ -x /data/server/nginx/sbin/nginx ]];then
clear
$setcolor_success
echo -n "一鍵部署nginx已經完成!"
$setcolor_normal
fi
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/289542.html
標籤:其他
上一篇:UniApp+Vue實作直播功能
