#!/bin/bash #by LC IP=`ifconfig eth0|awk -F ‘[ :]+‘ ‘NR==2{print $4}‘` ZHANDIAN=/data01/static/share EXTRA=haixiang.conf TOOLSDIR=/application/tools NGINXDIR=/application/nginx1.8.0 EXTARDIR=/application/nginx1.8.0/conf/extra ALIYUN=/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo NGINXBANEN=nginx-1.8.0 NGINX=http://nginx.org/download/${NGINXBANEN}.tar.gz STICKYTAR=nginx-sticky-module-1.1.tar.gz STICKYWGET=http://nginx-sticky-module.googlecode.com/files/$STICKYTAR RS1=192.168.1.240 RS2=192.168.1.98:80 panduan(){ if [ $? -ne 0 ] then echo "===============$1 NOT OK ====================" exit 1 fi } function checkNginxRoot(){ if [ $UID -ne 0 ] then echo ‘PLEASES DO THIS "su -"‘ && exit 1 fi } function checkNginxUser(){ if [ `cat /etc/passwd|grep nginx|wc -l` -eq 0 ] then useradd nginx -s /sbin/nologin -M fi } function checkNginxDir(){ [ ! -d $TOOLSDIR ] && mkdir -p $TOOLSDIR [ ! -d /app/ ] && mkdir -p /app [ ! -d $NGINXDIR ] && mkdir -p $NGINXDIR [ ! -d $EXTARDIR ] && mkdir -p $EXTARDIR } function checkYnmANDstart(){ wget -O $ALIYUN yum makecache yum install pcre pcre-devel -y yum install openssl openssl-devel -y cd $TOOLSDIR && wget $STICKYWGET tar -xzvf $STICKYTAR wget $NGINX tar xf $NGINXBANEN.tar.gz cd $NGINXBANEN ./configure --user=nginx --group=nginx --prefix=$NGINXDIR --with-http_stub_status_module --with-http_ssl_module panduan bianyi make panduan make make install cd ../ ln -s $NGINXDIR /application/nginx panduan link } function NGINXCONF(){ cat >$NGINXDIR/conf/nginx.conf<<AA worker_processes 2; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; #nginx vhosts config ###########upstream################# upstream webservers { #ip_hash; server $RS1 ; server $RS2 ; ###########sticky################### #sticky name=srv_id expires=1h domain=www.haixiang.com path=/ ; } server{ server_name localhost; listen 80; location / { proxy_pass http://webservers; proxy_set_header Host \$host; proxy_set_header X-Forwarded-For \$remote_addr ; } } } AA } pkill nginx pkill httpd $NGINXDIR/sbin/nginx } function FORcurl(){ if [ $(curl -I $IP|egrep "403|200|404"|head -1|wc -l) -eq 1 ] then echo "############" echo " OK OK OK" echo "############" fi panduan CURL } function readme(){ echo "This is the start command :$NGINXDIR/sbin/nginx OR /application/nginx/sbin/nginx" echo "This is the reload command:$NGINXDIR/sbin/nginx -s reload" echo "This is the test command:$NGINXDIR/sbin/nginx -t" } main (){ checkNginxUser checkNginxDir checkYnmANDstart NGINXCONF FORcurl readme } main
本文出自 “10886311” 博客,请务必保留此出处http://10896311.blog.51cto.com/10886311/1718514
原文地址:http://10896311.blog.51cto.com/10886311/1718514