shell脚本一键安装nginx
程序员文章站
2022-04-03 14:59:53
依赖包安装包放在一起, 直接执行这个脚本就行。 ......
依赖包安装包放在一起, 直接执行这个脚本就行。
#!/bin/bash
#------------------------------------------------------------------------------------------------------------------#
#------------------------------------------------------------------------------------------------------------------#
#| chenglee public nginx |#
#| version: nginx-1.9.10 |#
#| version: openssl-1.1.0f |#
#| version: pcre-8.40 |#
#| version: zlib-1.2.11 |#
#| 2018.12.04 |#
#------------------------------------------------------------------------------------------------------------------#
#| some people die at the age of 25 and don't bury themselves in the earth until they are 75 |#
#------------------------------------------------------------------------------------------------------------------#
#| $$$$ $$ $$ $$$$$$ $$ $$ $$$$$$ $$ $$$$$$ $$$$$$ |#
#| $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ |#
#| $$ $$$$$$$ $$$$$ $$ $$ $ $$ $$$$$$ $$ $$$$$ $$$$$ |#
#| $$ $$ $$ $$ $$ $ $ $$ $$ $$ $$ $$ |#
#| $$$$ $$ $$ $$$$$$ $$ $$ $$$$$ $$ $$$$$$ $$$$$$ $$$$$$ |#
#------------------------------------------------------------------------------------------------------------------#
k_nginx="nginx-1.9.10.tar.gz"
k_pcre="pcre-8.40.tar.gz"
k_openssl="openssl-1.1.0f.tar.gz"
k_zlib="zlib-1.2.11.tar.gz"
prename="nginx"
installpath=$(cd `dirname $0`; pwd)
function environment(){
echo "-----------------------------------------------------------------------"
echo "------------------------ check gcc ----------------------------------"
echo "-----------------------------------------------------------------------"
gccbin=`which gcc`
gccv=$(echo $gccbin | grep "gcc")
if [[ "$gccv" != "" ]]
then
echo "gcc was installed "
else
echo "install gcc"
yum install gcc gcc-c++ -y >/dev/null 2>&1
fi
}
function initialize(){
installpath=$(cd `dirname $0`; pwd)
cd ${installpath}
cd ${prename}/lib/openssl* && opensslpath=`pwd`
cd ${installpath}
cd ${prename}/lib/pcre* && pcrepath=`pwd`
cd ${installpath}
cd ${prename}/lib/zlib* && zlibpath=`pwd`
cd ${installpath}
}
function installssl(){
echo "-----------------------------------------------------------------------"
echo "---------------------- install openssl ------------------------------"
echo "-----------------------------------------------------------------------"
mkdir -p logs ${prename}/lib && touch logs/{openssl.log,pcre.log,zlib.log,nginx.log}
#openss
tar -zxvf ${k_openssl} -c ${prename}/lib >/dev/null 2>&1
cd ${prename}/lib/openssl* && opensslpath=`pwd`
./config --prefix=${opensslpath} >${installpath}/logs/openssl.log >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
return 1
else
make && make install >${installpath}/logs/openssl.log
if [[ $? -ne 0 ]]; then
return 1
fi
return 0
fi
}
function installpcre(){
echo "-----------------------------------------------------------------------"
echo "---------------------- install pcre ---------------------------------"
echo "-----------------------------------------------------------------------"
#pcre
cd ${installpath}
tar -zxvf ${k_pcre} -c ${prename}/lib >/dev/null 2>&1
cd ${prename}/lib/pcre* && pcrepath=`pwd`
./configure --prefix=${pcrepath} >${installpath}/logs/pcre.log >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
return 1
else
make && make install >${installpath}/logs/pcre.log
if [[ $? -ne 0 ]]; then
return 1
fi
return 0
fi
}
function installzlib(){
echo "-----------------------------------------------------------------------"
echo "---------------------- install zlib ---------------------------------"
echo "-----------------------------------------------------------------------"
#zlib
cd ${installpath}
tar -zxvf ${k_zlib} -c ${prename}/lib >/dev/null 2>&1
cd ${prename}/lib/zlib* && zlibpath=`pwd`
./configure --prefix=${zlibpath} >${installpath}/logs/zlib.log >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
return 1
else
make && make install >${installpath}/logs/zlib.log
if [[ $? -ne 0 ]]; then
return 1
fi
return 0
fi
}
function installnginx(){
echo "-----------------------------------------------------------------------"
echo "---------------------- install nginx --------------------------------"
echo "-----------------------------------------------------------------------"
#nginx
cd ${installpath}
initialize
tar -zxvf ${k_nginx} >/dev/null 2>&1
cd nginx-* && nginxpath=`pwd`
./configure --prefix=${installpath}/${prename} --with-pcre=${pcrepath} --with-openssl=${opensslpath} --with-zlib=${zlibpath}
if [[ $? -ne 0 ]]; then
return 1
else
make && make install >${installpath}/logs/nginx.log
if [[ $? -ne 0 ]]; then
return 1
fi
return 0
fi
}
environment
installssl
installpcre
installzlib
installnginx
推荐阅读
-
Ubuntu、Linux Mint一键安装Chrome浏览器的Shell脚本分享
-
lnmp一键安装环境中nginx开启pathinfo,lnmpnginx_PHP教程
-
lnmp一键安装环境中nginx开启pathinfo
-
MySQL5.7安装过程并重置root密码的方法(shell 脚本)
-
MySQL5.7安装过程并重置root密码的方法(shell 脚本)
-
Centos7安装 mysql5.6.29 shell脚本
-
shell脚本分析 nginx日志访问次数最多及最耗时的页面(慢查询)
-
nginx日志切割shell脚本
-
阿里云主机一键安装lamp、lnmp环境的shell脚本分享
-
Linux下实现SNMP一键安装的Shell脚本