Skip to content

Instantly share code, notes, and snippets.

@seansan
Created February 12, 2015 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save seansan/e357fa9f70a3c90764a2 to your computer and use it in GitHub Desktop.
Save seansan/e357fa9f70a3c90764a2 to your computer and use it in GitHub Desktop.
#!/bin/bash
### VARIABLES ###
PRE_PACK="gcc gcc-c++ make pcre-devel zlib-devel unzip wget"
OPT_PACK="openssl-devel"
VER="1.5.12"
PREV_VER="1.5.11"
USER="nginx"
GROUP="nginx"
INSTALL_DIR="/etc/nginx"
PROG_NAME="nginx"
OPENSSLVERSION="1.0.1f"
DT=`date +"%d%m%y-%H%M%S"`
HN=$(uname -n)
# Pre-Checks to prevent screw ups
DIR_TMP='/svr-setup'
SCRIPT_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
if [ ! -d "$DIR_TMP" ]; then
mkdir -p $DIR_TMP
fi
# Setup Colours
black='\E[30;40m'
red='\E[31;40m'
green='\E[32;40m'
yellow='\E[33;40m'
blue='\E[34;40m'
magenta='\E[35;40m'
cyan='\E[36;40m'
white='\E[37;40m'
boldblack='\E[1;30;40m'
boldred='\E[1;31;40m'
boldgreen='\E[1;32;40m'
boldyellow='\E[1;33;40m'
boldblue='\E[1;34;40m'
boldmagenta='\E[1;35;40m'
boldcyan='\E[1;36;40m'
boldwhite='\E[1;37;40m'
Reset="tput sgr0" # Reset text attributes to normal
#+ without clearing screen.
cecho () # Coloured-echo.
# Argument $1 = message
# Argument $2 = color
{
message=$1
color=$2
echo -e "$color$message" ; $Reset
return
}
clear
if [[ -z $(cat /etc/resolv.conf) ]]; then
echo ""
echo "/etc/resolv.conf is empty. No nameserver resolvers detected !! "
echo "Please configure your /etc/resolv.conf correctly or you will not"
echo "be able to use the internet or download from your server."
echo "aborting script."
echo ""
exit
fi
if [ -f /proc/user_beancounters ]; then
CPUS='1'
MAKETHREADS=" -j$CPUS"
else
# speed up make
CPUS=`cat "/proc/cpuinfo" | grep "processor"|wc -l`
MAKETHREADS=" -j$CPUS"
fi
if [ -f /proc/user_beancounters ];
then
cecho "OpenVZ system detected, NTP not installed" $boldgreen
else
echo "*************************************************"
cecho "* Installing NTP (and syncing time)" $boldgreen
echo "*************************************************"
yum -y install ntp
chkconfig --levels 235 ntpd on
ntpdate pool.ntp.org
echo "The date/time is now:"
date
echo "If this is correct, then everything is working properly"
echo "*************************************************"
cecho "* NTP installed" $boldgreen
echo "*************************************************"
fi
##### DO NOT EDIT BELOW THIS LINE #####
CWD=`pwd`
cecho "Installing/upgrading your web server..." $boldgreen
# install the prerequisites
yum -y -q install $PRE_PACK $OPT_PACK > /dev/null
cd $DIR_TMP
# Get OPENSSL
#
#if [ ! -d "/usr/local/ssl" ]; then
# cecho "Installing OpenSSL" $boldgreen
#
# # Install OpenSSL
# echo "Compiling OpenSSL...""
#download openssl centos 6.x
# wget -cnv --progress=bar http://www.openssl.org/source/openssl-${OPENSSLVERSION}.tar.gz
# tar xvzf openssl-${OPENSSLVERSION}.tar.gz
# cd openssl-${OPENSSLVERSION}
# ./config --prefix=/usr/local --openssldir=/usr/local/ssl
# make
# make install
# ./config shared enable-tlsext --prefix=/usr/local --openssldir=/usr/local/ssl
# make clean
# make
# make install
#fi
cecho "Getting NGINX" $boldgreen
# optional configuration directives
# --with-http_stub_status_module
# --with-http_realip_module
# --without-http_limit_zone_module
# --without-http_limit_req_module
# --without-http_memcached_module
CONFIGURE_OPTIONS="--user=$USER --group=$GROUP
--prefix=/etc/nginx
--sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--pid-path=/var/run/nginx.pid
--lock-path=/var/run/nginx.lock
--http-client-body-temp-path=/var/lib/nginx/body
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi
--http-proxy-temp-path=/var/lib/nginx/proxy
--with-http_ssl_module
--with-http_spdy_module
--with-http_realip_module
--with-http_gunzip_module
--with-http_gzip_static_module
--with-http_stub_status_module
--with-file-aio
--with-ipv6
--with-http_addition_module
--with-http_sub_module
--with-http_dav_module
--with-http_flv_module
--with-http_mp4_module
--with-http_random_index_module
--with-http_secure_link_module
--with-mail
--with-mail_ssl_module
--add-module=/src/tcpmodule/nginx_tcp_proxy_module-master
--without-http_upstream_ip_hash_module
--without-http_map_module
--without-http_autoindex_module
--without-http_ssi_module
--without-http_empty_gif_module
--without-http_scgi_module
--without-http_uwsgi_module"
mkdir -p /src
#Patch with TCP Proxy Module
if [ ! -d "/src/tcpmodule" ]; then
mkdir -p /src/tcpmodule && cd /src/tcpmodule
wget -q https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip
unzip master && rm -f master && cd nginx*
fi
cd /src
# download and install
wget -q http://nginx.org/download/nginx-$VER.tar.gz
tar xzf nginx-$VER.tar.gz && rm -f ng*.tar.gz;
ln -sf nginx-$VER nginx
cd nginx
cecho "Patching with TCP Proxy" $yellow
if [ ! -f /src/tcpmodule/nginx_tcp_proxy_module-master/tcp.patch ]; then
cecho "Patching with TCP Proxy failed, couldnt find patch" $boldred
exit 0
fi
patch -p1 < /src/tcpmodule/nginx_tcp_proxy_module-master/tcp.patch
cecho "Configuring and Making NGINX" $boldgreen
./configure $CONFIGURE_OPTIONS
cecho "Making NGINX" $green
make
cecho "Installing NGINX" $green
make install
cecho "Adding NGINX User" $boldyellow
id -u nginx &>/dev/null || useradd -r nginx
cecho "Adding Daemon" $boldgreen
wget -qO /etc/init.d/nginx https://gist.github.com/sairam/5892520/raw/b8195a71e944d46271c8a49f2717f70bcd04bf1a/etc-init.d-nginx
chmod +x /etc/init.d/nginx
cecho "chkconfig run" $boldyellow
chkconfig --add nginx
chkconfig --level 345 nginx on
service nginx start
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment