日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

MySQL笔记-MHA(Master High Availability)搭建

發布時間:2025/3/15 数据库 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 MySQL笔记-MHA(Master High Availability)搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這里以在Linux上個演示。

這里在SSH免密碼登錄的前提上個進行設置的。

如何設置免密登錄,請看前一篇博文,或者搜索下,在此不再給出鏈接。

?

同樣的3臺主機

名稱ip
Centos 7 MySQL Master192.168.79.134
Centos 7 MySQL Slave192.168.79.136
Centos 7 MySQL Manager

192.168.79.137

?

三臺主機全部安裝依賴:

yum install perl-DBD-MySQL yum install perl-DBI yum install mysql-libs get http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm rpm -ivh epel-release-latest-7.noarch.rpm yum install -y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager

然后在Manager上個,也就是192.168.79.137的機器上個安裝控制端:

wget https://qiniu.wsfnk.com/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

隨后在Manager機器上個添加如下文件/etc/app1.cnf

[server default] manager_workdir=/var/log/mha/app1 manager_log=/var/log/mha/app1/manager.log user=root password=root ssh_user=root repl_user=rep1 repl_password=rep1 ping_interval=1[server1] hostname=192.168.79.134 port=3306 master_binlog_dir=/u01/mysql3306/log/binlog candidate_master=1 check_repl_delay=0[server2] hostname=192.168.79.136 port=3306 master_binlog_dir=/u01/mysql3306/log/binlog candidate_master=1 check_repl_delay=0

這里改創建新路徑要創建,master_binlog_dir需要改的就要改。

下面是一些常用命令:

masterha_check_ssh --conf=/etc/app1.cnf masterha_check_repl --conf=/etc/app1.cnf masterha_manager --conf=/etc/app1.cnf masterha_check_status --conf=/etc/app1.cnf masterha_stop --conf=/etc/app1.cnf

如下測試條命令:

[root@localhost ~]# masterha_check_ssh --conf=/etc/app1.cnf Sat Jun 6 14:03:39 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sat Jun 6 14:03:39 2020 - [info] Reading application default configuration from /etc/app1.cnf.. Sat Jun 6 14:03:39 2020 - [info] Reading server configuration from /etc/app1.cnf.. Sat Jun 6 14:03:39 2020 - [info] Starting SSH connection tests.. Sat Jun 6 14:03:39 2020 - [debug] Sat Jun 6 14:03:39 2020 - [debug] Connecting via SSH from root@192.168.79.134(192.168.79.134:22) to root@192.168.79.136(192.168.79.136:22).. Sat Jun 6 14:03:39 2020 - [debug] ok. Sat Jun 6 14:03:40 2020 - [debug] Sat Jun 6 14:03:39 2020 - [debug] Connecting via SSH from root@192.168.79.136(192.168.79.136:22) to root@192.168.79.134(192.168.79.134:22).. Sat Jun 6 14:03:39 2020 - [debug] ok. Sat Jun 6 14:03:40 2020 - [info] All SSH connection tests passed successfully.

第二個:

[root@localhost ~]# masterha_check_repl --conf=/etc/app1.cnf Sat Jun 6 16:36:33 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. Sat Jun 6 16:36:33 2020 - [info] Reading application default configuration from /etc/app1.cnf.. Sat Jun 6 16:36:33 2020 - [info] Reading server configuration from /etc/app1.cnf.. Sat Jun 6 16:36:33 2020 - [info] MHA::MasterMonitor version 0.58. Sat Jun 6 16:36:34 2020 - [info] GTID failover mode = 0 Sat Jun 6 16:36:34 2020 - [info] Dead Servers: Sat Jun 6 16:36:34 2020 - [info] Alive Servers: Sat Jun 6 16:36:34 2020 - [info] mydb1(192.168.79.134:3306) Sat Jun 6 16:36:34 2020 - [info] mydb2(192.168.79.136:3306) Sat Jun 6 16:36:34 2020 - [info] Alive Slaves: Sat Jun 6 16:36:34 2020 - [info] mydb2(192.168.79.136:3306) Version=5.7.25-log (oldest major version between slaves) log-bin:enabled Sat Jun 6 16:36:34 2020 - [info] Replicating from 192.168.79.134(192.168.79.134:3306) Sat Jun 6 16:36:34 2020 - [info] Primary candidate for the new Master (candidate_master is set) Sat Jun 6 16:36:34 2020 - [info] Current Alive Master: mydb1(192.168.79.134:3306) Sat Jun 6 16:36:34 2020 - [info] Checking slave configurations.. Sat Jun 6 16:36:34 2020 - [info] read_only=1 is not set on slave mydb2(192.168.79.136:3306). Sat Jun 6 16:36:34 2020 - [warning] relay_log_purge=0 is not set on slave mydb2(192.168.79.136:3306). Sat Jun 6 16:36:34 2020 - [info] Checking replication filtering settings.. Sat Jun 6 16:36:34 2020 - [info] binlog_do_db= , binlog_ignore_db= Sat Jun 6 16:36:34 2020 - [info] Replication filtering check ok. Sat Jun 6 16:36:34 2020 - [info] GTID (with auto-pos) is not supported Sat Jun 6 16:36:34 2020 - [info] Starting SSH connection tests.. Sat Jun 6 16:36:35 2020 - [info] All SSH connection tests passed successfully. Sat Jun 6 16:36:35 2020 - [info] Checking MHA Node version.. Sat Jun 6 16:36:35 2020 - [info] Version check ok. Sat Jun 6 16:36:35 2020 - [info] Checking SSH publickey authentication settings on the current master.. Sat Jun 6 16:36:35 2020 - [info] HealthCheck: SSH to mydb1 is reachable. Sat Jun 6 16:36:36 2020 - [info] Master MHA Node version is 0.58. Sat Jun 6 16:36:36 2020 - [info] Checking recovery script configurations on mydb1(192.168.79.134:3306).. Sat Jun 6 16:36:36 2020 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/u01/mysql3306/log/binlog --output_file=/var/tmp/save_binary_logs_test --manager_version=0.58 --start_file=binlog.000054 Sat Jun 6 16:36:36 2020 - [info] Connecting to root@192.168.79.134(mydb1:22).. Creating /var/tmp if not exists.. ok.Checking output directory is accessible or not..ok.Binlog found at /u01/mysql3306/log/binlog, up to binlog.000054 Sat Jun 6 16:36:36 2020 - [info] Binlog setting check done. Sat Jun 6 16:36:36 2020 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers.. Sat Jun 6 16:36:36 2020 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=mydb2 --slave_ip=192.168.79.136 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.25-log --manager_version=0.58 --relay_log_info=/u01/mysql3306/log/relay-log.info --relay_dir=/u01/mysql3306/data/ --slave_pass=xxx Sat Jun 6 16:36:36 2020 - [info] Connecting to root@192.168.79.136(mydb2:22).. Checking slave recovery environment settings..Opening /u01/mysql3306/log/relay-log.info ... ok.Relay log found at /u01/mysql3306/log, up to relaylog.000002Temporary relay log file is /u01/mysql3306/log/relaylog.000002Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.Testing mysql connection and privileges.. mysql: [Warning] Using a password on the command line interface can be insecure.done.Testing mysqlbinlog output.. done.Cleaning up test file(s).. done. Sat Jun 6 16:36:36 2020 - [info] Slaves settings check done. Sat Jun 6 16:36:36 2020 - [info] mydb1(192.168.79.134:3306) (current master)+--mydb2(192.168.79.136:3306)Sat Jun 6 16:36:36 2020 - [info] Checking replication health on mydb2.. Sat Jun 6 16:36:36 2020 - [info] ok. Sat Jun 6 16:36:36 2020 - [warning] master_ip_failover_script is not defined. Sat Jun 6 16:36:36 2020 - [warning] shutdown_script is not defined. Sat Jun 6 16:36:36 2020 - [info] Got exit code 0 (Not master dead).MySQL Replication Health is OK. [root@localhost ~]#

?

總結

以上是生活随笔為你收集整理的MySQL笔记-MHA(Master High Availability)搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。