Installation and testing of Nginx load Balancer

Source: Internet
Author: User
installation and testing of Nginx load Balancer 1. Configure 3 Machines

A server ip:192.168.157.128 (master)

b Server ip:192.168.157.136

C Server ip:192.168.157.137

Vim/etc/hosts

192.168.157.128 HADOOP1
192.168.157.136 HADOOP2
192.168.157.137 HADOOP3

2. nginx.conf setting

A server nginx.conf settings
Open nginx.conf, and the file location is in the Conf directory of the Nginx installation directory.

Add the following code to the HTTP segment

Upstream A.com {
Server 192.168.157.136:80;
Server 192.168.157.137:80;
}

server{
Listen 80;
server_name HADOOP1;
Location/{
Proxy_pass Http://hadoop1;
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
}
}

Save Restart Nginx-s Reload

Configure the B, C server nginx.conf settings separately
Open Nginx.confi and add the following code to the HTTP segment

server{
Listen 80;
server_name HADOOP1;
Index index.html;
}

Restart the B, C server nginx-s reload respectively

Differentiated interface:
192.168.157.128 vim/usr/local/nginx/html/index.html content is HADOOP1
192.168.157.136 vim/usr/local/nginx/html/index.html content is HADOOP2
192.168.157.137 vim/usr/local/nginx/html/index.html content is HADOOP3
3. Restart A, B, and C servers respectively

Nginx-s Reload

Access the HTTP://HADOOP1:80 refresh interface to see the interface content as HADOOP2 or HADOOP3
Conclusion:
Open the browser to access the HTTP://HADOOP1:80 results, The refresh discovers that all requests are allocated to B server (192.168.157.136) and C server (192.168.157.137), respectively, by the primary server (192.168.157.128), and the load balancing effect is achieved.


4. Simulate a server outage

What if one of the servers goes down.
When a server goes down, does it affect access?

Let's take a look at the example above, assuming that the C server 192.168.157.137 the machine is down (because it can't emulate the outage, so I shut down the C server) and then come back to see it.

Access Result: HADOOP2

We found that although the C server (192.168.157.137) was down, it did not affect website access. This way, there is no fear of dragging the entire site in a load-balancing mode because of a machine outage.

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.