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