Nginx + Keepalived load balancing on Ubuntu

Source: Internet
Author: User
For Nginx installation and Web service configuration, see: Ingress;

For Nginx installation and Web service configuration, see: http://www.linuxidc.com/Linux/2011-02/32410.htm

I. nginx reverse proxy configuration

Open the/etc/nginx. conf configuration file and add it to http:

Upstream ip {# external virtual IP Address

Server IP1;

Server IP2;

}

Server {

Listen 80;

Server_name ip; # I external virtual IP

Index index.php#index.html#index.htm;

Location /{

Proxy_pass http: // ip;

}

}

Ii. keepalived Configuration

1. Install Keepalived

Sudo apt-get install keepalived

2 configure keepalived

Use IP1 as the master server of Server Load balancer and IP2 as the slave server ". This is achieved through the priority in the configuration file. Set "master server" to 101 and "slave server" to 100.

On IP1, set/etc/keepalived. conf

$ Sudo nano/etc/keepalived. conf

Vrrp_script chk_haproxy {

Script "killall-0 haproxy"

Interval 2

Weight 2

}

Vrrp_instance VI_1 {

Interface eth0

State MASTER

Virtual_router_id 51

Priority 101 #101 is "master", 100 is "slave"

Virtual_ipaddress {

Ip # external virtual IP Address

}

Track_script {

Chk_haproxy

}

}

Run the keepalived Service

Sudo/etc/init. d/keepalived start

The configurations of IP2 and IP1 are basically the same. You only need to set the priority to 100.

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.