Configure master-slave backup for keepalived

Source: Internet
Author: User

Keepalived is a software used for hot standby (HA). It is often used together with haproxy for Hot Standby + load balancing to achieve high availability.

Operating principle

Keepalived selects a Hot Standby server as the master machine through election (depending on the weight set by the server). The master machine will be allocated to a specified virtual IP address, external programs can access this server through this IP address. If this server fails (Network disconnection, restart, or keepalived crash on this machine ), keepalived will reselect one machine from another backup machine (or check the weight set by the server) as the master and allocate the same virtual IP address to the current master role.

Election strategy

The election policy is based on the vrrp protocol, completely based on the weight, the maximum weight (0 ~ 255) the master machine will trigger the election in the following situations

1. When keepalived is started

2. master server faults (Network disconnection, restart, or keepalived crash on the machine, but other applications on the machine are not counted as crash)

3. A new backup server is added and the weight is the maximum.

Configure an instance

Two servers and two machines need to access the LAN, and the virtual IP address will be set in their common LAN. If the two machines do not have access to the LAN, each of the virtual IP addresses will be set.

192.168.1.41 Ubuntu 10.04.1 lts (32-bit)

192.168.1.135 Red Hat Enterprise Linux Server Release 6.1 (Santiago) (64-bit)

Download the source code for installation. Both servers must be installed and configured.

Note that you may need to install the popt Library

Ubuntu

sudo apt-get install libpopt-dev

RedHat

sudo yum install popt-devel.x86_64

 

Unzip and install

tar -zxvf keepalived-1.2.2.tar.gzcd keepalived-1.2.2./configure --prefix=/usr/local/keepalived makemake install

The following steps are not required, but are recommended for future operations.

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

Create a path for storing configuration files for keepalived

mkdir -p /etc/etc/keepalived/

The following is the configuration file on each server. The configuration items are exactly the same. The configuration value is based on the specific situation of the local machine. I will paste the RedHat

global_defs{    notification_email    {        [email protected]163.com    }    notification_email_from [email protected]163.com    smtp_server 127.0.0.1    stmp_connect_timeout 30    router_id lnmp_node1}vrrp_instance lnmp {    state MASTER    interface em1    virtual_router_id 100    priority 170    advert_int 5    track_interface {        em1    }    authentication {        auth_type PASS        auth_pass 123456    }    virtual_ipaddress {        192.168.1.200    }}
    • Global_defs: global configuration identifier. The area {} below the surface is a global configuration.

    • Notification_email: Enter the email address in it. If keepalived sends an email to the configured email address when a switchover occurs, there can be multiple email addresses, with one email address per line.
    • Notification_email_from: indicates who sent the email source address when sending the notification email
    • Smtp_server: indicates the SMTP server address used to send an email. You can enter 127.0.0.1.
    • Smtp_connect_timeout: SMTP connection timeout
    • Vrrp_instance: configuration domain of instances on each server. Set this parameter based on the actual situation of the server.
    • State: the instance startup status, Master/Slave. Whether you fill in Master/Slave, it depends on the weight of the machine.
    • Interface: The network card bound to the instance. Because the virtual IP address must be added to an existing network card, this depends on the local machine.
    • Virtual_router_id: Set vrid here. If the two machines are in the same backup group, set the same
    • Priority: set the priority of the current node. The priority must be master and cannot exceed 255.
    • Advert_int: interval for sending multicast information. The two machines in the same backup group must have the same settings. The default value is 1 s.
    • Authentication: verification domain. auth_type (authentication type) and auth_pass (authentication password) must be the same for machines in the same group.
    • Virtual_ipaddress: VIP, the virtual address set for the master machine, and the network interface bound to the instance is set to a network segment

After configuration, you can start it directly.

Start in Ubuntu

/usr/local/keepalived/sbin/keepalived

In RedHat, you can start Ubuntu or as follows

sudo /etc/init.d/keepalived restart

After starting, you can use the IP address a command to check the binding status of the virtual IP address. My configuration is high in the weight of 192.168.1.135, so the VIP is bound to the 135

(ape2!1076)~(h135:135)ip a1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN     link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00    inet 127.0.0.1/8 scope host lo    inet6 ::1/128 scope host        valid_lft forever preferred_lft forever2: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000    link/ether d4:ae:52:6c:74:69 brd ff:ff:ff:ff:ff:ff    inet 192.168.1.135/24 brd 192.168.1.255 scope global em1    inet 192.168.1.200/32 scope global em1    inet6 fe80::d6ae:52ff:fe6c:7469/64 scope link 

At this time, you can use the IP address 192.168.1.200 to access the 135 host.

 

Configure master-slave backup for keepalived

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.