Last active
August 29, 2015 14:01
-
-
Save sennajox/e5eee8704793c715d192 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. 建立DB节点 | |
(其中2台为master,另一台为slave); | |
以master1作为主库 | |
master1特殊配置: | |
# custom | |
server-id = 1001 | |
log_bin = mysql-bin | |
log_bin_index = mysql-bin.index | |
log-slave-updates | |
sync_binlog = 1 | |
auto_increment_increment = 2 | |
auto_increment_offset = 1 | |
skip_slave_start | |
read_only = 1 | |
master2特殊配置 | |
# custom | |
server-id = 1002 | |
log_bin = mysql-bin | |
log_bin_index = mysql-bin.index | |
log-slave-updates | |
sync_binlog = 1 | |
auto_increment_increment = 2 | |
auto_increment_offset = 2 | |
read_only = 1 | |
slave特殊配置 | |
# custom | |
server-id = 1003 | |
log_bin = mysql-bin | |
log_bin_index = mysql-bin.index | |
#log-slave-updates | |
sync_binlog = 1 | |
read_only = 1 | |
2. 安装node | |
https://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-0.el6.noarch.rpm | |
shell> yum install perl-DBD-MySQL | |
rpm -ivh mha4mysql-node-0.54-0.el6.noarch.rpm | |
3. 安装manager | |
https://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.55-0.el6.noarch.rpm | |
shell> yum install perl-DBD-MySQL | |
shell> yum install perl-Config-Tiny | |
shell> yum install perl-Log-Dispatch | |
shell> yum install perl-Parallel-ForkManager | |
shell> yum install perl-Time-HiRes | |
rpm -ivh mha4mysql-node-0.54-0.el6.noarch.rpm | |
rpm -ivh mha4mysql-manager-0.55-0.el6.noarch.rpm | |
4. 配置mha | |
为确保结构不被破坏,使用1主2从的架构,同时其中一台slave不作为高可用切换的候选节点,即主从切换只在固定的2台之间进行 | |
4.1 default全局配置 | |
[server default] | |
user=root | |
password= | |
ssh_user=root | |
repl_user=replication | |
repl_password=123456 | |
ping_interval=1 | |
#master_ip_online_change_script="" | |
#master_ip_failover_script="" | |
[server1] | |
hostname = 192.168.1.100 | |
port = 3306 | |
master_binlog_dir = /var/lib/mysql | |
candidate_master = 1 | |
[server2] | |
hostname = 192.168.1.101 | |
port = 3306 | |
master_binlog_dir = /var/lib/mysql | |
candidate_master = 1 | |
[server3] | |
hostname = 192.168.1.102 | |
port = 3306 | |
master_binlog_dir = /var/lib/mysql | |
no_master = 1 | |
5. 切换方法 | |
5.1 在线切换——保留原master节点 | |
masterha_master_switch --master_state=alive --conf=/etc/mha.cnf --new_master_host=192.168.1.101 --orig_master_is_new_slave | |
这个切换可以随时执行,不需要manager处于运行中,期间会询问几次yes/no; | |
需要注意的是,在线切换时,如果没有online_change脚本处理对应逻辑的话,工具本身并不会将旧的master置为read_only,只会把新的master置为read_only=0,最好先把原主库read_only设置为1 | |
5.2 离线切换 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment