Mysql+keepalived implementation of dual-machine ha

Source: Internet
Author: User

Host1 and Host3 are mainly from each other, that is, Host1 is the host3 of the host, but also for the host3 slavehost1 192.168.203.131host2 192.168.203.132host3 192.168.203.133 1. Install keepalivedwww.keepalived.org 2. Notice to empty the firewall Iptalbles-f 3. Configure host1 and Host3 to master from and authorize the login grant all on * * to ' Replmonitor ' @ ' 192.168.203.% ' identified by ' 000000 ' with GRANT option; 4. Configure keealived.conf
! ConfigurationFile  forKeepalivedhost1 on: global_defs {notification_email {root@localhost. localdomain} notification_email_from Root@localhost. Localdomain Smtp_server127.0.0.1Smtp_connect_timeout -router_id Test-Mysql-ha}vrrp_instance vi_1 { stateBACKUPinterface ETH3! The network interface name of the current machine virtual_router_idWuyi Priority -! Priority level Nopreempt! Do not take back the master service permissions after rebooting Advert_int1Authentication {auth_type PASS auth_pass1111} virtual_ipaddress {192.168.203.200virtual IP Address, etc will be logged on host2 with this IP}} Virtual_server192.168.203.200 3306{! This port is the service of MySQL Delay_loop1Lb_algo wrr lb_kind DR persistence_timeout -protocol TCP Real_server192.168.203.131 3306{! IP address of host weight1Notify_down/etc/Keepalived/mysql.sh Tcp_check {connect_timeoutTenbingto192.168.203.200Nb_get_retry3Delay_before_retry3Connect_port3306}}host3 just make the corresponding changes to the black part above and remove the Nopreempt ./etc/Keepalived/the contents of mysql.sh are: #!/Bin/Bashpkill keepalived
5.host1 and Host3 Open keepalived, execute the login mysql-h 192.168.203.200-ureplmonitor-p on host2 (this host is the virtual IP address)/etc/init.d/ keepalived start 6. Begin testing, we will host1 on the MySQL stop [[email protected] keepalived]#/etc/init.d/mysql stop
Shutting down to MySQL ..... success!
[Email protected] keepalived]# Ps-ef | grep keepalived
Root 5409 5115 0 00:51 pts/2 00:00:00 grep keepalived on HOST3 query that HOST3 has taken over the virtual host we continue to execute the operation statement on the HOST2 will first prompt the connection to fail and re- Connect and get the results of the query, the failure fails to migrate successfully 7. Execute on HOST3:
Mysql> Delete  fromT1whereIdinch(4,5,6); Query OK,3Rows Affected (0.01sec) re-open mysqlmysql on host1> Select *  fromT1;+------+|Id|+------+|    1 ||    2 ||    4 ||    5 ||    6 |+------+5Rowsinch Set(0.00sec) MySQL>start slave; Query OK,0Rows Affected (0.03sec) MySQL> Select *  fromT1;+------+|Id|+------+|    1 ||    2 |+------+2Rowsinch Set(0.00sec) data is all synchronized, then stop MySQL on HOST3, insert a row of data on host1: MySQL> Insert  intoT1Values(3); query on host2: MySQL> Select *  fromtestdb.t1; ERROR2006(HY000): MySQL server has gone awayno connection. Trying toReconnect ... Connection ID:5 Current Database:***NONE***MySQL> Select *  fromtestdb.t1;+------+|Id|+------+|    1 ||    2 ||    3 |+------+3Rowsinch Set(0.00Sec

The visible data also comes in, keepalive can carry on the efficient data migration work.

Mysql+keepalived implementation of dual-machine ha

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.