Nginx installation and support upstream monitoring

Source: Internet
Author: User

Nginx installs and supports upstream and TCP proxy modules


Yum Groupinstall "Development tools"

Yum-y install pcre-devel OpenSSL openssl-devel git

wget http://nginx.org/download/nginx-1.4.5.tar.gz

Tar zxvf nginx-1.4.5.tar.gz

CD nginx-1.4.5

git clone https://github.com/yaoweibin/nginx_upstream_check_module.git//upstream module

git clone https://github.com/yaoweibin/nginx_tcp_proxy_module.git//tcp proxy module

Yum Install patch

PATCH-P1 <nginx_upstream_check_module/check_1.2.6+.patch

PATCH-P1 <nginx_tcp_proxy_module/tcp.patch

./configure--add-module=nginx_upstream_check_module--add-module=nginx_tcp_proxy_module

Make

Make install


cp/usr/local/nginx/sbin/nginx/usr/sbin/



#!/bin/sh

#

# Nginx-this script starts and stops the Nginx daemon

#

# Chkconfig:-85 15

# Description:nginx is an HTTP (s) server, HTTP (s) reverse \

# Proxy and IMAP/POP3 proxy server

# Processname:nginx

# config:/etc/nginx/nginx.conf

# config:/etc/sysconfig/nginx

# Pidfile:/var/run/nginx.pid

# Source function library.

. /etc/rc.d/init.d/functions

# Source Networking configuration.

. /etc/sysconfig/network

# Check that networking are up.

["$NETWORKING" = "no"] && exit 0

nginx= "/usr/sbin/nginx"

prog=$ (basename $nginx)

Nginx_conf_file= "/usr/local/nginx/conf/nginx.conf"

[-f/etc/sysconfig/nginx] &&. /etc/sysconfig/nginx

Lockfile=/var/lock/subsys/nginx

Make_dirs () {

# Make required Directories

User= ' Nginx-v 2>&1 | grep "Configure arguments:" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-'

Options= ' $nginx-v 2>&1 | grep ' Configure arguments: '

for opt in $options; Do

If [' Echo $opt | grep '. *-temp-path ']; Then

Value= ' echo $opt | Cut-d "="-F 2 '

if [!-D "$value"]; Then

# echo "Creating" $value

Mkdir-p $value && chown-r $user $value

Fi

Fi

Done

}

Start () {

[-X $nginx] | | Exit 5

[-F $NGINX _conf_file] | | Exit 6

Make_dirs

Echo-n $ "Starting $prog:"

Daemon $nginx-C $NGINX _conf_file

Retval=$?

Echo

[$retval-eq 0] && Touch $lockfile

Return $retval

}

Stop () {

Echo-n $ "Stopping $prog:"

Killproc $prog-quit

Retval=$?

Echo

[$retval-eq 0] && rm-f $lockfile

Return $retval

}

Restart () {

Configtest | | Return $?

Stop

Sleep 1

Start

}

Reload () {

Configtest | | Return $?

Echo-n $ "Reloading $prog:"

Killproc $nginx-hup

Retval=$?

Echo

}

Force_reload () {

Restart

}

Configtest () {

$nginx-T-C $NGINX _conf_file

}

Rh_status () {

Status $prog

}

Rh_status_q () {

Rh_status >/dev/null 2>&1

}

Case "$" in

Start

Rh_status_q && Exit 0

$

;;

Stop

Rh_status_q | | Exit 0

$

;;

Restart|configtest)

$

;;

Reload

Rh_status_q | | Exit 7

$

;;

Force-reload)

Force_reload

;;

Status

Rh_status

;;

Condrestart|try-restart)

Rh_status_q | | Exit 0

;;

*)

echo $ "Usage: $ {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"

Exit 2

Esac

Then save the file as Nginx, and put it in the/etc/init.d/directory, give execute permission, boot control

# chmod +x/etc/init.d/nginx

# chkconfig--add Nginx

# chkconfig Nginx on


HTTP () below:

Upstream Jms_pool {

# Simple Round-robin

Server 192.168.0.74:8815;

Server 192.168.0.74:8816;

Server 192.168.0.76:8817;


Check interval=3000 rise=2 fall=5 timeout=1000 type=http;

Check_http_send "get/http/1.0\r\n\r\n";

Check_http_expect_alive http_2xx http_3xx;

}



Upstream Lucene_pool {

# Simple Round-robin

Server 192.168.0.88:4906;

Server 192.168.0.89:4906;

Server 192.168.0.90:4906;

Server 192.168.0.91:4906;

Server 192.168.0.92:4906;

Check interval=3000 rise=2 fall=5 timeout=1000 type=tcp;

}


server {

Listen 80;

Location/{

Proxy_pass Http://jms_pool;

}

Location/status {

Check_status;

}

Access_log/var/logs/jms_access.log;

}


server {

Listen 82;

Location/{

Proxy_pass Http://lucene_pool;

}


Location/status {

Check_status;

}

Access_log/var/logs/lucene_access.log;

}




Keepalived realizes Nginx dual machine high Availability

http://sdwang.blog.51cto.com/8432181/1880579

This article is from the "Clown World" blog, please be sure to keep this source http://setup.blog.51cto.com/36721/1882259

Nginx installation and support upstream monitoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.