nginx自動化安裝指令碼

2021-10-21 18:26:40 字數 4096 閱讀 5933

nginx安裝之前需要的一些步驟

系統引數調整

vi /etc/sysctl.conf,在末尾新增

net.ipv4.tcp_keepalive_intvl = 15

net.ipv4.tcp_keepalive_probes = 3

net.ipv4.tcp_keepalive_time = 1800

net.ipv4.tcp_tw_reuse = 1

net.ipv4.tcp_tw_recycle = 1

net.ipv4.tcp_fin_timeout = 30

sysctl -p 生效

修改openfile開啟最大數

編輯vi /etc/security/limits.conf檔案在末尾新增如下兩行(將開啟的檔案數修改為65535)

* soft nofile 65535

* hard nofile 65535

此項配置完成需要執行reboot來重啟伺服器,否則修改不生效。

可通過ulimit -a命令檢視是否生效

#!/bin/bash

#變數配置部分

#nginx安裝基於root使用者安裝 nginx基本庫

yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl--devel openssl openssl-devel-y

echo

-e "\033[32m########## yum install finish ##########\033[0m"

#nginx安裝檔名

nginx_tarname=/home/nginx/nginx-1.17.9.tar.gz

#解壓資料夾名稱

nginx_filename=nginx-1.17.9

#nginx安裝路徑

nginx_prefile=/home/nginx/nginx8000/

#安裝部分

#基礎執行庫安裝

#解壓nginx檔案

echo

$nginx_tarname

tar -xvzf $nginx_tarname

#源檔案目錄

cd $nginx_filename

#建立資料夾if[

!-d $nginx_prefile

];then

echo

-e "\033[32mthe directory is not exist.\033[0m"

#判斷備份檔案夾是否存在,不存在則建立

mkdir -p $nginx_prefile

else

echo

-e "\033[32mthe directory is exist.\033[0m"

fiecho

-e "\033[32m##########start install nginx ##########\033[0m"

#安裝 具體外掛程式可根據實際生產環境進行配置在此不一一枚舉

#編譯make

make install

#啟動cd $nginx_prefile

/sbin

./nginx

#程序檢視

ps-ef|grep nginx

echo

-e "\033[32m########## install nginx finish ##########\033[0m"

常用外掛程式引數

本模組提供flv檔案載入基於時間位移.

mp4外掛程式

ssl證書模組

gzip模組

完整配置

--prefix=/home/nginx/nginx --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --with-http_gzip_static_module --with-http_stub_status_module

自帶指令碼啟動

cd sbin #nginx的指令碼執行目錄

./nginx 啟動nginx

./nginx -s stop 停止nginx

./nginx -s quite 斷開停止nginx

./nginx -s reload 過載nginx配置檔案

#!/bin/sh

#nginx自定義啟動指令碼

if[ $(whoami)

!= "root"

]then

echo

"shell must be excuted by root!"

exit 1

ficd ~/nginx/sbin

echo

"******************************===="

ps-ef | grep nginx| grep .

/nginx | grep -v grep

processnum=$(

ps-ef | grep nginx| grep .

/nginx | grep -v grep | wc -l)if[

$processnum

-gt 0 ]

then

echo

"nginx is running"

exit 1fi.

/nginx

echo

"******************************===="

ps-ef | grep nginx| grep .

/nginx | grep -v grep

processnum=$(

ps-ef | grep nginx| grep .

/nginx | grep -v grep | wc -l)if[

$processnum

-eq 0 ]

then

echo

"*****===startup nginx fail!!!!!!!*************************"

else

echo

"*****===startup nginx success*************************"

fi

#!/bin/bash

if[ $(whoami)

!= "root"

]then

echo

"shell must be excuted by root!"

exit 1

ficd ~/nginx/sbin

./nginx -s stop

sleep 5

echo

"******************************===="

ps-ef | grep nginx| grep .

/nginx | grep -v grep

processnum=$(

ps-ef | grep nginx| grep .

/nginx | grep -v grep | wc -l)if[

$processnum

-gt 0 ]

then

ps-ef | grep nginx| grep .

/nginx | grep -v grep | cut -c 9-15 | xargs kill

-9fi

echo

"*****===stop nginx success*************************"

nginx自動化安裝指令碼

自動化安裝指令碼,需要root使用者執行 bin sh etc init.d functions nginx使用者資訊 nginxuser nginx nginxversion 1.15.12 dirsoft usr local src 安裝目錄 yum install wget y 安裝環境 yu...

nginx自動化安裝指令碼

安裝環境 yum install gcc c y 判斷是否安裝成功 if ne 0 then action install gcc bin false exit 1 fiyum install pcre pcre devel y if ne 0 then action install prce pr...

指令碼自動化安裝Nginx 1 9 9

建立autoinstallnginx.sh root plc001 mkdir scripts root plc001 cd scripts root plc001 scripts vi autoinstallnginx.sh bin bash author bin xiao date 2018 1...