nginx 一键安装脚本
#/bin/bash
#install nginx
#env
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
install_path=/usr/local/src
#check root
NowUser=`id -u -n`
if [[ $NowUser != 'root' ]]
then
echo "Usage:Must be root!"
exit 2
fi
function CheckPkg(){
PkgCheck=`rpm -qa | grep ${Pkg} | wc -l`
if [[ $PkgCheck -gt 0 ]]
then
echo "----${Pkg} had installed----"
echo "----------------------------"
return 3
fi
}
function CheckNet(){
HttpCode=`curl -I -m 10 -o /dev/null -s -w %{http_code} www.baidu.com`
if [[ ${HttpCode} == 200 ]]
then
echo "--Network is ok!--"
return ${HttpCode}
else
echo "--Network Error!--"
echo "--Pls check--"
exit 1
fi
}
function InstallPcre(){
Pkg="pcre"
CheckPkg
if [[ $? -eq 3 ]]
then
return 4
fi
DownloadUrl="https://sourceforge.net/projects/pcre/files/pcre/8.38/pcre-8.38.tar.gz"
echo "------------wget pcre-------------"
echo
cd ${install_path}
/usr/bin/wget ${DownloadUrl}
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure && make && make install
cd ${install_path};mkdir /tmp/pkg;mv pcre*.tar.gz /tmp/pkg
}
function InstallZlib(){
Pkg="zlib"
CheckPkg
if [[ $? -eq 3 ]]
then
return 4
fi
DownloadUrl="http://zlib.net/zlib-1.2.11.tar.gz"
echo "------------wget zlib-------------"
echo
cd ${install_path}
/usr/bin/wget ${DownloadUrl}
tar -xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure && make && make install
cd ${install_path};mkdir /tmp/pkg;mv zlib*.tar.gz /tmp/pkg
}
function InstallSSL() {
Pkg="openssl"
CheckPkg
if [[ $? -eq 3 ]]
then
return 4
fi
DownloadUrl="https://www.openssl.org/source/openssl-1.0.1t.tar.gz"
echo "------------wget SSL-------------"
echo
cd ${install_path}
/usr/bin/wget ${DownloadUrl}
tar -zxvf openssl-1.0.1t.tar.gz
cd ${install_path};mkdir /tmp/pkg;mv openssl*.tar.gz /tmp/pkg
}
function InstallNginx() {
Pkg="nginx"
CheckPkg
if [[ $? -eq 3 ]]
then
return 4
fi
DownloadUrl="http://nginx.org/download/nginx-1.4.2.tar.gz"
echo "------------wget Nginx-------------"
echo
cd ${install_path}
wget ${DownloadUrl}
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.38 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1t
make
cd ${install_path}
make install
#将软件包归档
cd ${install_path};mkdir /tmp/pkg;mv nginx*.tar.gz /tmp/pkg
}
function main() {
CheckNet
#安装编译环境
/usr/bin/yum -y install gcc automake autoconf libtool make gcc-c++
InstallPcre
InstallZlib
InstallSSL
InstallNginx
}
main