Ubuntu 14.04.3 LTS version with Nginx + keepalived configuration high-availability load Balancer cluster demo

Source: Internet
Author: User

system version : Ubuntu 14.04.3 LTS

Server Preparation :
lb01-> ifconfig Display Result: 192.168.91.136 effect: Install keepalived and Nginx
lb02-> ifconfig Display Result: 192.168.91.135 effect: Install keepalived and Nginx
web01-> ifconfig Display Result: 192.168.91.134 effect: Install Nginx is responsible for showing index.html page
web02-> ifconfig Display Result: 192.168.91.137 effect: Install Nginx is responsible for showing index.html page

Operating principle
1 Nginx acts as a Web server on WEB01/WEB02
2 Nginx acts as a load balancing tool on LB01 and LB02, using the upstream tool
3 keepalived Virtual VIP configuration on LB01 and LB02

specific installation steps:
1 Install Nginx on the LB01/LB02/WEB01/WEB02.
Apt-get Install Nginx-y
2 Modify the default display page of WEB01/WEB02 and change the contents to WEB01/WEB02
echo ' web02 ' >/usr/share/nginx/html/index.html
echo ' WEB01 ' >/usr/share/nginx/html/index.html
3 Configure the LB01/LB02 as a load balancer server.
Edit nginx.conf configuration file
Nano/etc/nginx/nginx.conf

 add the following:upstream backed{    server 192.168.91.134:80 weight=5; in the current default configuration file     server 192.168.91.137:80 weight=5;} server{    listen 80;    server_name www.jingshan.net;     location / {        root html;         index index.html index.htm;         proxy_pass http://backed;    }} 

and modify the corresponding/etc/hosts under the file, named Nano/etc/hosts added as follows:
127.0.0.1 www.jingshan.net
Restart Nginx,
Service Nginx Restart
Then use Curl www.jingshan.net to test, when multiple tests should be found, will show web01 or WEB02 certificate configuration OK.

4 install keepalived; command for Apt-get install Keepalived-y
Copy configuration file Past
Cp/usr/share/doc/keepalived/samples/keepalived.conf.vrrp/etc/keepalived/keepalived.conf
To edit a configuration file:
Nano/etc/keepalived/keepalived.conf
The corresponding LB01: The configuration file is:
Global_defs {
Notification_email {
Acassen
}
Notification_email_from [email protected]
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
router_id LB01
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
Garp_master_delay 10
Smtp_alert
VIRTUAL_ROUTER_ID 51
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
# Optional Label. Should is of the form "Realdev:sometext" for
# Compatibility with Ifconfig.
192.168.91.188/24 label Eth0:1
}
}
LB02 configuration file:
Global_defs {
Notification_email {
Acassen
}
Notification_email_from [email protected]
Smtp_server 192.168.200.1
Smtp_connect_timeout 30
router_id LB02
}

Vrrp_instance Vi_1 {
State BACKUP
Interface eth0
Garp_master_delay 10
Smtp_alert
VIRTUAL_ROUTER_ID 51
Priority 40
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1111
}
virtual_ipaddress {
# Optional Label. Should is of the form "Realdev:sometext" for
# Compatibility with Ifconfig.
192.168.91.188/24 label Eth0:1
}
}

Restart the corresponding keepalived respectively;
Use the IP addr command to retrieve the VIP to see if the new success.

If found: inet 192.168.188/24 scope Global Secondary eth0:1

Then the local host file on your computer is modified to
192.168.91.188 www.jingshan.net

Access through the browser, if displayed separately web01 and WEB02 is normal.
When the LB01 is stopped, it can also be displayed normally.


This article is from the "Focus on PHP Group number: 414194301" blog, please be sure to keep this source http://jingshanls.blog.51cto.com/3357095/1853438

Ubuntu 14.04.3 LTS version with Nginx + keepalived configuration high-availability load Balancer cluster demo

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.