nginx自動化安裝指令碼

2021-09-20 21:55:17 字數 2095 閱讀 1526

自動化安裝指令碼,需要root使用者執行

#!/bin/sh

. /etc/init.d/functions

#nginx使用者資訊

nginxuser=nginx

nginxversion=1.15.12

dirsoft=/usr/local/src

#安裝目錄

yum install wget -y

#安裝環境

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 prce-devlel" /bin/false

exit 1

fiyum install zlib zlib-devel -y

if [ $? -ne 0 ];then

action "install zlib zlib-devel" /bin/false

exit 1

fiyum install openssl openssl-devel -y

if [ $? -ne 0 ];then

action "install openssl openssl-devel" /bin/false

exit 1

fi#建立使用者:判定使用者和組是否存在,不存在則建立使用者和組

id $nginxuser >& /dev/null

if [ $? -ne 0 ];then

useradd $nginxuser -s /sbin/nogin -m

fiif [ ! -d $dirsoft ];then

mkdir $dirsoft -p

if [ $? -ne 0 ];then

action "mkdir $dirsoft -p" /bin/false

exit 1

fificd $dirsoft

wget

if [ $? -ne 0 ];then

action "wget nginx-$" /bin/false

exit 1

fi#解壓檔案

tar -zxf nginx-$.tar.gz

cd nginx-$

if [ $? -ne 0 ];then

action "cd nginx-$" /bin/false

exit 1

fi

#判斷安裝目錄是否存在

if [ ! -d $dirinstall ];then

mkdir $dirinstall -p

fi#編譯ngixn

#判斷是否編譯成功

if [ $? -ne 0 ];then

action "configure nginx" /bin/false

exit 1

fi#安裝

make && make install

if [ $? -ne 0 ];then

action "make && make install" /bin/false

exit 1

fi#軟鏈結

ln -s $dirinstall/nginx-$nginxversion $dirinstall/nginx

#啟動nginx

$dirinstall/nginx/sbin/nginx

#判斷是否啟動成功

cnginx=$(ps -c nginx --no-heading|wc -l)

if [ $cnginx -nq 0 ];then

action "intsall nginx" /bin/false

exit 1

fi#加入開機啟動

echo $/nginx/sbin/nginx >>/etc/rc.local

#輸出安裝成功提示

action "intsall nginx" /bin/true

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自動化安裝指令碼

nginx安裝之前需要的一些步驟 系統引數調整 vi etc sysctl.conf,在末尾新增 net.ipv4.tcp keepalive intvl 15 net.ipv4.tcp keepalive probes 3 net.ipv4.tcp keepalive time 1800 net....

指令碼自動化安裝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...