Keepalived+mysql primary master for high availability

Source: Internet
Author: User
Tags pkill

MySQL master-slave configuration reference: http://blog.51cto.com/243662875/2126015

Master configuration is the main

keepalived Download URL: http://www.keepalived.org/

Environment

Prepare your App

keepalived-2.0.2.tar.gzopenssl-devel-1.0.2k-12.el7.x86_64.rpm

Installation

rpm -ivh openssl-devel-1.0.2k-12.el7.x86_64.rpmtar -zxvf keepalived-2.0.2.tar.gz./configure --prefix=/usr/local/keepalivedmake && make install

Organize files

cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/mkdir -p /etc/keepalivedcd /etc/keepalived

Configuring the primary keepalived

vim keepalived.conf
global_defs {notification_email {        }}vrrp_instance VI_1 {        state MASTER      #备服务器上改为 BACKUP        interface ens33     #网卡        virtual_router_id 11        priority 100            #备用服务器上改为99        advert_int 1        authentication {        auth_type PASS        auth_pass 1111        }        virtual_ipaddress {                    192.168.10.11         #VIP        }}virtual_server 192.168.10.132 3306 {    delay_loop 6         #每隔6秒检查一次real_server状态    lb_algo rr             #负载调度算法rr|wrr|lc|wlc|lblc|sh|dh    lb_kind NAT       #负载均衡转发规则NAT|DR|RUN    nat_mask 255.255.255.0    persistence_timeout 50           #回话保持时间    protocol TCP    real_server 192.168.10.132 3306 {        weight 2        notify_down "/etc/keepalived/mysql.sh"   #新建这个mysql.sh文件,输入 pkill keepalived        TCP_CHECK {            connect_timeout 3            connect_port 3306        }    }}

Standby keepalived Configuration

vim keepalived.conf
global_defs {notification_email {        }}vrrp_instance VI_1 {        state BACKUO      #主服务器上改为 master        interface ens33     #网卡        virtual_router_id 11        priority 99        #主服务器设置比备服务器数大        advert_int 1        authentication {        auth_type PASS        auth_pass 1111        }        virtual_ipaddress {            192.168.10.11            #VIP        }}virtual_server 192.168.10.200 3306 {    delay_loop 6       #每隔6秒检查一次real_server状态    lb_algo rr     lb_kind NAT    nat_mask 255.255.255.0    persistence_timeout 50              #回话保持时间    protocol TCP    real_server 192.168.10.200 3306 {        weight 1        notify_down "/etc/keepalived/mysql.sh"   #新建这个mysql.sh文件,输入 pkill keepalived        TCP_CHECK {             connect_timeout 3            connect_port 3306        }    }}

Creating a MySQL detection script

vim mysql.sh#!/bin/bashpkill keepalived         #检测到mysql关闭后自动关闭keepalived

The above Keepalived+mysql configuration is complete. You can check whether the VIP drifts to the standby by turning off the master's MySQL, turn off the main keepalived to see if the VIP is drifting to standby, and turn off the main VIP machine.

About the keepalived algorithm description

RR polling algorithm , which assigns the request to a different RS node, that is, an equally distributed distribution in the RS node. This algorithm is simple, but only suitable for the RS node processing performance is similar to the situation
WRR weighted rotation dispatch , which assigns tasks according to the weights of different Rs. RS with higher weights will take precedence over the task, and the number of connections allocated will be more than RS with lower weights. RS of the same weighted value get the same number of connections.
WLC weighted minimum number of connections scheduling , assuming that each of the RS full-time is WI, the current number of TCP connections is TI, in turn Ti/wi for the smallest RS as the next assigned RS
Dh Destination Address hash dispatch (destination hashing) Find a static hash table with the destination address as the keyword to obtain the required RS
SH Source Address hash dispatch (source hashing) finds a static hash table with the source address as a keyword to obtain the required RS
Lc Minimum number of connections is scheduled (least-connection), and the Ipvs table stores all active connections. LB compares the connection request to the RS with the least current connection.
LBLC Address-based minimum number of connections dispatch (locality-based least-connection): This server is not fully loaded when a request from the same destination address is assigned to the same Rs. Otherwise, the request is assigned to the RS with the smallest number of connections and is considered first as the next assignment.

LVS调度算法的生产环境选型:1、一般的网络服务,如http,mail,mysql等常用的LVS调度算法为:        a.基本轮询调度rr        b.加权最小连接调度wlc        c.加权轮询调度wrc2、基于局部性的最小连接lblc和带复制的给予局部性最小连接lblcr主要适用于web cache和DB cache3、源地址散列调度SH和目标地址散列调度DH可以结合使用在防火墙集群中,可以保证整个系统的出入口唯一。

Practical application of these algorithms are many applications, the best reference in the core of the implementation of the connection scheduling algorithm principle, and then according to the specific business needs of a reasonable selection.

Load Balancing forwarding operation mode
1.Dr Mode :
By overwriting the target MAC address of the request message, the request is sent to the real server, and the real server returns the corresponding processing result directly to the client user. Greatly improve the scalability of the cluster, but lb and Rs must be in the same LAN environment.
2.Nat Mode:
Through the network address translation, the LB rewrite request message destination address, according to the preset scheduling algorithm, the request is dispatched to the backend real server, the real server Response message processing, the return must pass lb, after the LB times the source address is rewritten, and then returned to the customer.
3. Tunnel mode:
LB forwards the requested message over the IP tunnel to the real server, and the real server returns the response directly to the client user.
4.Fullnat mode:
Packet entry, in addition to do Dnat, but also do snat, so that lvs-realserver can communicate across the VLAN, realserver only need to connect to the intranet.

Keepalived+mysql primary master for high availability

Related Article

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.