{"id":152930,"date":"2019-08-26T08:21:18","date_gmt":"2019-08-26T00:21:18","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=152930"},"modified":"2019-08-12T17:18:42","modified_gmt":"2019-08-12T09:18:42","slug":"centos7-mha-mysql5","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos7-mha-mysql5.html","title":{"rendered":"MHA\u67b6\u6784\u7684\u5b9e\u73b0\u65b9\u5f0f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nMHA\u76ee\u524d\u5728MySQL\u9ad8\u53ef\u7528\u65b9\u9762\u662f\u4e00\u4e2a\u76f8\u5bf9\u6210\u719f\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5b83\u7531\u65e5\u672cDeNA\u516c\u53f8youshimaton(\u73b0\u5c31\u804c\u4e8eFacebook\u516c\u53f8)\u5f00\u53d1\uff0c\u662f\u4e00\u5957\u4f18\u79c0\u7684\u4f5c\u4e3a\uff1bMySQL\u9ad8\u53ef\u7528\u6027\u73af\u5883\u4e0b\u6545\u969c\u5207\u6362\u548c\u4e3b\u4ece\u63d0\u5347\u7684\u9ad8\u53ef\u7528\u8f6f\u4ef6\u3002\u5728MySQL\u6545\u969c\u5207\u6362\u8fc7\u7a0b\u4e2d\uff0cMHA\u80fd\u505a\u5230\u57280~30\u79d2\u4e4b\u5185\u81ea\u52a8\u5b8c\u6210\u6570\u636e\u5e93\u7684\u6545\u969c\u5207\u6362\u64cd\u4f5c\uff0c\u5e76\u4e14\u5728\u8fdb\u884c\u6545\u969c\u5207\u6362\u7684\u8fc7\u7a0b\u4e2d\uff0cMHA\u80fd\u5728\u6700\u5927\u7a0b\u5ea6\u4e0a\u4fdd\u8bc1\u6570\u636e\u7684\u4e00\u81f4\u6027\uff0c\u4ee5\u8fbe\u5230\u771f\u6b63\u610f\u4e49\u4e0a\u7684\u9ad8\u53ef\u7528\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u5b89\u88c5mysql5.7\uff0c\u5e76\u914d\u7f6e\u597d\u4e3b\u4ece\u590d\u5236<\/strong><\/span><\/div>\n

\u7b2c\u4e00\uff1a\u5b89\u88c5mysql57\uff0c\u5e76\u5173\u95ed\u9632\u706b\u5899<\/p>\n

\r\nyum install epel*  -y && yum clean all && yum makecache \r\nrpm -Uvh http:\/\/repo.mysql.com\/mysql57-community-release-el7.rpm\r\nyum clean all && yum makecache\r\nyum install gcc gcc-c++ openssl-devel mysql mysql-server mysql-devel -y\r\n\r\nsystemctl disable firewalld\r\nsystemctl stop firewalld\r\n\r\nsystemctl start mysqld\r\ncat \/var\/log\/mysqld.log | grep 'password is generated'\t#\u627e\u5230mysql\u521d\u59cb\u5bc6\u7801\r\nmysql_secure_installation\t#\u5bf9mysql\u8fdb\u884c\u5b89\u5168\u52a0\u56fa\r\n<\/pre>\n

\u7b2c\u4e8c\uff1a\u4fee\u6539my.cnf(\u4e09\u53f0\u90fd\u8981\uff0c\u53ea\u6709server-id\u4fee\u6539\u4e3a\u4e0d\u4e00\u6837\u7684\u5c31\u597d\u5566)<\/p>\n

\r\nvi \/etc\/my.cnf\r\n\r\n[client]\r\nuser=root\r\npassword=123456\r\n\r\n[mysqld]\r\ndatadir=\/var\/lib\/mysql\r\nsocket=\/var\/lib\/mysql\/mysql.sock\r\nlog-error=\/var\/log\/mysqld.log\r\npid-file=\/var\/run\/mysqld\/mysqld.pid\r\n\r\n#\u6bcf\u4e2aserver\u4e0a\u4e0d\u4e00\u81f4\uff0c\u89c1\u89c4\u5212\r\nserver-id = 1\r\n#read-only=1\t#\u4e0d\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u9650\u5b9a\u53ea\u8bfb\uff0c\u4f46\u662f\u8981\u8bb0\u5f97\u5728slave\u4e0a\u9650\u5236\u53ea\u8bfb\r\n\r\n#mysql5.6\u5df2\u4e0a\u7684\u7279\u6027\uff0c\u5f00\u542fgtid\uff0c\u5fc5\u987b\u4e3b\u4ece\u5168\u5f00\r\ngtid_mode = on\t\r\nenforce_gtid_consistency = 1\r\nlog_slave_updates = 1\r\n\r\n#\u5f00\u542f\u534a\u540c\u6b65\u590d\u5236  \u5426\u5219\u81ea\u52a8\u5207\u6362\u4e3b\u4ece\u7684\u65f6\u5019\u4f1a\u62a5\u4e3b\u952e\u9519\u8bef\r\nplugin_load = \"rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so\"\r\nloose_rpl_semi_sync_master_enabled = 1\r\nloose_rpl_semi_sync_slave_enabled = 1\r\nloose_rpl_semi_sync_master_timeout = 5000\r\n\r\nlog-bin=mysql-bin\r\nrelay-log = mysql-relay-bin\r\nreplicate-wild-ignore-table=mysql.%\r\nreplicate-wild-ignore-table=test.%\r\nreplicate-wild-ignore-table=information_schema.%\r\n<\/pre>\n

\u7b2c\u4e09\uff1a\u5728 3 \u4e2a mysql \u8282\u70b9\u505a\u6388\u6743\u914d\u7f6e(\u4e3b\u4ece\u590d\u5236\u6388\u6743)<\/p>\n

\r\nmysql> grant replication slave on *.* to 'repl_user'@'192.168.1.%' identified by '123456';\r\nmysql> grant all on *.* to 'root'@'192.168.1.%' identified by '123456'; #\u5f88\u91cd\u8981\r\n<\/pre>\n

\u7b2c\u56db\uff1a\u5728\u4e24\u4e2asalve\u8282\u70b9\u4e0a\u6267\u884c\uff0c\u53ea\u8bfb\u9650\u5236\uff08\u9632\u6b62\u610f\u5916\u88ab\u5199\u6570\u636e\uff0c\u5f88\u91cd\u8981\uff09<\/p>\n

\r\nmysql> set global read_only=1;\r\n<\/pre>\n

\u7b2c\u4e94\uff1a\u5728\u4e3bmaster\u4e0a\u67e5\u770b\u72b6\u6001<\/p>\n

\r\nmysql> show master status;\r\n+------------------+----------+--------------+------------------+-------------------+\r\n| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |\r\n+------------------+----------+--------------+------------------+-------------------+\r\n| mysql-bin.000002 |     1298 |              |                  |                   |\r\n+------------------+----------+--------------+------------------+-------------------+\r\n1 row in set (0.00 sec)\r\n<\/pre>\n

\u7b2c\u516d\uff1a\u5728\u4e24\u4e2aslave\u8282\u70b9\u6267\u884c\u4e0b\u9762\u7684\u64cd\u4f5c<\/p>\n

\r\nmysql> change master to master_host='192.168.1.57',master_user='repl_user',master_password='123456',master_log_file='mysql-bin.000002',master_log_pos=1298;\r\nmysql> start slave;\r\nmysql> show slave status\\G;\t#\u67e5\u770bslave IO\u548cslave sql\u662f\u5426\u90fd\u6b63\u5e38\r\n<\/pre>\n
MHA\u57fa\u672c\u73af\u5883\u51c6\u5907<\/strong><\/span><\/div>\n

\u7b2c\u4e03\uff1a\u914d\u7f6e\u4e09\u53f0\u673a\u5668\u7684ssh\u4e92\u4fe1\uff08\u4e09\u53f0\u90fd\u8981\u64cd\u4f5c\uff09<\/p>\n

\r\nssh-keygen -t rsa\r\nssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.1.56\r\nssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.1.57\r\nssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.1.58\r\n\r\n#\u6d4b\u8bd5\u662f\u5426\u6210\u529f\r\nssh 192.168.1.57 date\r\n<\/pre>\n

\u7b2c\u516b\uff1a\u5b89\u88c5MHA\u8f6f\u4ef6\uff08\u5728\u4e09\u4e2a\u8282\u70b9\u4e0a\u90fd\u88c5mha\u7684node\u8f6f\u4ef6\uff09<\/p>\n

\r\n#\u5148\u5b89\u88c5\u4f9d\u8d56\r\nwget http:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\r\nrpm -ivh epel-release-latest-7.noarch.rpm\r\nyum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager\u3000-y\r\n\r\n\u4e0b\u8f7d\u8f6f\u4ef6\uff08\u65b9\u5f0f\u4efb\u9009\u5176\u4e00\uff09\r\nwget https:\/\/qiniu.wsfnk.com\/mha4mysql-node-0.58-0.el7.centos.noarch.rpm\r\n#wget https:\/\/github.com\/yoshinorim\/mha4mysql-node\/releases\/download\/v0.58\/mha4mysql-node-0.58-0.el7.centos.noarch.rpm\r\nrpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm\r\n<\/pre>\n

\u7b2c\u4e5d\uff1a\u4ec5\u5728manager\u8282\u70b9\u4e0a\u5b89\u88c5mha\u7ba1\u7406\u8f6f\u4ef6<\/p>\n

\r\nwget https:\/\/qiniu.wsfnk.com\/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm\r\n#wget https:\/\/github.com\/yoshinorim\/mha4mysql-manager\/releases\/download\/v0.58\/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm\r\nrpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm\r\nyum install mailx -y\t#\u8be5\u8f6f\u4ef6\u662f\u7528\u6765\u53d1\u9001\u90ae\u4ef6\u7684\r\n<\/pre>\n
\u914d\u7f6eMHA\uff08\u5728manager\u8282\u70b9\u4e0a\u64cd\u4f5c\uff09<\/strong><\/span><\/div>\n

\u521b\u5efa\u76ee\u5f55<\/p>\n

\r\nmkdir -p \/etc\/mha\/scripts\r\n<\/pre>\n

\u7b2c\u5341\uff1a\u914d\u7f6e\u5168\u5c40\u914d\u7f6e\u6587\u4ef6<\/p>\n

\r\nvi \/etc\/masterha_default.cnf\t#\u4e00\u5b9a\u8981\u662f\u8fd9\u4e2a\u8def\u5f84\uff0c\u4e0d\u7136\u540e\u671fmasterha_check_ssh\u4f1a\u63d0\u793a\u672a\u627e\u5230\u5168\u5c40\u6587\u4ef6\r\n\r\n[server default]\r\nuser=root\r\npassword=123456\r\nssh_user=root\r\nrepl_user=repl_user\r\nrepl_password=123456\r\nping_interval=1\r\n#master_binlog_dir= \/var\/lib\/mysql,\/var\/log\/mysql\r\nsecondary_check_script=masterha_secondary_check -s 192.168.1.57 -s 192.168.1.58 -s 192.168.1.56 \r\nmaster_ip_failover_script=\"\/etc\/mha\/scripts\/master_ip_failover\"\r\nmaster_ip_online_change_script=\"\/etc\/mha\/scripts\/master_ip_online_change\"\r\nreport_script=\"\/etc\/mha\/scripts\/send_report\"\r\n<\/pre>\n

\u7b2c\u5341\u4e00\uff1a\u914d\u7f6e\u4e3b\u914d\u7f6e\u6587\u4ef6<\/p>\n

\r\nvi \/etc\/mha\/app1.cnf\r\n\r\n[server default]\r\nmanager_workdir=\/var\/log\/mha\/app1\r\nmanager_log=\/var\/log\/mha\/app1\/manager.log\r\n\r\n[server1]\r\nhostname=192.168.1.57\r\ncandidate_master=1\r\nmaster_binlog_dir=\"\/var\/lib\/mysql\"\r\n#\u67e5\u770b\u65b9\u5f0f\u3000find \/ -name mysql-bin*\r\n\r\n[server2]\r\nhostname=192.168.1.58\r\ncandidate_master=1\r\nmaster_binlog_dir=\"\/var\/lib\/mysql\"\r\n\r\n[server3]\r\nhostname=192.168.1.56\r\nmaster_binlog_dir=\"\/var\/lib\/mysql\"\r\n#\u8868\u793a\u6ca1\u6709\u673a\u4f1a\u6210\u4e3amaster\r\nno_master=1\r\n<\/pre>\n

\u7b2c\u5341\u4e8c\uff1a\u914d\u7f6eVIP<\/p>\n

\r\n#\u4e3a\u4e86\u9632\u6b62\u8111\u88c2\u53d1\u751f,\u63a8\u8350\u751f\u4ea7\u73af\u5883\u91c7\u7528\u811a\u672c\u7684\u65b9\u5f0f\u6765\u7ba1\u7406\u865a\u62df ip,\u800c\u4e0d\u662f\u4f7f\u7528 keepalived\u6765\u5b8c\u6210\u3002\r\nvi \/etc\/mha\/scripts\/master_ip_failover\r\n\r\n#!\/usr\/bin\/env perl\r\nuse strict;\r\nuse warnings FATAL => 'all';\r\nuse Getopt::Long;\r\n\r\nmy (\r\n\t$command,\t$ssh_user,\t$orig_master_host,\r\n\t$orig_master_ip,$orig_master_port, $new_master_host, $new_master_ip,$new_master_port\r\n);\r\n\r\n#\u5b9a\u4e49VIP\u53d8\u91cf\r\nmy $vip = '192.168.1.59\/24';\r\nmy $key = '1';\r\nmy $ssh_start_vip = \"\/sbin\/ifconfig ens192:$key $vip\";\r\nmy $ssh_stop_vip = \"\/sbin\/ifconfig ens192:$key down\";\r\n\r\nGetOptions(\r\n\t'command=s'\t\t=> \\$command,\r\n\t'ssh_user=s'\t\t=> \\$ssh_user,\r\n\t'orig_master_host=s'\t=> \\$orig_master_host,\r\n\t'orig_master_ip=s'\t=> \\$orig_master_ip,\r\n\t'orig_master_port=i'\t=> \\$orig_master_port,\r\n\t'new_master_host=s'\t=> \\$new_master_host,\r\n\t'new_master_ip=s'\t=> \\$new_master_ip,\r\n\t'new_master_port=i'\t=> \\$new_master_port,\r\n);\r\n\r\nexit &main();\r\n\r\nsub main {\r\n\tprint \"\\n\\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\\n\\n\";\r\n\tif ( $command eq \"stop\" || $command eq \"stopssh\" ) {\r\n\t\tmy $exit_code = 1;\r\n\t\teval {\r\n\t\t\tprint \"Disabling the VIP on old master: $orig_master_host \\n\";\r\n\t\t\t&stop_vip();\r\n\t\t\t$exit_code = 0;\r\n\t\t};\r\n\t\tif ($@) {\r\n\t\t\twarn \"Got Error: $@\\n\";\r\n\t\t\texit $exit_code;\r\n\t\t}\r\n\t\texit $exit_code;\r\n\t}\r\n\r\n\telsif ( $command eq \"start\" ) {\r\n\tmy $exit_code = 10;\r\n\teval {\r\n\t\tprint \"Enabling the VIP - $vip on the new master - $new_master_host \\n\";\r\n\t\t&start_vip();\r\n\t\t$exit_code = 0;\r\n\t};\r\n\r\n\tif ($@) {\r\n\t\twarn $@;\r\n\t\texit $exit_code;\r\n\t\t}\r\n\texit $exit_code;\r\n\t}\r\n\r\n\telsif ( $command eq \"status\" ) {\r\n\t\tprint \"Checking the Status of the script.. OK \\n\";\r\n\t\texit 0;\r\n\t}\r\n\telse {\r\n\t\t&usage();\r\n\t\texit 1;\r\n\t}\r\n}\r\n\r\nsub start_vip() {\r\n\t`ssh $ssh_user\\@$new_master_host \\\" $ssh_start_vip \\\"`;\r\n}\r\nsub stop_vip() {\r\n\treturn 0 unless ($ssh_user);\r\n\t`ssh $ssh_user\\@$orig_master_host \\\" $ssh_stop_vip \\\"`;\r\n}\r\nsub usage {\r\n\tprint\r\n\t\"Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\\n\";\r\n}\r\n<\/pre>\n

\u7b2c\u5341\u4e09\uff1a\u914d\u7f6e\u62a5\u8b66\u90ae\u4ef6\u811a\u672c<\/p>\n

\r\n#mail\u90ae\u4ef6\u53d1\u9001\u7a0b\u5e8f\uff0c\u9700\u8981\u5148\u914d\u7f6e\u597d\u53d1\u9001\u8fd9\u4fe1\u606f\r\nvi \/etc\/mail.rc\r\n\r\nset from=xingu@163.com\r\nset smtp=smtp.163.com\r\nset smtp-auth-user=xing\r\n\r\n#\u62ff163\u90ae\u7bb1\u6765\u8bf4\u8fd9\u4e2a\u4e0d\u662f\u5bc6\u7801\uff0c\u800c\u662f\u6388\u6743\u7801\r\nset smtp-auth-password=wqwqwq123\r\nset smtp-auth=login\r\n\r\n#\u8fd9\u662f\u5177\u4f53\u7684\u90ae\u4ef6\u53d1\u9001\u811a\u672c\r\nvi \/etc\/mha\/scripts\/send_report\r\n\r\n#!\/bin\/bash\r\nsource \/root\/.bash_profile\r\n\r\n# \u89e3\u6790\u53d8\u91cf\r\norig_master_host=`echo \"$1\" | awk -F = '{print $2}'`\r\nnew_master_host=`echo \"$2\" | awk -F = '{print $2}'`\r\nnew_slave_hosts=`echo \"$3\" | awk -F = '{print $2}'`\r\nsubject=`echo \"$4\" | awk -F = '{print $2}'`\r\nbody=`echo \"$5\" | awk -F = '{print $2}'`\r\n\r\n#\u5b9a\u4e49\u6536\u4ef6\u4eba\u5730\u5740\r\nemail=\"888118@wsfnk.com\"\r\ntac \/var\/log\/mha\/app1\/manager.log | sed -n 2p | grep 'successfully' > \/dev\/null\r\nif [ $? -eq 0 ]\r\n\tthen\r\n\tmessages=`echo -e \"MHA $subject \u4e3b\u4ece\u5207\u6362\u6210\u529f\\n master:$orig_master_host --> $new_master_host \\n $body \\n \u5f53\u524d\u4ece\u5e93:$new_slave_hosts\"` \r\n\techo \"$messages\" | mail -s \"Mysql \u5b9e\u4f8b\u5b95\u6389\uff0cMHA $subject \u5207\u6362\u6210\u529f\" $email >>\/tmp\/mailx.log 2>&1 \r\n\telse\r\n\tmessages=`echo -e \"MHA $subject \u4e3b\u4ece\u5207\u6362\u5931\u8d25\\n master:$orig_master_host --> $new_master_host \\n $body\" `\r\n\techo \"$messages\" | mail -s \"\"Mysql \u5b9e\u4f8b\u5b95\u6389\uff0cMHA $subject \u5207\u6362\u5931\u8d25\"\" $email >>\/tmp\/mailx.log 2>&1  \r\nfi\r\n<\/pre>\n

\u7b2c\u5341\u56db\uff1a\u914d\u7f6e\u7f16\u5199VIP\u811a\u672c<\/p>\n

\r\nvi \/etc\/mha\/scripts\/master_ip_online_change\r\n#!\/bin\/bash\r\nsource \/root\/.bash_profile\r\nvip=`echo '192.168.1.59\/24'`  #\u8bbe\u7f6eVIP\r\nkey=`echo '1'`\r\n\r\ncommand=`echo \"$1\" | awk -F = '{print $2}'`\r\norig_master_host=`echo \"$2\" | awk -F = '{print $2}'`\r\nnew_master_host=`echo \"$7\" | awk -F = '{print $2}'`\r\norig_master_ssh_user=`echo \"${12}\" | awk -F = '{print $2}'`\r\nnew_master_ssh_user=`echo \"${13}\" | awk -F = '{print $2}'`\r\n\r\n#\u8981\u6c42\u670d\u52a1\u7684\u7f51\u5361\u8bc6\u522b\u540d\u4e00\u6837\uff0c\u90fd\u4e3aens192(\u8fd9\u91cc\u662f)\r\nstop_vip=`echo \"ssh root@$orig_master_host \/usr\/sbin\/ifconfig ens192:$key down\"`\r\nstart_vip=`echo \"ssh root@$new_master_host \/usr\/sbin\/ifconfig ens192:$key $vip\"`\r\n\r\nif [ $command = 'stop' ]\r\n\t then\r\n\t  echo -e \"\\n\\n\\n****************************\\n\"\r\n\t   echo -e \"Disabled thi VIP - $vip on old master: $orig_master_host \\n\"\r\n\t   $stop_vip\r\n\t   if [ $? -eq 0 ]\r\n\t     then\r\n\t\techo \"Disabled the VIP successfully\"\r\n\t      else\r\n\t\techo \"Disabled the VIP failed\"\r\n\t    fi\r\n\t    echo -e \"***************************\\n\\n\\n\"\r\n\t  fi\r\n\r\nif [ $command = 'start' -o $command = 'status' ]\r\n\t  then\r\n\t    echo -e \"\\n\\n\\n*************************\\n\"\r\n\t    echo -e \"Enabling the VIP - $vip on new master: $new_master_host \\n\"\r\n\t    $start_vip\r\n\t    if [ $? -eq 0 ]\r\n\t      then\r\n\t\techo \"Enabled the VIP successfully\"\r\n\t      else\r\n\t\techo \"Enabled the VIP failed\"\r\n\t   fi\r\n\t   echo -e \"***************************\\n\\n\\n\"\r\nfi\r\n<\/pre>\n

\u7b2c\u5341\u4e94\uff1a\u5c06\u811a\u672c\u8d4b\u4e88\u53ef\u6267\u884c\u6743\u9650<\/p>\n

\r\nchmod +x \/etc\/mha\/scripts\/master_ip_failover \r\nchmod +x \/etc\/mha\/scripts\/master_ip_online_change \r\nchmod +x \/etc\/mha\/scripts\/send_report\r\n<\/pre>\n

\u7b2c\u5341\u516d\uff1a\u901a\u8fc7 masterha_check_ssh \u9a8c\u8bc1 ssh \u4fe1\u4efb\u767b\u5f55\u662f\u5426\u6210\u529f<\/p>\n

\r\nmasterha_check_ssh --conf=\/etc\/mha\/app1.cnf\r\nWed May 16 23:17:58 2018 -  All SSH connection tests passed successfully.\t\t#\u8868\u793a\u6240\u6709\u90fd\u6210\u529f\r\n<\/pre>\n

\u7b2c\u5341\u4e03\uff1a\u901a\u8fc7 masterha_check_repl \u9a8c\u8bc1 mysql \u4e3b\u4ece\u590d\u5236\u662f\u5426\u6210\u529f\uff08\u4e0b\u9762\u8f93\u51fa\u8868\u793a\u6d4b\u8bd5\u901a\u8fc7\uff09<\/p>\n

\r\nmasterha_check_repl --conf=\/etc\/mha\/app1.cnf\r\nIN SCRIPT TEST====\/sbin\/ifconfig ens192:1 down==\/sbin\/ifconfig ens192:1 192.168.1.59\/24===\r\nChecking the Status of the script.. OK \r\nWed May 16 23:59:42 2018 -   OK.\r\nWed May 16 23:59:42 2018 -  shutdown_script is not defined.\r\nWed May 16 23:59:42 2018 -  Got exit code 0 (Not master dead).\r\nMySQL Replication Health is OK.\r\n<\/pre>\n
\u542f\u52a8MHA\uff08\u6ce8\u610f\uff1aMHA\u76d1\u63a7\u811a\u672c\u5207\u6362\u4e00\u6b21\u5c31\u4f1a\u9000\u51fa\uff0c\u9700\u8981\u518d\u6b21\u542f\u52a8\uff09<\/strong><\/span><\/div>\n

\u7b2c\u5341\u516b\uff1a\u5148\u5728master\u4e0a\u7ed1\u5b9avip\uff0c(\u53ea\u9700\u8981\u5728master\u7ed1\u5b9a\u8fd9\u4e00\u6b21\uff0c\u4ee5\u540e\u4f1a\u81ea\u52a8\u5207\u6362)<\/p>\n

\r\n\/usr\/sbin\/ifconfig ens192:1 192.168.1.59\/24\r\n<\/pre>\n

\u7b2c\u5341\u4e5d\uff1a\u7136\u540e\u901a\u8fc7 masterha_manager \u542f\u52a8 MHA \u76d1\u63a7(\u5728manager\u89d2\u8272\u4e0a\u6267\u884c)<\/p>\n

\r\nmkdir \/var\/log\/mha\/app1 -p\r\ntouch \/var\/log\/mha\/app1\/manager.log\r\n\r\n#\u542f\u52a8mha\u76d1\u63a7\u8fdb\u7a0b\uff0c\u4e0b\u9762\u662f\u4e00\u6761\u547d\u4ee4\r\nnohup masterha_manager --conf=\/etc\/mha\/app1.cnf --remove_dead_master_conf --ignore_last_failover < \/dev\/null > \/var\/log\/mha\/app1\/manager.log 2>&1 &\r\n\r\n#\u8fd9\u6837 MHA \u7684\u65e5\u5fd7\u4fdd\u5b58\u5728\/var\/log\/masterha\/app1\/manager.log \u4e0b\r\n\u68c0\u67e5MHA\u7684\u542f\u52a8\u72b6\u6001\r\ntailf \/var\/log\/masterha\/app1\/manager.log\r\n\r\n#\u5982\u679c\u6700\u540e\u4e00\u884c\u662f\u5982\u4e0b\uff0c\u8868\u660e\u542f\u52a8\u6210\u529f\r\nPing(SELECT) succeeded, waiting until MySQL doesn\u2019t respond..\r\n<\/pre>\n

\u7b2c\u4e8c\u5341\uff1a\u68c0\u67e5\u96c6\u7fa4\u72b6\u6001<\/p>\n

\r\nmasterha_check_status --conf=\/etc\/mha\/app1.cnf\r\n<\/pre>\n
\u5207\u6362\u6d4b\u8bd5\u4e4b\uff1a\u81ea\u52a8\u5207\u6362\uff08\u6a21\u62dfmaster\u5b95\u4e86\uff09(\u5b9e\u9a8c\u6d4b\u8bd5\u5f53\u7269\u7406\u6545\u969c\u65f6\uff0c\u6ca1\u6709\u6307\u5b9ashutdown_script\u662f\u6ca1\u7528\u7684\uff0c\u4e0d\u5207\u6362)<\/strong><\/span><\/div>\n

\u7b2c\u4e00\uff1a\u8981\u5b9e\u73b0\u81ea\u52a8 Failover,\u5fc5\u987b\u5148\u542f\u52a8 MHA Manager,\u5426\u5219\u65e0\u6cd5\u81ea\u52a8\u5207\u6362<\/p>\n

A\u3001\u6740\u6389\u4e3b\u5e93 mysql \u8fdb\u7a0b,\u6a21\u62df\u4e3b\u5e93\u53d1\u751f\u6545\u969c,\u8fdb\u884c\u81ea\u52a8 failover \u64cd\u4f5c\u3002<\/p>\n

B\u3001\u770b MHA \u5207\u6362\u65e5\u5fd7,\u4e86\u89e3\u6574\u4e2a\u5207\u6362\u8fc7\u7a0b<\/p>\n

\u7b2c\u4e8c\uff1a\u4ece\u4e0a\u9762\u7684\u8f93\u51fa\u53ef\u4ee5\u770b\u51fa\u6574\u4e2a MHA \u7684\u5207\u6362\u8fc7\u7a0b,\u5171\u5305\u62ec\u4ee5\u4e0b\u7684\u6b65\u9aa4\uff1a<\/p>\n

1).\u914d\u7f6e\u6587\u4ef6\u68c0\u67e5\u9636\u6bb5,\u8fd9\u4e2a\u9636\u6bb5\u4f1a\u68c0\u67e5\u6574\u4e2a\u96c6\u7fa4\u914d\u7f6e\u6587\u4ef6\u914d\u7f6e;<\/p>\n

2).\u5b95\u673a\u7684 master \u5904\u7406,\u8fd9\u4e2a\u9636\u6bb5\u5305\u62ec\u865a\u62df ip \u6458\u9664\u64cd\u4f5c,\u4e3b\u673a\u5173\u673a\u64cd\u4f5c\uff08\u7531\u4e8e\u6ca1\u6709\u5b9a\u4e49power_manager\u811a\u672c\uff0c\u4e0d\u4f1a\u5173\u673a\uff09;<\/p>\n

3).\u590d\u5236 dead maste \u548c\u6700\u65b0 slave \u76f8\u5dee\u7684 relay log,\u5e76\u4fdd\u5b58\u5230 MHA Manger \u5177\u4f53\u7684\u76ee\u5f55\u4e0b;<\/p>\n

4).\u8bc6\u522b\u542b\u6709\u6700\u65b0\u66f4\u65b0\u7684 slave;<\/p>\n

5).\u5e94\u7528\u4ece master \u4fdd\u5b58\u7684\u4e8c\u8fdb\u5236\u65e5\u5fd7\u4e8b\u4ef6(binlog events)\uff08\u8fd9\u70b9\u4fe1\u606f\u5bf9\u4e8e\u5c06\u6545\u969cmaster\u4fee\u590d\u540e\u52a0\u5165\u96c6\u7fa4\u5f88\u91cd\u8981\uff09;<\/p>\n

6).\u63d0\u5347\u4e00\u4e2a slave \u4e3a\u65b0\u7684 master \u8fdb\u884c\u590d\u5236;<\/p>\n

7).\u4f7f\u5176\u4ed6\u7684 slave \u8fde\u63a5\u65b0\u7684 master \u8fdb\u884c\u590d\u5236\u3002<\/p>\n

\u7b2c\u4e09\uff1a\u5207\u6362\u5b8c\u6210\u540e,\u5173\u6ce8\u5982\u4e0b\u53d8\u5316:<\/p>\n

1\u3001vip \u81ea\u52a8\u4ece\u539f\u6765\u7684 master \u5207\u6362\u5230\u65b0\u7684 master,\u540c\u65f6,manager \u8282\u70b9\u7684\u76d1\u63a7\u8fdb\u7a0b\u81ea\u52a8\u9000\u51fa\u3002<\/p>\n

2\u3001\u5728\u65e5\u5fd7\u76ee\u5f55(\/var\/log\/mha\/app1)\u4ea7\u751f\u4e00\u4e2a app1.failover.complete \u6587\u4ef6<\/p>\n

3\u3001\/etc\/mha\/app1.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u539f\u6765\u8001\u7684 master \u914d\u7f6e\u88ab\u5220\u9664\u3002<\/p>\n

\u5207\u6362\u6d4b\u8bd5\u4e4b\uff1a\u5728\u7ebf\u5207\u6362\uff08\u7528\u4e8e\u786c\u4ef6\u5347\u7ea7\uff09(\u5f88\u597d\u4f7f)<\/strong><\/span><\/div>\n

MHA \u5728\u7ebf\u5207\u6362\u662f MHA \u9664\u4e86\u81ea\u52a8\u76d1\u63a7\u5207\u6362\u6362\u63d0\u4f9b\u7684\u53e6\u5916\u4e00\u79cd\u65b9\u5f0f,\u591a\u7528\u4e8e\u8bf8\u5982\u786c\u4ef6\u5347\u7ea7\uff0cMySQL \u6570\u636e\u5e93\u8fc1\u79fb\u7b49\u7b49\u3002\u8be5\u65b9\u5f0f\u63d0\u4f9b\u5feb\u901f\u5207\u6362\u548c\u4f18\u96c5\u7684\u963b\u585e\u5199\u5165,\u65e0\u5173\u5173\u95ed\u539f\u6709\u670d\u52a1\u5668\uff0c\u6574\u4e2a\u5207\u6362\u8fc7\u7a0b\u5728 0.5-2s \u7684\u65f6\u95f4\u5de6\u53f3,\u5927\u5927\u51cf\u5c11\u4e86\u505c\u673a\u65f6\u95f4<\/p>\n

\u7b2c\u4e00\uff1a\u6ce8\u610f\u70b9\uff1a\u524d\u63d0\uff0cmha\u76d1\u63a7\u6ca1\u6709\u8fd0\u884c\u7684\u60c5\u51b5\u4e0b\uff0c\u624d\u80fd\u8fdb\u884c<\/p>\n

A\u3001\u8001master\u4e0a\u7684vip\u5df2\u7ecf\u6b63\u786e\u751f\u6548\u4e86<\/p>\n

B\u3001\u5404\u4e2asalve\u8282\u70b9\u6570\u636e\u5e93\u7684sql_IO\u548csql_sql\u8fdb\u7a0b\u90fd\u6b63\u5e38\uff08\u5373YES)<\/p>\n

\r\nshow slave status\\G;\r\n<\/pre>\n

C\u3001MHA\u811a\u672c\u4e0d\u80fd\u8fd0\u884c\uff0c\u82e5\u5df2\u5904\u4e8e\u76d1\u63a7\u72b6\u6001\uff0c\u9700\u8981\u505c\u6389\u5b83<\/p>\n

\r\nmasterha_stop --conf=\/etc\/mha\/app1.cnf\r\n<\/pre>\n

#\u82e5\u662fmha\u76d1\u63a7\u8fdb\u7a0b\u5728\u8fd0\u884c\uff0c\u4f1a\u62a5\u5982\u4e0b\u9519\u8bef<\/p>\n

\r\nSat May 19 03:40:00 2018 - [error][\/usr\/share\/perl5\/vendor_perl\/MHA\/MasterRotate.pm, ln143] Getting advisory lock failed on the current master. MHA Monitor runs on the current master. Stop MHA Manager\/Monitor and try again.\r\nSat May 19 03:40:00 2018 - [error][\/usr\/share\/perl5\/vendor_perl\/MHA\/ManagerUtil.pm, ln177] Got ERROR:  at \/usr\/bin\/masterha_master_switch line 53.\r\n<\/pre>\n

\u7b2c\u4e8c\uff1a\u6267\u884c\u5207\u6362<\/p>\n

#\u9700\u8981\u586b\u5199\u65b0\u7684master\u7684IP<\/p>\n

\r\nmasterha_master_switch --conf=\/etc\/mha\/app1.cnf --master_state=alive --new_master_host=192.168.1.57 --orig_master_is_new_slave --running_updates_limit=10000 --interactive=0\r\n<\/pre>\n

\u7b2c\u4e09\uff1aMHA \u5728\u7ebf\u5207\u6362\u57fa\u672c\u6b65\u9aa4\uff1a<\/p>\n

a\u3001\u68c0\u6d4b MHA \u914d\u7f6e\u7f6e\u53ca\u786e\u8ba4\u5f53\u524d master;<\/p>\n

b\u3001\u51b3\u5b9a\u65b0\u7684 master;<\/p>\n

c\u3001\u963b\u585e\u5199\u5165\u5230\u5f53\u524d master;<\/p>\n

d\u3001\u7b49\u5f85\u6240\u6709\u4ece\u670d\u52a1\u5668\u4e0e\u73b0\u6709 master \u5b8c\u6210\u540c\u6b65;<\/p>\n

e\u3001\u5728\u65b0 master \u6388\u4e88\u5199\u6743\u9650,\u4ee5\u53ca\u5e76\u884c\u5207\u6362\u4ece\u5e93;<\/p>\n

f\u3001\u91cd\u7f6e\u539f master \u4e3a\u65b0 master \u7684 slave;<\/p>\n

g\u3001\u5728\u7ebf\u5207\u6362\u4e0d\u4f1a\u5220\u9664\/etc\/mha\/app1.cnf \u914d\u7f6e\u6587\u4ef6\u4e2d\u539f\u6765\u8001\u7684 master \u914d\u7f6e;<\/p>\n

\u5982\u4f55\u5c06\u6545\u969c\u8282\u70b9\u91cd\u65b0\u52a0\u5165\u96c6\u7fa4<\/strong><\/span><\/div>\n

\u901a\u5e38\u60c5\u51b5\u4e0b\u81ea\u52a8\u5207\u6362\u4ee5\u540e,\u539f master \u53ef\u80fd\u5df2\u7ecf\u5e9f\u5f03\u6389,\u5f85\u539f master \u4e3b\u673a\u4fee\u590d\u540e,\u5982\u679c\u6570\u636e\u5b8c\u6574\u7684\u60c5\u51b5\u4e0b,\u53ef\u80fd\u60f3\u628a\u539f\u6765 master \u91cd\u65b0\u4f5c\u4e3a\u65b0\u4e3b\u5e93\u7684 slave,\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u501f\u52a9\u5f53\u65f6\u81ea\u52a8\u5207\u6362\u65f6\u523b\u7684 MHA \u65e5\u5fd7\u6765\u5b8c\u6210\u5bf9\u539f master \u7684\u4fee\u590d\u3002(\u82e5\u662f\u4e0b\u9762\u7b2c\u4e8c\u6b65\uff1a\u51fa\u73b0\u7684\u662f\u7b2c\u4e8c\u79cd\uff0c\u53ef\u4ee5\u4e0d\u7528\u501f\u52a9\u65e5\u5fd7\uff0c\u5b9a\u4f4dbinlog\u65e5\u5fd7\u70b9\uff0c\u53ef\u4ee5\u81ea\u52a8\u5b9a\u4f4d)<\/p>\n

(1)\u3001\u4fee\u6539 manager \u914d\u7f6e\u6587\u4ef6\uff08\u53ea\u9488\u5bf9\u81ea\u52a8\u5207\u6362\u7684\uff0c\u5728\u7ebf\u5207\u6362\u4e0d\u4f1a\u5220\u9664\u914d\u7f6e\uff09<\/p>\n

\r\n#\u5c06\u5982\u4e0b\u5185\u5bb9\u6dfb\u52a0\u5230\/etc\/mha\/app1.conf \u4e2d\r\n[server1]\r\nhostname=192.168.1.57\r\ncandidate_master=1\r\nmaster_binlog_dir=\"\/var\/lib\/mysql\"\r\n<\/pre>\n

(2)\u3001\u4fee\u590d\u8001\u7684 master,\u7136\u540e\u8bbe\u7f6e\u4e3a slave<\/p>\n

\u4ece\u81ea\u52a8\u5207\u6362\u65f6\u523b\u7684 MHA \u65e5\u5fd7\u4e0a\u53ef\u4ee5\u53d1\u73b0\u7c7b\u4f3c\u5982\u4e0b\u4fe1\u606f\uff1a\u610f\u601d\u662f\u8bf4,\u5982\u679c Master \u4e3b\u673a\u4fee\u590d\u597d\u4e86,\u53ef\u4ee5\u5728\u4fee\u590d\u597d\u540e\u7684 Master \u4e0a\u6267\u884c CHANGE MASTER\u64cd\u4f5c,\u4f5c\u4e3a\u65b0\u7684 slave \u5e93\u3002<\/p>\n

\r\ncat \/var\/log\/mha\/app1\/manager.log\r\nSat May 27 14:59:17 2017 -  All other slaves should start replication from here. Statement\r\nshould be: CHANGE MASTER TO MASTER_HOST='172.16.213.232', MASTER_PORT=3306,\r\nMASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=120, MASTER_USER='repl_user',\r\nMASTER_PASSWORD='xxx';\r\n#\u6216\u5219\r\nSat May 19 05:00:48 2018 -  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.1.58', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl_user', MASTER_PASSWORD='xxx';\r\n<\/pre>\n

\u5728\u8001\u7684 master \u6267\u884c\u5982\u4e0b\u547d\u4ee4:(\u5177\u4f53\u6267\u884c\u54ea\u6761\uff0c\u6839\u636e\u4e0a\u9762\u8f93\u51fa\u6765\u786e\u5b9a\uff0c\u533a\u522b\u662f\u4e00\u4e2a\u6709\u65e5\u5fd7\u7684\u5b9a\u4f4d\uff0c\u4e00\u4e2a\u662f\u81ea\u52a8\u5b9a\u4f4d)<\/p>\n

\r\nmysql> change master to master_host='192.168.1.57',master_user='repl_user',master_password='123456',master_log_file='mysql-bin.0000124',master_log_pos=234;\r\n#\u6216\u5219\r\nmysql> change master to master_host='192.168.1.57',master_user='repl_user',master_password='123456',MASTER_AUTO_POSITION=1;\r\nmysql> start slave;\r\nmysql> show slave status\\G;\r\n<\/pre>\n

\u8fd9\u6837,\u6570\u636e\u5c31\u5f00\u59cb\u540c\u6b65\u5230\u8001\u7684 master \u4e0a\u4e86\u3002\u6b64\u65f6\u8001\u7684 master \u5df2\u7ecf\u91cd\u65b0\u52a0\u5165\u96c6\u7fa4,\u53d8\u6210 mha\u96c6\u7fa4\u4e2d\u7684\u4e00\u4e2a slave \u89d2\u8272\u4e86\u3002<\/p>\n

(3)\u3001\u5728 manger \u8282\u70b9\u4e0a\u91cd\u65b0\u542f\u52a8\u76d1\u63a7\u8fdb\u7a0b<\/p>\n

\r\nnohup masterha_manager --conf=\/etc\/mha\/app1.cnf --remove_dead_master_conf --ignore_last_failover < \/dev\/null > \/var\/log\/mha\/app1\/manager.log 2>&1 &\r\n<\/pre>\n
\u9644\uff1aMHA\u5207\u6362\u9636\u6bb5\u7684\u5de5\u4f5c\u5177\u4f53\u5e72\u4e86\u90a3\u4e9b\u4e8b<\/strong><\/span><\/div>\n

https:\/\/blog.csdn.net\/shiyu1157758655\/article\/details\/70242093<\/a><\/p>\n

\u9644\uff1a\u9ad8\u4fca\u5cf0\u8001\u5e08\u7684\u8bfe\u4ef6\u4ee5\u4f9b\u5b66\u4e60<\/strong><\/span><\/div>\n

https:\/\/qiniu.wsfnk.com\/%E7%AC%AC12%E8%AF%BE-4%E4%BC%81%E4%B8%9A%E5%B8%B8%E8%A7%81MySQL%E6%9E%B6%E6%9E%84%E5%BA%94%E7%94%A8%E5%AE%9E%E6%88%98%E4%B9%8BMHA%E6%9E%B6%E6%9E%84.pdf<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"

\u7b2c\u4e00\uff1a\u5b89\u88c5mysql57\uff0c\u5e76\u5173\u95ed\u9632\u706b\u5899 yum install epel* -y && yum clean a […]<\/p>\n","protected":false},"author":668,"featured_media":152934,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-152930","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/152930","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/668"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=152930"}],"version-history":[{"count":7,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/152930\/revisions"}],"predecessor-version":[{"id":154124,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/152930\/revisions\/154124"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/152934"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=152930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=152930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=152930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}