keepalived monitor MySQL master-slave switching

Source: Internet
Author: User

1), install MySQL on the two machines separately, keepalived

2),

Keepalived Master-Slave:

Master: vim/etc/keepalived/keepalived.conf

Vrrp_instance Vi_1 {

State backup # Backup with Backup

Interface Eth2 #用的是哪个网卡

virtual_router_id #虚拟路由地址必须一样 to be configured as a group

Priority 100 # Spare 90

Advert_int 1 #MASTER与BACKUP负载均衡器之间同步检查的时间间隔, Unit is seconds

Nopreempt

Authentication {

Auth_type PASS # (password form)

Auth_pass 1111

}

virtual_ipaddress {

192.168.32.100

}

Notify_master "/bin/bash-x/usr/local/sbin/modify_master.sh 2>&1 | Tee/tmp/modi.txt "

#notify_master "/bin/echo Master >>/etc/keepalived/temp.txt"

}

Virtual_server 192.168.32.100 3306 {

Delay_loop 6 #每隔6s Query Realserver status

Lb_algo RR #lvs algorithm

Lb_kind NAT #Direct Route

Persistence_timeout #会话保持时间, the unit is seconds (can be extended to keep the session properly)

Protocol TCP # Check Realserver status with TCP protocol

Real_server 192.168.32.79 3306 {

Weight 1

notify_down/usr/local/sbin/keepalived.sh

Tcp_check {

Connect_timeout #10s No response timeout

Nb_get_retry 3

Delay_before_retry 3

Connect_port 3306

}

}

}

From: vim/etc/keepalived/keepalived.conf


Vrrp_instance Vi_1 {

State backup # Backup with Backup

Interface Eth2 #用的是哪个网卡

virtual_router_id #虚拟路由地址必须一样 to be configured as a group

Priority 90 # Spare 90

Advert_int 1 #MASTER与BACKUP负载均衡器之间同步检查的时间间隔, Unit is seconds

Nopreempt

Authentication {

Auth_type PASS # (password form)

Auth_pass 1111

}

virtual_ipaddress {

192.168.32.100

}

Notify_master "/bin/bash-x/usr/local/sbin/modify_master.sh 2>&1 | Tee/tmp/modi.txt"

#notify_master "/bin/echo Master >>/etc/keepalived/temp.txt"

}

Virtual_server 192.168.32.100 3306 {

Delay_loop 2 #每隔2s Query realserver status

Lb_algo RR #lvs algorithm

Lb_kind NAT #Direct Route

Persistence_timeout #会话保持时间, the unit is seconds (can be extended to keep the session properly)

Protocol TCP # Check Realserver status with TCP protocol

Real_server 192.168.32.87 3306 {

Weight 1

notify_down/usr/local/sbin/keepalived.sh

Tcp_check {

Connect_timeout #10s No response timeout

Nb_get_retry 3

Delay_before_retry 3

Connect_port 3306

}

}

}

where master-slave keepalived.sh:

#!/bin/bash

Service keepalived Restart

Service MySQL Start

master-Slave modify_master.sh:

#!/bin/bash

/usr/local/mysql/bin/mysql-uroot-p1234567-e ' Set global read_only=0; '

/usr/local/mysql/bin/mysql-uroot-h 192.168.32.87 -p1234567-e ' Set global read_only=1; ' ( where-H follows the host either a space, or quotes, from modified to: 192.168.32.79)

MySQL master-slave (need to build mutual master from):

Primary server:

server_id = 1

Log-bin=aming

BINLOG-DO-DB=DB1,DB2 (Binlog-ignore-db=mysql)

Specify permissions:

>grant replication Slave on * * to ' repl ' @ ' 192.168.32.87 ' identified by ' 1234567 ';

>flush privileges;

>flush tables with read lock; (Unlock tables;)

To view the primary server status:

>show Master status;

From the server:

server_id = 11

Replicate-do-db = DB1; (Replicate-ignore-db=mysql)

Then copy the data from the master server to the slave server.

> Stop slave;

> Change Master to master_host= ' 192.168.32.79 ', master_port=3306,master_user= ' repl ', master_password= ' 1234567 ',

> master_log_file= ' aming.00001 ', master_log_pos=106; (Data seen by show master status in the master server)

> Start slave;

Note: A reboot is required after configuration, where the master/slave needs to see the slave-io-running and slave-sql-running in show slave status from the server, and view Last-io-error and La St_sql_error if the error

MySQL settings are read-only:

1) flush tables with read lock; (Exit termination failure)

2) set global read_only=1; This can still write operations with super privilege

3) Grant Select .... Permissions


When using keepalived for the master-slave configuration, the application will need to configure the keepalived VIP address.

keepalived monitor MySQL master-slave switching

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.