編譯安裝nginx 1 16

2021-10-23 23:25:18 字數 3717 閱讀 8929

#!/usr/bin/bash

#編譯安裝nginx,個人使用,不能用於生產,用於生產概不負責

#劉彬彬

#有事聯絡此郵箱[email protected]

echo

"此指令碼用於一鍵編譯安裝nginx僅限個人使用,不想安裝請在10秒內,ctrl+c停止"

sleep 10

wt()

#編譯配置,需要什麼新增什麼,這裡所有的配置已經指定目錄

configure(

)systemctl disable firewalld if[

[$? -ne 0 ]];

then

echo

"關閉失敗"

exit

else

echo

"防火牆已經關閉"

figet=if[

[$get

= disabled ||

$get

= permissive ]];

then

echo

"關閉失敗"

exit

else

echo

"selinux已經關閉"

"網路不通,請手動檢查網路"

exit

else

echo

"網路通暢,可以安裝軟體"

fiyum -y install gcc gcc-c++ if[

[$? -ne 0 ]];

then

echo

"編譯環境安裝失敗"

exit

else

echo

"編譯環境安裝成功"

fiyum install -y pcre pcre-devel

#使nginx支援http rewrite模組if[

[$? -ne 0 ]];

then

echo

"安裝失敗"

exit

else

echo

"安裝pcre成功"

fiyum install -y openssl openssl-devel

#使nginx支援sslif[

[$? -ne 0 ]];

then

echo

"安裝失敗"

exit

else

echo

"安裝openssl-devel成功"

fiyum install -y zlib zlib-devel gd gd-devel if[

[$? -ne 0 ]];

then

echo

"安裝失敗"

exit

else

echo

"安裝zlib成功"

fiuseradd -s /sbin/nologin nginx

#使建立的nginx使用者沒有登入的許可權,為了安全if[

[$? -ne 0 ]];

then

echo

"建立使用者失敗"

break

else

echo

"建立使用者成功"

fiwt if[

[$? -ne 0 ]];

then

echo

else

echo

ficd /usr/local/src/

#解壓tar -zxvf nginx-1.16.0.tar.gz

echo

"配置檔案,指定目錄,如果不想指定目錄請ctrl+c退出指令碼"

sleep 5

configure &

>/etc/null #上面有函式,在開頭if[

[$? -ne 0 ]];

then

echo

"配置失敗"

exit

else

echo

"配置成功"

fiecho

"開始安裝"

sleep 3

make

&>/dev/null &&

make

installif[

[$? -ne 0 ]];

then

echo

"安裝失敗"

exit

else

echo

"安裝成功"

fiecho

"啟動服務"

sleep 3

cd /usr/local/nginx/sbin

./nginx

netstat -ntlp |

grep nginx if[

[$? -ne 0 ]];

then

echo

"啟動失敗"

exit

else

echo

"nginx啟動成功,可以使用了"

ficd /usr/local/nginx/sbin

./nginx -s stop

#把nginx新增system管理

cat>/usr/lib/systemd/system/nginx.service <<

eof[unit]

description=nginx - high performance web server

documentation=

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

execreload=/bin/kill -s hup \$mainpid

execstop=/bin/kill -s quit \$mainpid

privatetmp=true

[install]

wantedby=multi-user.target

eofecho

"新增許可權,執行權"

chmod +x /usr/lib/systemd/system/nginx.service

echo

"開機自啟配置中"

#實驗一下這幾項是否可以正常使用

systemctl daemon-reload

systemctl start nginx.service

systemctl stop nginx.service

systemctl reload nginx.service

systemctl restart nginx.service

systemctl enable nginx.serviceif[

[$? -ne 0 ]];

then

echo

"啟動失敗"

exit

else

echo

"啟動成功"

fi

MAC系統下重新編譯安裝nginx1 16 1

自昨晚公升級mac系統到catalina版後,原先安裝在 usr loca 目錄下的nginx服務目錄在公升級時丟失,只能再裝一次,這次安裝目錄選擇為 users mac service nginx目錄下。具體步驟為 當前穩定版本 zlib 當前穩定版本 tar zxvf zlib 1.2.11.t...

nginx編譯安裝

nginx版本 1.12.2 1.安裝依賴包 yum install y gcc gcc c zlib zlib devel openssl openssl devel pcre pcre devel 2.編譯和安裝nginx 執行如下命令 3.安裝完成啟動nginx。如果用指定使用者啟動nginx...

Nginx編譯安裝

ububtu apt get install build essential apt get install libtool centos yum y install gcc automake autoconf libtool make yum install gcc gcc c 1 pcre庫 a...