Use keepalived + S to build (High Availability + load balancing) environments!

Source: Internet
Author: User

I have previously written a heartbeat-ldirectord to achieve high availability of LVS. Here, a lightweight program keepalived is introduced based on vrrp protocol, which can also provide high availability for services, this program was originally developed to provide high availability for LVS.


Next, let's take a look at how to use keepalived + ipvs to achieve high availability + load balancing.

The RPM installation package is provided after rhel6.4. Here we use the source code for compilation and installation.

Go to the official website to download the source package http://keepalived.org/

Decompress the source program package, pre-compile the configuration, compile the program, and install the program.

Tar zxvf keepalived-1.2.13.tar.gz

./Configure -- prefix =/usr/local/keepalived -- sysconfdir =/etc/

Make & make install

Edit the service script and modify the program path.

Vim/etc/init. d/keepalived

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/44/38/wKioL1PgO0zD0cJAAADv96mxCJg145.jpg "Title =" gw.ye9olmm6((w2mx0hew.w.p.jpg "alt =" wkiol1pgo0zd0cjaaadv96mxcjg145.jpg "/>

Edit the master configuration file/etc/keepalived. conf

! Configuration file for keepalived


Global_defs {// global configuration segment

Icationication_email {// recipient's email address

[Email protected]

}

Notification_email_from [email protected] // sender

Smtp_server 127.0.0.1 // Mail Server

Smtp_connect_timeout 30 // wait for timeout

Router_id lvs_devel

}


Vrrp_instance vi_1 {// define a vrrp route instance

State master // initial State (the slave node is changed to backup)

Interface eth0

Virtual_router_id 51 // route instance id (unique)

Priority 100 // priority (the value of the slave node must be lower than that of the master node)

Advert_int 1 // notification frequency

Authentication {// authentication Configuration

Auth_type pass // Authentication Type

Auth_pass 1111 // Password

}

Virtual_ipaddress {// virtual IP Address

192.168.18.18

}

Notify_master "/etc/keepalived/notify. Sh master" // state conversion notification, you must write your own script.

Notify_backup "/etc/keepalived/notify. Sh backup"

Notify_fault "/etc/keepalived/notify. Sh fault"

}


Virtual_server 192.168.18.18 80 {// define a virtual service

Delay_loop 6

Lb_algo wlc // specify the Scheduling Algorithm

Lb_kind Dr // specify the Working Model

Nat_mask 255.255.255.0

Persistence_timeout 0 // persistent connection

Protocol TCP


Real_server 192.168.18.203 80 {// define RealServer

Weight 1 // set the weight

Http_get {// configure HTTP Health Check

URL {

Path /// check path

Status_code 200 // response status information

}

Connect_timeout 3 // timeout

Nb_get_retry 3 // Number of Retries

Delay_before_retry 3 // the waiting time before each retry

}

}

Real_server 192.168.18.204 80 {

Weight 2

Http_get {

URL {

Path/

Status_code 200

}

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

}

}

}

Synchronize the configuration file to the slave node and modify the two mentioned above. The two nodes start the keepalived service.

RealServer configuration (omitted)

SCP/etc/keepalived. conf admin2:/etc/keepalived/

/Etc/init. d/keepalived start

View the configuration generated by the master node

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/44/3A/wKioL1PgQsXQSilFAARhbTuMsPI761.jpg "Title =" x36ddd6uveu00004ti74u00004pop.jpg "alt =" wkiol1pgqsxqsilarhbtumspi761.jpg "/>

Access VIP 192.168.18.18

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/44/3A/wKioL1PgQ0vSUdFEAADPguPp12k580.jpg "Title ="] MP [3t7pgjm3gd [] 9avh ~ % B .jpg "alt =" wkiol1pgq0vsudfeaadpgupp12k580.jpg "/>


Refresh the page and the request is automatically forwarded to the second RealServer.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/44/3A/wKioL1PgQ9HjnDxjAADU-ggc238496.jpg "Title =" 7 $ V ('9c ~ 4tbaobg77v8a51a.jpg "alt =" wKioL1PgQ9HjnDxjAADU-ggc238496.jpg "/>



At this time we simulate a RealServer, The Realserver2-192.168.18.203 network service to stop, and then look at the status.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/44/3E/wKioL1PgRd-hoPxxAAInQXlGlLI194.jpg "Title ="] n (4eof @ to}] 3N ~ Qd9vbbie.jpg "alt =" wKioL1PgRd-hoPxxAAInQXlGlLI194.jpg "/>

Restore realserver2.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/44/3E/wKioL1PgR36D_f42AAH3A0Pw9QM939.jpg "Title =" pdln(fw?pp=%1%rz7947e5l.jpg "alt =" wkiol1pgr36d_f42aah3a09pwqm939.jpg "/>

In this case, we simulate a fault in the primary ctor and stop the master node network service.

We are on the slave node.

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/44/3E/wKioL1PgSKPRDU53AATldlDQ0sY874.jpg "Title = "~ Zn263jrnofq1p4ktra'_xjwjpg "alt =" wkiol1pgskprdu53aatldldq0sy874.jpg "/>

If the master node is deprecated and the slave node has the highest priority, it inherits resources. If the master node is restored, the resources will still return to the master node because the master node has a higher priority.

Now, keepalived is used to provide high availability for LVS.


If you have any questions, please contact me at qq1183710107.


This article is from the blog of "bad guys". For more information, contact the author!

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.