MySQL High Availability: mysql+lvs+keepalived load balancing and failover

Source: Internet
Author: User

turn from

MySQL High Availability: mysql+lvs+keepalived load balancing and failover-kk--focus Data-Blog channel-csdn.net
http://blog.csdn.net/kk185800961/article/details/51115264#

System Information:   192.168. 1.152   5.6  5.6.  A     192.168. 1.153   5.6  5.6.  A    VIP         192.168.  1.150  


MySQL primary master synchronization is set Auto-increment-offset,auto-increment-increment to avoid self-increment conflicts.
Reference: MySQL High Availability: Primary master replication (dual master replication)

LVS Download:
Http://www.linuxvirtualserver.org/software/
Http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz


keepalived Download:
Http://www.keepalived.org/software/

Http://www.keepalived.org/software/keepalived-1.2.19.tar.gz

Yum-y install gcc gcc-c++ gcc-g77 ncurses-devel bison libaio-devel  cmake libnl* libpopt* popt-static Openssl-devel   



# LVS Installation configuration: (yum-y install ipvsadm)

cd/usr/local/src  wget http://www.linuxvirtualserver.org/software/kernel-2.6/ ipvsadm-1.24.tar.gz  tar zxvf ipvsadm-1.24. tar.gz  cd Ipvsadm-1.24    -s/usr/src/kernels/2.6. -402. el5-i686//usr/src/linux  #找自己的目录看看/usr/src/kernels  


# keepalived Installation Configuration

cd/usr/local/src wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gzTar zxvf keepalived-1.2. +. tar.gz CD keepalived-1.2. +  ./configure--prefix=/usr/local/keepalived--disable-Fwmark Make&&Make install 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/mkdir-p/etc/keepalived/CP/usr/local/keepalived/etc/keepalived/keepalived.conf/etc/keepalived/


#编辑或者新建 (the master has two places, the other is the same. Standby to: State BACKUP, priority 50)

Vi/etc/keepalived/keepalived.conf

! Configuration File forkeepalived global_defs {#全局标识模块 notification_email {#定义邮件通知 [email protected]163. com #目标邮箱} notification_email_from [email protected]163. com #发送邮箱 smtp_server127.0.0.1#发送邮箱的smtp服务器 smtp_connect_timeout -#smtp服务器连接超时时间 router_id Lvs_devel} vrrp_instance vi_1 {State MASTER #本实例启动状态: Master/BACKUPInterfaceeth0 #监控的网络接口 virtual_router_idWuyi#vrrp实例 (same as a group master and standby server settings) priority -#优先级高的为master, not more than 255. (Backup can be set to Advert_int)1#均衡器检测间隔1秒 (server settings are the same) authentication {#验证类型及密码 (server settings are the same) Auth_type PASS #认证方式, PA SS or Ah Auth_pass123456#认证密码} virtual_ipaddress {#虚拟ip地址virtual_ipaddress, you can define multiple192.168.1.150}} virtual_server192.168.1.150 3306{#定义虚拟服务器, just like the virtual_server above Delay_loop6#健康检查时间间隔, 6 sec Lb_algo rr #负载均衡调度算法: RR|wrr|lc|wlc|sh|dh|LBLC lb_kind Nat #负载均衡转发规则: Nat| dr|TUN Nat_mask255.255.255.0Persistence_timeout -#回话保持时间50秒, dynamic service is recommended to open protocol TCP #转发协议protocol, generally have TCP and UDP two kinds of #后端真实服务器, a few sets of several real_serve R192.168.1.152 3306{weight1#权重越大负载分越大, 0 means invalid Ssl_get {#健康检查方式: Http_get| Ssl_get| tcp_check| smtp_check|Misc_check connect_timeout3Nb_get_retry3Delay_before_retry3}} real_server192.168.1.153 3306{weight1Ssl_get {connect_timeout3Nb_get_retry3Delay_before_retry3          }      }  }  

#启动 keepalived Services   /etc/rc.d/init.d/keepalived start    #添加到rc. Local from startup   "/etc/rc.d/init.d/keepalived Start" >>/etc/rc.local

#152服务器IP [[email protected] keepalived]# IP a1: Lo: <LOOPBACK,UP,LOWER_UP> MTU16436qdisc noqueue Link/loopbackxx:xx:xx:xx:xx:xxBrdxx:xx:xx:xx:xx:xxinet127.0.0.1/8Scope host Lo2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU theQdisc Pfifo_fast Qlen +Link/etherxx: 0c: in: 3b:c4:a5 BRD ff:ff:ff:ff:ff:ff inet192.168.1.152/ -Brd192.168.1.255ScopeGlobaleth0 inet192.168.1.150/ +ScopeGlobalEth0

#现在在第三台mysql服务器中连接VIP测试    #ping VIP normal   192.168.  1.150    #连接到 VIP normal   -umysqlproxy-pmysqlproxy-h192.  168.1.  port3306    -153  View process to see which server the user mysqlproxy connected to  MySQL > show processlist;    #停止 mysqlproxy Server keepalived service   /etc/rc.d/init.d/keepalived stop    at this time at 150 Connected MySQL switches to another server's MySQL database.      


Some tests at the end have not been standardized and are for reference only.

For more information:

MySQL High Availability: Primary master replication (dual master replication)

IPVSADM installation Configuration

MySQL High availability Explore (ii) Lvs+keepalived+mysql single-point write master synchronization high Availability scheme

Lvs+keepalived+mysql Dual Master

keepalived Configuring Master-slave Backup

Installation and configuration of Linux under Keepalived

CentOS 5.9 Installation Configuration keepalived

Keepalived.conf Content Description

MySQL High Availability: mysql+lvs+keepalived load balancing and failover

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.