Linux system Architecture (lb-ha cluster)-nginx load Balancing cluster configuration

Source: Internet
Author: User
Tags nginx load balancing

Nginx Load Balancer cluster configuration

[Email protected] ~]# cd/usr/local/nginx/conf/vhosts/

[[email protected] vhosts]# ls

Default.conf test.conf

[Email protected] vhosts]# vim lb.conf

Upstream Wang {

Server 192.168.137.21:80;

Server 192.168.137.23:80;

}

server {

Listen 80;

server_name www.123.com;

Location/{

Proxy_pass http://wang/;

Proxy_set_header Host $host;

}

}

[Email protected] vhosts]# ipvsadm-c

[Email protected] vhosts]# iptables-t nat-f

[Email protected] vhosts]# iptables-f

[[Email protected] vhosts]# CD

If you've done this before, clear it up first .

[Email protected] ~]# NETSTAT-LNP |grep nginx

TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 24166/nginx

[Email protected] ~]# curl-xlocalhost:80www.123.com

Master

[Email protected] ~]# curl-xlocalhost:80www.123.com

Slave

[Email protected] ~]# curl-xlocalhost:80www.123.com

Master

[Email protected] ~]# curl-xlocalhost:80www.123.com

slave650) this.width=650, "style=" Border-bottom: #ddd 1px solid;border-left: #ddd 1px solid;background:url ("/e/u261/ Lang/zh-cn/images/localimage.png ") no-repeat Center 50%;border-top: #ddd 1px solid;border-right: #ddd 1px solid;" alt= " Spacer.gif "src="/e/u261/themes/default/images/spacer.gif "width=" 554 "height=" 98 "/>

Visit Master once , slave once.

[Email protected] ~]# cd/usr/local/nginx/conf/vhosts/

[Email protected] vhosts]# vim lb.conf

Upstream Wang {

Server 192.168.137.21:80 weight=2 ;

Server 192.168.137.23:80 weight=1 ;

}

server {

Listen 80;

server_name www.123.com;

Location/{

Proxy_pass http://wang/;

Proxy_set_header Host $host;

}

}

Plus weight

[Email protected] vhosts]#/etc/init.d/nginxrestart

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

650) this.width=650, "style=" Border-bottom: #ddd 1px solid;border-left: #ddd 1px solid;background:url ("/e/u261/lang/ Zh-cn/images/localimage.png ") no-repeat Center 50%;border-top: #ddd 1px solid;border-right: #ddd 1px solid;" alt= " Spacer.gif "src="/e/u261/themes/default/images/spacer.gif "width=" 456 "height=" 212 "/>

occurs two times master, once slave

on Rs1:

Stop Service

[[email protected] ~]#/etc/init.d/nginx stop

Dir on test:

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

650) this.width=650, "style=" Border-bottom: #ddd 1px solid;border-left: #ddd 1px solid;background:url ("/e/u261/lang/ Zh-cn/images/localimage.png ") no-repeat Center 50%;border-top: #ddd 1px solid;border-right: #ddd 1px solid;" alt= " Spacer.gif "src="/e/u261/themes/default/images/spacer.gif "width=" "height=" 155 "/>"

All Access slave, automatic rejection of bad, automatic switching

Rs1 Recovery Service

[[email protected] ~]#/etc/init.d/nginx start

Dir on test

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Slave

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

[Email protected] vhosts]# curl-xlocalhost:80www.123.com

Master

650) this.width=650, "style=" Border-bottom: #ddd 1px solid;border-left: #ddd 1px solid;background:url ("/e/u261/lang/ Zh-cn/images/localimage.png ") no-repeat Center 50%;border-top: #ddd 1px solid;border-right: #ddd 1px solid;" alt= " Spacer.gif "src="/e/u261/themes/default/images/spacer.gif "width=" 396 "height="/>

Auto Recovery, two times master, one time slave


This article is from the Linux Learning Notes blog, so be sure to keep this source http://9656134.blog.51cto.com/9646134/1678349

Linux system Architecture (lb-ha cluster)-nginx load Balancing cluster configuration

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.