#!/bin/bash#by lc ip= ' ifconfig eth0|awk -f ' [ :]+ ' ' NR==2{print $4} ' zhandian=/data01/static/shareextra=haixiang.conftoolsdir=/application/toolsnginxdir=/application/ nginx1.8.0extardir=/application/nginx1.8.0/conf/extraaliyun=/etc/yum.repos.d/centos-base.repo http:// Mirrors.aliyun.com/repo/centos-6.reponginxbanen=nginx-1.8.0nginx=http://nginx.org/download/${nginxbanen}. tar.gzstickytar=nginx-sticky-module-1.1.tar.gzstickywget=http://nginx-sticky-module.googlecode.com/files/$ Stickytar rs1=192.168.1.240rs2=192.168.1.98:80panduan () {If [ $? -ne 0 ]then echo "===============$1 not ok ====================" exit 1fi}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&NBSP;&NBSP;&NBSP;&NBSP;MAKEPANDUAN&NBSP;MAKE&NBSP;&NBSP;MAKE&NBSP;INSTALL&NBSP;&NBSP;CD&NBSP, .... / ln -s $NGINXDIR /application/nginxpanduan link}function nginxconf () {cat > $NGINXDIR/conf/nginx.conf<<aaworker_processes 2;events { worker_connections 1024;} http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; &nBSP; #nginx vhosts config########## #upstream ################# upstream webservers { #ip_hash; server $RS 1 ; server $RS 2 ;########## #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 Nginxpkill 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
This article is from the "10886311" blog, please be sure to keep this source http://10896311.blog.51cto.com/10886311/1718514
Shell Nginx Install + Load Balancer + Session hold