keepalived Build High Availability Mysql-ha

Source: Internet
Author: User
Tags end log modify mysql mysql update mysql version query version

With regard to mysql-ha, there are many solutions, such as heartbeat, DRBD, MMM, shared storage, but each has its pros and cons. Heartbeat, DRBD configuration is more complex, need to write their own script to achieve MySQL automatic switching, for those who do not script language, this is a problem of brain crack; for MMM, few people in the production environment, and MMM management end need to run a separate server, If you want to achieve high availability, you have to do to the MMM management end ha, which undoubtedly increased the hardware costs; for shared storage, the individual feel that MySQL data or on the local security, storage equipment, after all, a single point of trouble. The use of MySQL dual master+keepalived is a very good solution, in the mysql-ha environment, MySQL interoperability from the relationship, so as to ensure the consistency of the two MySQL data, and then use keepalived to achieve virtual IP, Through the keepalived of the service monitoring function to achieve MySQL failure automatically switch.

Below, I will be on the line of a production environment in the framework to share with you, look at this architecture, mysql-ha is how to achieve the environment topology as follows

 
  
  
  1. mysql-vip:192.168.1.200
  2. mysql-master1:192.168.1.201
  3. mysql-master2:192.168.1.202
  4. OS Version: CentOS 5.4
  5. MySQL version: 5.0.89
  6. Keepalived version: 1.1.20

First, MySQL master-master configuration

1, modify the MySQL configuration file

Both MySQL to open the Binlog log function, open method: In the MySQL configuration file [MySQLd] section, add log-bin=mysql-bin option

Two MySQL Server-id can not be the same, by default, two MySQL ServerID are 1, you need to modify one of the 2 can be

2. Set 192.168.1.201 as 192.168.1.202 Primary server

Create a new authorized user on 192.168.1.201

 
 
  1. mysql> grant replication Slave on *.* to ' replication ' @ '% ' identified by ' replication ';
  2. Query OK, 0 rows Affected (0.00 sec)
  3. Mysql> Show master status;
  4. +------------------+----------+--------------+------------------+
  5. File Position binlog_do_db binlog_ignore_db
  6. +------------------+----------+--------------+------------------+
  7. mysql-bin.000003 374
  8. +------------------+----------+--------------+------------------+
  9. 1 row in Set (0.00 sec)

Set 192.168.1.201 as your primary server on 192.168.1.202

 
 
  1. mysql> Change Master to master_host= ' 192.168.1.201 ', master_user= ' replication ', master_password= ' replication ', Master_log_file= ' mysql-bin.000003 ', master_log_pos=374;
  2. Query OK, 0 rows affected (0.05 sec)
  3. mysql> start slave;
  4. Query OK, 0 rows Affected (0.00 sec)
  5. Mysql> Show Slave Status\g
  6. 1. Row ***************************
  7. Slave_io_state:waiting for Master to send event
  8. master_host:192.168.1.201
  9. Master_user:replication
  10. master_port:3306
  11. Connect_retry:60
  12. master_log_file:mysql-bin.000003
  13. read_master_log_pos:374
  14. relay_log_file:mysql-master2-relay-bin.000002
  15. relay_log_pos:235
  16. relay_master_log_file:mysql-bin.000003
  17. Slave_io_running:yes
  18. Slave_sql_running:yes
  19. replicate_do_db:
  20. replicate_ignore_db:
  21. Replicate_do_table:
  22. Replicate_ignore_table:
  23. Replicate_wild_do_table:
  24. Replicate_wild_ignore_table:
  25. last_errno:0
  26. Last_error:
  27. skip_counter:0
  28. exec_master_log_pos:374
  29. relay_log_space:235
  30. Until_condition:none
  31. Until_log_file:
  32. until_log_pos:0
  33. Master_ssl_allowed:no
  34. Master_ssl_ca_file:
  35. Master_ssl_ca_path:
  36. Master_ssl_cert:
  37. Master_ssl_cipher:
  38. Master_ssl_key:
  39. seconds_behind_master:0
  40. 1 row in Set (0.00 sec)

3. Set 192.168.1.202 as 192.168.1.201 Primary server

Create a new authorized user on 192.168.1.202

 
 
  1. mysql> grant replication Slave on *.* to ' replication ' @ '% ' identified by ' replication ';
  2. Query OK, 0 rows Affected (0.00 sec)
  3. Mysql> Show master status;
  4. +------------------+----------+--------------+------------------+
  5. File Position binlog_do_db binlog_ignore_db
  6. +------------------+----------+--------------+------------------+
  7. mysql-bin.000003 374
  8. +------------------+----------+--------------+------------------+
  9. 1 row in Set (0.00 sec)

On the 192.168.1.201, set 192.168.1.202 as your own home server

 
 
  1. mysql> Change Master to master_host= ' 192.168.1.202 ', master_user= ' replication ', master_password= ' replication ', Master_log_file= ' mysql-bin.000003 ', master_log_pos=374;
  2. Query OK, 0 rows affected (0.05 sec)
  3. mysql> start slave;
  4. Query OK, 0 rows Affected (0.00 sec)
  5. Mysql> Show Slave Status\g
  6. 1. Row ***************************
  7. Slave_io_state:waiting for Master to send event
  8. master_host:192.168.1.202
  9. Master_user:replication
  10. master_port:3306
  11. Connect_retry:60
  12. master_log_file:mysql-bin.000003
  13. read_master_log_pos:374
  14. relay_log_file:mysql-master1-relay-bin.000002
  15. relay_log_pos:235
  16. relay_master_log_file:mysql-bin.000003
  17. Slave_io_running:yes
  18. Slave_sql_running:yes
  19. replicate_do_db:
  20. replicate_ignore_db:
  21. Replicate_do_table:
  22. Replicate_ignore_table:
  23. Replicate_wild_do_table:
  24. Replicate_wild_ignore_table:
  25. last_errno:0
  26. Last_error:
  27. skip_counter:0
  28. exec_master_log_pos:374
  29. relay_log_space:235
  30. Until_condition:none
  31. Until_log_file:
  32. until_log_pos:0
  33. Master_ssl_allowed:no
  34. Master_ssl_ca_file:
  35. Master_ssl_ca_path:
  36. Master_ssl_cert:
  37. Master_ssl_cipher:
  38. Master_ssl_key:
  39. seconds_behind_master:0
  40. 1 row in Set (0.00 sec)

4, MySQL synchronization test

If all of the above are properly configured, now any MySQL update data will sync to another mysql,mysql sync here no more demo




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.