[分享]MySQL-master-ha的安装与使用MHA_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3636 | 回复: 0   主题: [分享]MySQL-master-ha的安装与使用MHA        下一篇 
game
注册用户
等级:新兵
经验:36
发帖:61
精华:0
注册:2011-7-23
状态:离线
发送短消息息给game 加好友    发送短消息息给game 发消息
发表于: IP:您无权察看 2014-11-13 15:15:09 | [全部帖] [楼主帖] 楼主

参考:http://www.techsiteanalytics.com/index.php/2013/07/19/6288

参考:http://www.techsiteanalytics.com/index.php/2012/11/07/4209

参考:http://www.vmcd.org/2012/04/mysql-high-availability-mha/

学习地址:http://huoding.com/2011/12/18/139

http://qiufengy.blog.51cto.com/391990/848468


另一个学习地址:http://www.uini.net/?p=1833

主库:172.1.3.221

备主(平时从库使用):172.1.3.222

从库:172.1.3.223

Manger的角色:172.1.2.108

软件下载:http://code.google.com/p/mysql-master-ha/

作为前提条件,应先配置MySQL复制,并设置SSH公钥免密码登录。下面以CentOS为例来说明,最好先安装EPEL,不然YUM可能找不到某些软件包。

MHA由Node和Manager组成,Node运行在每一台MySQL服务器上,也就是说,不管是MySQL主服务器,还是MySQL从服务器,都要安装Node,而Manager通常运行在独立的服务器上,但如果硬件资源吃紧,也可以用一台MySQL从服务器来兼职Manager的角色

操作系统版本:

[root@yz-db ~]# cat /etc/issue
CentOS release 5.8 (Final)
Kernel \r on an \m


安装:

在每台机器上安装:

[root@hadoop221/hadoop222/hadoop223/hadoop224 ~]# rpm -ivh epel-release-5-4.noarch.rpm


在主库(172.1.3.221)安装Node节点:

[root@hadoop221 ~]# yum install perl-DBD-MySQL
Setting up Install Process
Package perl-DBD-MySQL-3.0007-2.el5.x86_64 already installed and latest version
[root@hadoop221 ~]# rpm -Uvh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
Retrieving http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
Preparing…                ########################################### [100%]
1:mha4mysql-node         ########################################### [100%]


安装:

在备主(172.1.3.222)安装Node节点:

[root@hadoop222 ~]# yum install perl-DBD-MySQL
Package perl-DBD-MySQL-3.0007-2.el5.x86_64 already installed and latest version
[root@hadoop222 ~]# rpm -Uvh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
Retrieving http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
Preparing…                ########################################### [100%]
1:mha4mysql-node         ########################################### [100%]
[root@hadoop222 ~]#


在从库(172.1.3.223)安装Node节点:

[root@hadoop223 ~]# yum install perl-DBD-MySQL
Package perl-DBD-MySQL-3.0007-2.el5.x86_64 already installed and latest version
[root@hadoop223 ~]#
[root@hadoop223 ~]# rpm -Uvh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
Retrieving http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
Preparing…                ########################################### [100%]
1:mha4mysql-node         ########################################### [100%]
[root@openvpn ~]# yum install perl-DBD-MySQL
[root@openvpn ~]# rpm -Uvh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
———————————————————————————————————————–


(172.1.2.108)安装Manager节点:

[root@hadoop224~]# yum install perl-DBD-MySQL
[root@hadoop224 ~]# yum install perl-Config-Tiny
[root@hadoop224 ~]# yum install perl-Log-Dispatch
[root@hadoop224 ~]# yum install perl-Parallel-ForkManager
[root@hadoop224 ~]# rpm -ivh http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.55-1.el5.noarch.rpm
Retrieving http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.55-1.el5.noarch.rpm
error: Failed dependencies:
mha4mysql-node >= 0.54 is needed by mha4mysql-manager-0.55-1.el5.noarch
perl(MHA::BinlogManager) is needed by mha4mysql-manager-0.55-1.el5.noarch
perl(MHA::NodeConst) is needed by mha4mysql-manager-0.55-1.el5.noarch
perl(MHA::NodeUtil) is needed by mha4mysql-manager-0.55-1.el5.noarch
perl(MHA::SlaveUtil) is needed by mha4mysql-manager-0.55-1.el5.noarch
[root@hadoop224 ~]#  rpm -Uvh http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.54-1.el5.noarch.rpm
[root@hadoop224 ~]# rpm -ivh http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.55-1.el5.noarch.rpm
[root@hadoop224 ~]#


配置全局设置(配置manager):

[root@hadoop224 ~]# masterha_
masterha_check_repl       masterha_check_status     masterha_manager          masterha_master_switch    masterha_stop
masterha_check_ssh        masterha_conf_host        masterha_master_monitor   masterha_secondary_check
[root@hadoop224 ~]# which masterha_manager
/usr/bin/masterha_manager
[root@hadoop224 ~]# which masterha_manager


官方参数:http://code.google.com/p/mysql-master-ha/wiki/Parameters

配置主从关系:

主库:172.1.3.221

配置如下:

server_id=17213221
log-bin=master1-bin
log-bin-index=master1-bin.index
relay_log=mysql-relay-bin
relay_log_index=mysql-relay-bin.index
log_slave_updates= 1
sync_binlog=1
max_binlog_size= 1G
expire_logs_days = 15


备主(平时从库使用):172.1.3.222

配置如下:

# binary logging is required for replication
server_id=17213222
log-bin=master2-bin
log-bin-index=master2-bin.index
relay_log=mysql-relay-bin
relay_log_index=mysql-relay-bin.index
log_slave_updates= 1
max_binlog_size= 1G
expire_logs_days = 15


从库:172.1.3.223

server_id=17213223
log-bin=slave-bin
log-bin-index=slave-bin.index
relay_log=mysql-relay-bin
relay_log_index=mysql-relay-bin.index
log_slave_updates= 1
sync_binlog=1
max_binlog_size= 1G
expire_logs_days = 15
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


主库:172.1.3.221

主库上:

mysql> show master status;


记录下 “File”和“Position”即当前主库使用的二进制日志名称和位置。

设置复制权限:

mysql> create user repl_user;
Query OK, 0 rows affected (0.08 sec)
mysql> grant replication slave on *.* to repl_user@’%’ identified by ‘111111’;
Query OK, 0 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)


备库:172.1.3.222

设置复制权限:

mysql> create user repl_user;
Query OK, 0 rows affected (0.08 sec)
mysql> grant replication slave on *.* to repl_user@’%’ identified by ‘111111’;
Query OK, 0 rows affected (0.06 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.04 sec)


设置备库:172.1.3.222是主库的从库:

MySQL [(none)]> CHANGE MASTER TO MASTER_HOST=’172.1.3.221′,MASTER_USER=’repl_user’,MASTER_PASSWORD=’111111′
,MASTER_LOG_FILE=’master1-bin.000001′,MASTER_LOG_POS=407;
Query OK, 0 rows affected (0.23 sec)
MySQL [(none)]> start slave;
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.1.3.221
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master1-bin.000001
Read_Master_Log_Pos: 407
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 255
Relay_Master_Log_File: master1-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes


设置成功

设置172.1.3.221是172.1.3.222的从库:

MySQL [(none)]> show master status\G
*************************** 1. row ***************************
File: master2-bin.000001
Position: 442
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)
MySQL [(none)]>
mysql> CHANGE MASTER TO MASTER_HOST=’172.1.3.222′,MASTER_USER=’repl_user’,MASTER_PASSWORD=’111111′
,MASTER_LOG_FILE=’master2-bin.000001′,MASTER_LOG_POS=422;
Query OK, 0 rows affected (0.22 sec)
mysql> start slave;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.1.3.222
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master2-bin.000001
Read_Master_Log_Pos: 422
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 255
Relay_Master_Log_File: master2-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes


从库(172.1.3.223)为172.1.3.221的从库:

mysql> CHANGE MASTER TO MASTER_HOST=’172.1.3.221′,MASTER_USER=’repl_user’,MASTER_PASSWORD=’111111′,
MASTER_LOG_FILE=’master1-bin.000001′,MASTER_LOG_POS=407;
Query OK, 0 rows affected (0.53 sec)
mysql> start slave;
Query OK, 0 rows affected (0.03 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.1.3.221
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master1-bin.000001
Read_Master_Log_Pos: 407
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 255
Relay_Master_Log_File: master1-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes


同步完成

设置SSH无密码登录(172.1.2.108)

设置如下

[root@hadoop224 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
e6:a7:01:33:8d:97:bc:c9:f1:ad:dd:cc:da:b7:c1:1a root@hadoop224
[root@hadoop224 ~]#
[root@hadoop224 ~]# cd /root/.ssh/
[root@hadoop224 .ssh]# cp id_rsa.pub authorized_keys
[root@hadoop224 .ssh]# scp -rP22 /root/.ssh 172.1.3.221:/root/
[root@hadoop224 .ssh]# scp -rP22 /root/.ssh 172.1.3.222:/root/
[root@hadoop224 .ssh]# scp -rP22 /root/.ssh 172.1.3.223:/root/


在Manger的角色:172.1.2.108设置配置文件

[root@hadoop224 etc]# mkdir /etc/masterha
[root@hadoop224 etc]# vim /etc/masterha/app1.conf
[root@hadoop224 etc]# mkdir /var/log/masterha/app1
[root@hadoop224 etc]# vim /etc/masterha/app1.conf
[root@hadoop224 app1]# touch /var/log/masterha/app1/manager.log
[server default]
manager_workdir=/var/log/masterha
manager_log=/var/log/masterha/app1/manager.log
#remote_workdir=/usr/local/mysql
user=root
password=111111
ssh_user=root
repl_user=repl
repl_password=111111
ping_interval=1
shutdown_script=””
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change_script
report_script=””
[server1]
hostname=172.1.3.221
master_binlog_dir=/Data/apps/mysql-5.5.12/data
candidate_master=1
[server2]
hostname=172.1.3.222
master_binlog_dir=/mysql
candidate_master=1
[server3]
hostname=172.1.3.223
master_binlog_dir=/Data/apps/mysql-5.5.12/data
no_master=1


测试SSH无密码登录:

[root@hadoop224 etc]# /usr/bin/masterha_check_ssh –conf=/etc/masterha/app1.conf
Sat Aug 17 16:20:54 2013 – [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Aug 17 16:20:54 2013 – [info] Reading application default configurations from /etc/masterha/app1.conf..
Sat Aug 17 16:20:54 2013 – [info] Reading server configurations from /etc/masterha/app1.conf..
Sat Aug 17 16:20:54 2013 – [info] Starting SSH connection tests..
Sat Aug 17 16:20:56 2013 – [debug]
Sat Aug 17 16:20:54 2013 – [debug]  Connecting via SSH from root@172.1.3.221(172.1.3.221:22) to root@172.1.3.222(172.1.3.222:22)..
Warning: Permanently added ‘172.1.3.222’ (RSA) to the list of known hosts.
Sat Aug 17 16:20:55 2013 – [debug]   ok.
Sat Aug 17 16:20:55 2013 – [debug]  Connecting via SSH from root@172.1.3.221(172.1.3.221:22) to root@172.1.3.223(172.1.3.223:22)..
Warning: Permanently added ‘172.1.3.223’ (RSA) to the list of known hosts.
Sat Aug 17 16:20:56 2013 – [debug]   ok.
Sat Aug 17 16:20:56 2013 – [debug]
Sat Aug 17 16:20:55 2013 – [debug]  Connecting via SSH from root@172.1.3.222(172.1.3.222:22) to root@172.1.3.221(172.1.3.221:22)..
Sat Aug 17 16:20:56 2013 – [debug]   ok.
Sat Aug 17 16:20:56 2013 – [debug]  Connecting via SSH from root@172.1.3.222(172.1.3.222:22) to root@172.1.3.223(172.1.3.223:22)..
Warning: Permanently added ‘172.1.3.223’ (RSA) to the list of known hosts.
Sat Aug 17 16:20:56 2013 – [debug]   ok.
Sat Aug 17 16:20:57 2013 – [debug]
Sat Aug 17 16:20:55 2013 – [debug]  Connecting via SSH from root@172.1.3.223(172.1.3.223:22) to root@172.1.3.221(172.1.3.221:22)..
Sat Aug 17 16:20:57 2013 – [debug]   ok.
Sat Aug 17 16:20:57 2013 – [debug]  Connecting via SSH from root@172.1.3.223(172.1.3.223:22) to root@172.1.3.222(172.1.3.222:22)..
Sat Aug 17 16:20:57 2013 – [debug]   ok.
Sat Aug 17 16:20:57 2013 – [info] All SSH connection tests passed successfully.
[root@hadoop224 etc]#


查看复制情况:

[root@hadoop224 etc]# /usr/bin/masterha_check_repl –conf=/etc/masterha/app1.conf
Sat Aug 17 16:23:34 2013 – [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Aug 17 16:23:34 2013 – [info] Reading application default configurations from /etc/masterha/app1.conf..
Sat Aug 17 16:23:34 2013 – [info] Reading server configurations from /etc/masterha/app1.conf..
Sat Aug 17 16:23:34 2013 – [info] MHA::MasterMonitor version 0.55.
Sat Aug 17 16:23:35 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/ServerManager.pm, ln732] Multi-master configuration is detected, but two or more masters are either writable (read-only is not set) or dead! Check configurations for details. Master configurations are as below:
Master 172.1.3.222(172.1.3.222:3306), replicating from 172.1.3.221(172.1.3.221:3306)
Master 172.1.3.221(172.1.3.221:3306), replicating from 172.1.3.222(172.1.3.222:3306)
Sat Aug 17 16:23:35 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations.  at /usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm line 300
Sat Aug 17 16:23:35 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.
Sat Aug 17 16:23:35 2013 – [info] Got exit code 1 (Not master dead).
MySQL Replication Health is NOT OK!


解决:

备主(平时从库使用):172.1.3.222

设置:

read_only=1


出错:

Sat Aug 17 17:33:52 2013 – [info]   Connecting to root@172.1.3.223(172.1.3.223:22)..
mysqlbinlog version is 3.2 (included in MySQL Client 5.0 or lower). This is not recommended. Consider upgrading MySQL Client to 5.1 or higher.
mysqlbinlog is 3.2 (included in MySQL Client 5.0 or lower), but MySQL server version is 5.5.12-log. mysqlbinlog can not parse row based events. Terminating script for safety reasons.
at /usr/bin/apply_diff_relay_logs line 482
Sat Aug 17 17:33:52 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln195] Slaves settings check failed!
Sat Aug 17 17:33:52 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln375] Slave configuration failed.
Sat Aug 17 17:33:52 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations.  at /usr/bin/masterha_check_repl line 48
Sat Aug 17 17:33:52 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.
Sat Aug 17 17:33:52 2013 – [info] Got exit code 1 (Not master dead).
MySQL Replication Health is NOT OK!
[root@hadoop224 ~]#


解决:

登录172.1.3.223

[root@hadoop223 bin]# which mysqlbinlog
/usr/bin/mysqlbinlog
[root@hadoop223 bin]# ln -s /Data/apps/mysql-5.5.12/bin/mysqlbinlog /usr/bin/mysqlbinlog
ln: creating symbolic link `/usr/bin/mysqlbinlog’ to `/Data/apps/mysql-5.5.12/bin/mysqlbinlog': File exists
[root@hadoop223 bin]# rm /usr/bin/mysqlbinlog
rm: remove regular file `/usr/bin/mysqlbinlog’? y
[root@hadoop223 bin]# ln -s /Data/apps/mysql-5.5.12/bin/mysqlbinlog /usr/bin/mysqlbinlog
[root@hadoop223 bin]#


问题解决

[root@hadoop224 ~]# /usr/bin/masterha_check_repl –conf=/etc/masterha/app1.conf
Sat Aug 17 17:38:15 2013 – [info] Checking replication health on 172.1.3.222..
Sat Aug 17 17:38:15 2013 – [info]  ok.
Sat Aug 17 17:38:15 2013 – [info] Checking replication health on 172.1.3.223..
Sat Aug 17 17:38:15 2013 – [info]  ok.
Sat Aug 17 17:38:15 2013 – [warning] master_ip_failover_script is not defined.
Sat Aug 17 17:38:15 2013 – [warning] shutdown_script is not defined.
Sat Aug 17 17:38:15 2013 – [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.
[root@hadoop224 ~]#


启动:

[root@hadoop224 ~]# nohup /usr/bin/masterha_manager –conf=/etc/masterha/app1.cnf > /var/log/masterha/app1/manager.log </dev/null 2>&1 &
[1] 4672


查看所有状态:

[root@hadoop224 ~]# masterha_check_status –conf=/etc/masterha/app1.conf
app1 (pid:4687) is running(0:PING_OK), master:172.1.3.221
[root@hadoop224 ~]#


测试failover过程

登录当前主库(172.1.3.221):

mysql> show slave hosts;
+———–+——+——+———–+
| Server_id | Host | Port | Master_id |
+———–+——+——+———–+
|  17213223 |      | 3306 |  17213221 |
|  17213222 |      | 3306 |  17213221 |
+———–+——+——+———–+
2 rows in set (0.00 sec)
mysql>


关闭当前主库:

[root@hadoop221 data]# /etc/init.d/mysqld stop
Shutting down MySQL…                                     [  OK  ]
[root@hadoop221 data]#


登录从库切换:

[root@hadoop223 bin]# mysql -uroot -p111111
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.5.12-log Source distribution
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.1.3.222
Master_User: repl_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: master2-bin.000003
Read_Master_Log_Pos: 1169
Relay_Log_File: mysql-relay-bin.000002
Relay_Log_Pos: 786
Relay_Master_Log_File: master2-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes


地址换了之前是211.现在是222

查看日志:

Sat Aug 17 17:53:20 2013 – [info] Slaves settings check done.
Sat Aug 17 17:53:20 2013 – [info]
172.1.3.221 (current master)
+–172.1.3.222
+–172.1.3.223
Sat Aug 17 17:53:20 2013 – [warning] master_ip_failover_script is not defined.
Sat Aug 17 17:53:20 2013 – [warning] shutdown_script is not defined.
Sat Aug 17 17:53:20 2013 – [info] Set master ping interval 1 seconds.
Sat Aug 17 17:53:20 2013 – [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Sat Aug 17 17:53:20 2013 – [info] Starting ping health check on 172.1.3.221(172.1.3.221:3306)..
Sat Aug 17 17:53:20 2013 – [info] Ping(SELECT) succeeded, waiting until MySQL doesn’t respond..
Sat Aug 17 17:54:55 2013 – [warning] Got timeout on MySQL Ping child process and killed it! at /usr/lib/perl5/vendor_perl/MHA/HealthCheck.pm line 384.
Sat Aug 17 17:54:55 2013 – [info] Executing SSH check script: save_binary_logs –command=test –start_pos=4 –binlog_dir=/Data/apps/mysql-5.5.12/data –output_file=/var/tmp/save_binary_logs_test –manager_version=0.55 –binlog_prefix=master1-bin
Sat Aug 17 17:54:56 2013 – [info] HealthCheck: SSH to 172.1.3.221 is reachable.
Sat Aug 17 17:54:58 2013 – [info] Ping(SELECT) succeeded, waiting until MySQL doesn’t respond..
Sat Aug 17 17:56:17 2013 – [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Sat Aug 17 17:56:17 2013 – [info] Executing SSH check script: save_binary_logs –command=test –start_pos=4 –binlog_dir=/Data/apps/mysql-5.5.12/data –output_file=/var/tmp/save_binary_logs_test –manager_version=0.55 –binlog_prefix=master1-bin


在切换中…

Sat Aug 17 17:56:17 2013 – [info] HealthCheck: SSH to 172.1.3.221 is reachable.
Sat Aug 17 17:56:18 2013 – [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet’, system error: 111)
Sat Aug 17 17:56:18 2013 – [warning] Connection failed 1 time(s)..
Sat Aug 17 17:56:19 2013 – [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet’, system error: 111)
Sat Aug 17 17:56:19 2013 – [warning] Connection failed 2 time(s)..
Sat Aug 17 17:56:20 2013 – [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet’, system error: 111)
Sat Aug 17 17:56:20 2013 – [warning] Connection failed 3 time(s)..
Sat Aug 17 17:56:20 2013 – [warning] Master is not reachable from health checker!
Sat Aug 17 17:56:20 2013 – [warning] Master 172.1.3.221(172.1.3.221:3306) is not reachable!
Sat Aug 17 17:56:20 2013 – [warning] SSH is reachable.
Sat Aug 17 17:56:20 2013 – [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/masterha/app1.conf again, and trying to connect to all servers to check server status..
Sat Aug 17 17:56:20 2013 – [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Aug 17 17:56:20 2013 – [info] Reading application default configurations from /etc/masterha/app1.conf..
Sat Aug 17 17:56:20 2013 – [info] Reading server configurations from /etc/masterha/app1.conf..
Sat Aug 17 17:56:20 2013 – [info] Dead Servers:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info] Alive Servers:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.222(172.1.3.222:3306)
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.223(172.1.3.223:3306)
Sat Aug 17 17:56:20 2013 – [info] Alive Slaves:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.222(172.1.3.222:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Primary candidate for the new Master (candidate_master is set)
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.223(172.1.3.223:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Not candidate for the new Master (no_master is set)
Sat Aug 17 17:56:20 2013 – [info] Checking slave configurations..
Sat Aug 17 17:56:20 2013 – [info] Checking replication filtering settings..
Sat Aug 17 17:56:20 2013 – [info]  Replication filtering check ok.
Sat Aug 17 17:56:20 2013 – [info] Master is down!
Sat Aug 17 17:56:20 2013 – [info] Terminating monitoring script.
Sat Aug 17 17:56:20 2013 – [info] Got exit code 20 (Master dead).
Sat Aug 17 17:56:20 2013 – [info] MHA::MasterFailover version 0.55.
Sat Aug 17 17:56:20 2013 – [info] Starting master failover.
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] * Phase 1: Configuration Check Phase..
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] Dead Servers:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info] Checking master reachability via mysql(double check)..
Sat Aug 17 17:56:20 2013 – [info]  ok.
Sat Aug 17 17:56:20 2013 – [info] Alive Servers:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.222(172.1.3.222:3306)
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.223(172.1.3.223:3306)
Sat Aug 17 17:56:20 2013 – [info] Alive Slaves:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.222(172.1.3.222:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Primary candidate for the new Master (candidate_master is set)
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.223(172.1.3.223:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Not candidate for the new Master (no_master is set)
Sat Aug 17 17:56:20 2013 – [info] ** Phase 1: Configuration Check Phase completed.
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] * Phase 2: Dead Master Shutdown Phase..
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] Forcing shutdown so that applications never connect to the current master..
Sat Aug 17 17:56:20 2013 – [warning] master_ip_failover_script is not set. Skipping invalidating dead master ip address.
Sat Aug 17 17:56:20 2013 – [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Sat Aug 17 17:56:20 2013 – [info] * Phase 2: Dead Master Shutdown Phase completed.
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] * Phase 3: Master Recovery Phase..
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] * Phase 3.1: Getting Latest Slaves Phase..
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] The latest binary log file/position on all slaves is master1-bin.000002:693
Sat Aug 17 17:56:20 2013 – [info] Latest slaves (Slaves that received relay log files to the latest):
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.222(172.1.3.222:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Primary candidate for the new Master (candidate_master is set)
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.223(172.1.3.223:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Not candidate for the new Master (no_master is set)
Sat Aug 17 17:56:20 2013 – [info] The oldest binary log file/position on all slaves is master1-bin.000002:693
Sat Aug 17 17:56:20 2013 – [info] Oldest slaves:
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.222(172.1.3.222:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Primary candidate for the new Master (candidate_master is set)
Sat Aug 17 17:56:20 2013 – [info]   172.1.3.223(172.1.3.223:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:20 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:20 2013 – [info]     Not candidate for the new Master (no_master is set)
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:20 2013 – [info] * Phase 3.2: Saving Dead Master’s Binlog Phase..
Sat Aug 17 17:56:20 2013 – [info]
Sat Aug 17 17:56:21 2013 – [info] Fetching dead master’s binary logs..
Sat Aug 17 17:56:21 2013 – [info] Executing command on the dead master 172.1.3.221(172.1.3.221:3306): save_binary_logs –command=save –start_file=master1-bin.000002  –start_pos=693 –binlog_dir=/Data/apps/mysql-5.5.12/data –output_file=/var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog –handle_raw_binlog=1 –disable_log_bin=0 –manager_version=0.55
Creating /var/tmp if not exists..    ok.
Concat binary/relay logs from master1-bin.000002 pos 693 to master1-bin.000002 EOF into /var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog ..
Dumping binlog format description event, from position 0 to 107.. ok.
Dumping effective binlog data from /Data/apps/mysql-5.5.12/data/master1-bin.000002 position 693 to tail(712).. ok.
Concat succeeded.
Sat Aug 17 17:56:22 2013 – [info] scp from root@172.1.3.221:/var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog to local:/var/log/masterha/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog succeeded.
Sat Aug 17 17:56:22 2013 – [info] HealthCheck: SSH to 172.1.3.222 is reachable.
Sat Aug 17 17:56:22 2013 – [info] HealthCheck: SSH to 172.1.3.223 is reachable.
Sat Aug 17 17:56:22 2013 – [info]
Sat Aug 17 17:56:22 2013 – [info] * Phase 3.3: Determining New Master Phase..
Sat Aug 17 17:56:22 2013 – [info]
Sat Aug 17 17:56:22 2013 – [info] Finding the latest slave that has all relay logs for recovering other slaves..
Sat Aug 17 17:56:22 2013 – [info] All slaves received relay logs to the same position. No need to resync each other.
Sat Aug 17 17:56:22 2013 – [info] Searching new master from slaves..
Sat Aug 17 17:56:22 2013 – [info]  Candidate masters from the configuration file:
Sat Aug 17 17:56:22 2013 – [info]   172.1.3.222(172.1.3.222:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:22 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:22 2013 – [info]     Primary candidate for the new Master (candidate_master is set)
Sat Aug 17 17:56:22 2013 – [info]  Non-candidate masters:
Sat Aug 17 17:56:22 2013 – [info]   172.1.3.223(172.1.3.223:3306)  Version=5.5.12-log (oldest major version between slaves) log-bin:enabled
Sat Aug 17 17:56:22 2013 – [info]     Replicating from 172.1.3.221(172.1.3.221:3306)
Sat Aug 17 17:56:22 2013 – [info]     Not candidate for the new Master (no_master is set)
Sat Aug 17 17:56:22 2013 – [info]  Searching from candidate_master slaves which have received the latest relay log events..
Sat Aug 17 17:56:22 2013 – [info] New master is 172.1.3.222(172.1.3.222:3306)
Sat Aug 17 17:56:22 2013 – [info] Starting master failover..
Sat Aug 17 17:56:22 2013 – [info]
From:
172.1.3.221 (current master)
+–172.1.3.222
+–172.1.3.223
To:
172.1.3.222 (new master)
+–172.1.3.223
Sat Aug 17 17:56:22 2013 – [info]
Sat Aug 17 17:56:22 2013 – [info] * Phase 3.3: New Master Diff Log Generation Phase..
Sat Aug 17 17:56:22 2013 – [info]
Sat Aug 17 17:56:22 2013 – [info]  This server has all relay logs. No need to generate diff files from the latest slave.
Sat Aug 17 17:56:22 2013 – [info] Sending binlog..
Sat Aug 17 17:56:23 2013 – [info] scp from local:/var/log/masterha/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog to root@172.1.3.222:/var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog succeeded.
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] * Phase 3.4: Master Log Apply Phase..
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
Sat Aug 17 17:56:23 2013 – [info] Starting recovery on 172.1.3.222(172.1.3.222:3306)..
Sat Aug 17 17:56:23 2013 – [info]  Generating diffs succeeded.
Sat Aug 17 17:56:23 2013 – [info] Waiting until all relay logs are applied.
Sat Aug 17 17:56:23 2013 – [info]  done.
Sat Aug 17 17:56:23 2013 – [info] Getting slave status..
Sat Aug 17 17:56:23 2013 – [info] This slave(172.1.3.222)’s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(master1-bin.000002:693). No need to recover from Exec_Master_Log_Pos.
Sat Aug 17 17:56:23 2013 – [info] Connecting to the target slave host 172.1.3.222, running recover script..
Sat Aug 17 17:56:23 2013 – [info] Executing command: apply_diff_relay_logs –command=apply –slave_user=’root’ –slave_host=172.1.3.222 –slave_ip=172.1.3.222  –slave_port=3306 –apply_files=/var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog –workdir=/var/tmp –target_version=5.5.12-log –timestamp=20130817175620 –handle_raw_binlog=1 –disable_log_bin=0 –manager_version=0.55 –slave_pass=xxx
Sat Aug 17 17:56:23 2013 – [info]
Applying differential binary/relay log files /var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog on 172.1.3.222:3306. This may take long time…
Applying log files succeeded.
Sat Aug 17 17:56:23 2013 – [info]  All relay logs were successfully applied.
Sat Aug 17 17:56:23 2013 – [info] Getting new master’s binlog name and position..
Sat Aug 17 17:56:23 2013 – [info]  master2-bin.000003:638
Sat Aug 17 17:56:23 2013 – [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST=’172.1.3.222′, MASTER_PORT=3306, MASTER_LOG_FILE=’master2-bin.000003′, MASTER_LOG_POS=638, MASTER_USER=’repl_user’, MASTER_PASSWORD=’xxx';
Sat Aug 17 17:56:23 2013 – [warning] master_ip_failover_script is not set. Skipping taking over new master ip address.
Sat Aug 17 17:56:23 2013 – [info] Setting read_only=0 on 172.1.3.222(172.1.3.222:3306)..
Sat Aug 17 17:56:23 2013 – [info]  ok.
Sat Aug 17 17:56:23 2013 – [info] ** Finished master recovery successfully.
Sat Aug 17 17:56:23 2013 – [info] * Phase 3: Master Recovery Phase completed.
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] * Phase 4: Slaves Recovery Phase..
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] — Slave diff file generation on host 172.1.3.223(172.1.3.223:3306) started, pid: 4947. Check tmp log /var/log/masterha/172.1.3.223_3306_20130817175620.log if it takes time..
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] Log messages from 172.1.3.223 …
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info]  This server has all relay logs. No need to generate diff files from the latest slave.
Sat Aug 17 17:56:23 2013 – [info] End of log messages from 172.1.3.223.
Sat Aug 17 17:56:23 2013 – [info] — 172.1.3.223(172.1.3.223:3306) has the latest relay log events.
Sat Aug 17 17:56:23 2013 – [info] Generating relay diff files from the latest slave succeeded.
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
Sat Aug 17 17:56:23 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] — Slave recovery on host 172.1.3.223(172.1.3.223:3306) started, pid: 4949. Check tmp log /var/log/masterha/172.1.3.223_3306_20130817175620.log if it takes time..
Sat Aug 17 17:56:25 2013 – [info]
Sat Aug 17 17:56:25 2013 – [info] Log messages from 172.1.3.223 …
Sat Aug 17 17:56:25 2013 – [info]
Sat Aug 17 17:56:23 2013 – [info] Sending binlog..
Sat Aug 17 17:56:24 2013 – [info] scp from local:/var/log/masterha/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog to root@172.1.3.223:/var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog succeeded.
Sat Aug 17 17:56:24 2013 – [info] Starting recovery on 172.1.3.223(172.1.3.223:3306)..
Sat Aug 17 17:56:24 2013 – [info]  Generating diffs succeeded.
Sat Aug 17 17:56:24 2013 – [info] Waiting until all relay logs are applied.
Sat Aug 17 17:56:24 2013 – [info]  done.
Sat Aug 17 17:56:24 2013 – [info] Getting slave status..
Sat Aug 17 17:56:24 2013 – [info] This slave(172.1.3.223)’s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(master1-bin.000002:693). No need to recover from Exec_Master_Log_Pos.
Sat Aug 17 17:56:24 2013 – [info] Connecting to the target slave host 172.1.3.223, running recover script..
Sat Aug 17 17:56:24 2013 – [info] Executing command: apply_diff_relay_logs –command=apply –slave_user=’root’ –slave_host=172.1.3.223 –slave_ip=172.1.3.223  –slave_port=3306 –apply_files=/var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog –workdir=/var/tmp –target_version=5.5.12-log –timestamp=20130817175620 –handle_raw_binlog=1 –disable_log_bin=0 –manager_version=0.55 –slave_pass=xxx
Sat Aug 17 17:56:24 2013 – [info]
Applying differential binary/relay log files /var/tmp/saved_master_binlog_from_172.1.3.221_3306_20130817175620.binlog on 172.1.3.223:3306. This may take long time…
Applying log files succeeded.
Sat Aug 17 17:56:24 2013 – [info]  All relay logs were successfully applied.
Sat Aug 17 17:56:24 2013 – [info]  Resetting slave 172.1.3.223(172.1.3.223:3306) and starting replication from the new master 172.1.3.222(172.1.3.222:3306)..
Sat Aug 17 17:56:25 2013 – [info]  Executed CHANGE MASTER.
Sat Aug 17 17:56:25 2013 – [info]  Slave started.
Sat Aug 17 17:56:25 2013 – [info] End of log messages from 172.1.3.223.
Sat Aug 17 17:56:25 2013 – [info] — Slave recovery on host 172.1.3.223(172.1.3.223:3306) succeeded.
Sat Aug 17 17:56:25 2013 – [info] All new slave servers recovered successfully.
Sat Aug 17 17:56:25 2013 – [info]
Sat Aug 17 17:56:25 2013 – [info] * Phase 5: New master cleanup phase..
Sat Aug 17 17:56:25 2013 – [info]
Sat Aug 17 17:56:25 2013 – [info] Resetting slave info on the new master..
Sat Aug 17 17:56:25 2013 – [info]  172.1.3.222: Resetting slave info succeeded.
Sat Aug 17 17:56:25 2013 – [info] Master failover to 172.1.3.222(172.1.3.222:3306) completed successfully.
Sat Aug 17 17:56:25 2013 – [info]
—– Failover Report —–
app1: MySQL Master failover 172.1.3.221 to 172.1.3.222 succeeded
Master 172.1.3.221 is down!
Check MHA Manager logs at hadoop224:/var/log/masterha/app1/manager.log for details.
Started automated(non-interactive) failover.
The latest slave 172.1.3.222(172.1.3.222:3306) has all relay logs for recovery.
Selected 172.1.3.222 as a new master.
172.1.3.222: OK: Applying all logs succeeded.
172.1.3.223: This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
172.1.3.223: OK: Applying all logs succeeded. Slave started, replicating from 172.1.3.222.
172.1.3.222: Resetting slave info succeeded.
Master failover to 172.1.3.222(172.1.3.222:3306) completed successfully.


成功

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

试下回切:

启动:

[root@hadoop221 data]# /etc/init.d/mysqld start
Starting MySQL..                                           [  OK  ]


测试能能否回来:

[root@hadoop224 ~]# masterha_check_status –conf=/etc/masterha/app1.conf
app1 (pid:5039) is running(0:PING_OK), master:172.1.3.222
[root@hadoop224 ~]#


登录查看172.1.3.221

mysql> show slave hosts;
Empty set (0.00 sec)
mysql>


登录查看172.1.3.222

MySQL [(none)]> show slave hosts;
+———–+——+——+———–+
| Server_id | Host | Port | Master_id |
+———–+——+——+———–+
|  17213221 |      | 3306 |  17213222 |
|  17213223 |      | 3306 |  17213222 |
+———–+——+——+———–+
2 rows in set (0.00 sec)
MySQL [(none)]>


启动172.1.3.221.关闭172.1.3.222

出错:

Sat Aug 17 18:31:38 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterFailover.pm, ln298] Last failover was done at 2013/08/17 17:07:25. Current time is too early to do failover again. If you want to do failover, manually remove /var/log/masterha/app1.failover.complete and run this script again.
Sat Aug 17 18:31:38 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/ManagerUtil.pm, ln178] Got ERROR:  at /usr/bin/masterha_manager line 65


删除提示中的文件:在监控机上:

[root@hadoop224 ~]# rm /var/log/masterha/app1.failover.complete


rm:是否删除 一般空文件 “/var/log/masterha/app1.failover.complete”? y

查看172.1.3.221

mysql> show slave hosts;
+———–+——+——+———–+
| Server_id | Host | Port | Master_id |
+———–+——+——+———–+
|  17213223 |      | 3306 |  17213221 |
+———–+——+——+———–+
1 row in set (0.00 sec)
mysql>


回切:

tail: /var/log/masterha/app1/manager.log: file truncated
Sat Aug 17 19:08:57 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/ServerManager.pm, ln604] There are 2 non-slave servers! MHA manages at most one non-slave server. Check configurations.
Sat Aug 17 19:08:57 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln386] Error happend on checking configurations.  at /usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm line 300
Sat Aug 17 19:08:57 2013 – [error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln482] Error happened on monitoring servers.
Sat Aug 17 19:08:57 2013 – [info] Got exit code 1 (Not master dead).


可能之前是双主的原因,改成单主

master:172.1.3.221
slave :172.1.3.222,172.1.3.223


启动:

[root@hadoop224 ~]# nohup /usr/bin/masterha_manager –conf=/etc/masterha/app1.conf >/var/log/masterha/app1/manager.log </dev/null 2>&1 &


查看:

[root@hadoop224 ~]# /usr/bin/masterha_check_status –conf=/etc/masterha/app1.conf
app1 monitoring program is now on initialization phase(10:INITIALIZING_MONITOR). Wait for a while and try checking again.
[root@hadoop224 ~]# /usr/bin/masterha_check_status –conf=/etc/masterha/app1.conf
app1 monitoring program is now on initialization phase(10:INITIALIZING_MONITOR). Wait for a while and try checking again.
[root@hadoop224 ~]# /usr/bin/masterha_check_status –conf=/etc/masterha/app1.conf
app1 (pid:6763) is running(0:PING_OK), master:172.1.3.221


关闭172.1.3.221主库:

[root@hadoop221 ~]# /etc/init.d/mysqld
mysqld               mysqld_multi.server
[root@hadoop221 ~]# /etc/init.d/mysqld stop
Shutting down MySQL…                                     [  OK  ]
[root@hadoop221 ~]#


出错:

[root@hadoop224 ~]# rm /var/log/masterha/app1.failover.complete


rm:是否删除 一般空文件 “/var/log/masterha/app1.failover.complete”? y

[1]+  Exit 1                  nohup /usr/bin/masterha_manager –conf=/etc/masterha/app1.conf > /var/log/masterha/app1/manager.log < /dev/null 2>&1
[root@hadoop224 ~]# /usr/bin/masterha_check_status –conf=/etc/masterha/app1.conf
app1 is stopped(2:NOT_RUNNING).
———————————————————————————————————————–


命令的使用方法:

[root@hadoop224 ~]# /usr/bin/masterha_master_switch –help
Usage:
# For master failover
masterha_master_switch –master_state=dead
–global_conf=/etc/masterha_default.cnf
–conf=/usr/local/masterha/conf/app1.cnf –dead_master_host=host1
# For online master switch
masterha_master_switch –master_state=alive
–global_conf=/etc/masterha_default.cnf
–conf=/usr/local/masterha/conf/app1.cnf
See online reference
(http://code.google.com/p/mysql-master-ha/wiki/masterha_master_switch)
for details.
[root@hadoop224 ~]#
[root@hadoop224 ~]# /usr/bin/masterha_check_status
Either –conf or –status_dir must be set.
at /usr/lib/perl5/vendor_perl/MHA/ManagerAdminWrapper.pm line 121
[root@hadoop224 ~]#
[root@hadoop224 ~]# /usr/bin/masterha_check_status –conf=/etc/masterha/app1.conf
app1 is stopped(2:NOT_RUNNING).
[root@hadoop224 ~]#
[root@hadoop224 ~]# /usr/bin/masterha_master_monitor
–conf=<server config file> must be set.
[root@hadoop224 ~]#
[root@hadoop224 ~]# /usr/bin/masterha_master_monitor
–conf=<server config file> must be set.
[root@hadoop224 ~]# /usr/bin/masterha_secondary_check
Usage:
masterha_secondary_check -s secondary_host1 -s secondary_host2 ..
–user=ssh_username –master_host=host –master_ip=ip –master_port=port
See online reference
(http://code.google.com/p/mysql-master-ha/wiki/Parameters#secondary_chec
k_script) for details.
[root@hadoop224 ~]#
[root@hadoop224 ~]# masterha_stop
Either –conf or –status_dir must be set.
at /usr/lib/perl5/vendor_perl/MHA/ManagerAdminWrapper.pm line 132
[root@hadoop224 ~]#


调整后的配置文件:

[server default]
manager_workdir=/var/log/masterha
manager_log=/var/log/masterha/app1/manager.log
#remote_workdir=/usr/local/mysql
user=root
password=111111
ssh_user=root
repl_user=repl_user
repl_password=111111
ping_interval=1
shutdown_script=””
#master_ip_failover_script=/usr/local/bin/master_ip_failover
#master_ip_online_change_script=/usr/local/bin/master_ip_online_change_script
report_script=””
[server1]
hostname=172.1.3.221
master_binlog_dir=/Data/apps/mysql-5.5.12/data
candidate_master=1
[server2]
hostname=172.1.3.222
master_binlog_dir=/mysql
candidate_master=1
[server3]
hostname=172.1.3.223
master_binlog_dir=/Data/apps/mysql-5.5.12/data
no_master=1


--转自 北京联动北方科技有限公司




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论