MySQL笔记-MHA(Master High Availability)搭建
生活随笔
收集整理的這篇文章主要介紹了
MySQL笔记-MHA(Master High Availability)搭建
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
這里以在Linux上個(gè)演示。
這里在SSH免密碼登錄的前提上個(gè)進(jìn)行設(shè)置的。
如何設(shè)置免密登錄,請(qǐng)看前一篇博文,或者搜索下,在此不再給出鏈接。
?
同樣的3臺(tái)主機(jī)
| 名稱 | ip |
| Centos 7 MySQL Master | 192.168.79.134 |
| Centos 7 MySQL Slave | 192.168.79.136 |
| Centos 7 MySQL Manager | 192.168.79.137 |
?
三臺(tái)主機(jī)全部安裝依賴:
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上個(gè),也就是192.168.79.137的機(jī)器上個(gè)安裝控制端:
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機(jī)器上個(gè)添加如下文件/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這里改創(chuàng)建新路徑要?jiǎng)?chuàng)建,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如下測(cè)試條命令:
[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.第二個(gè):
[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 ~]#?
總結(jié)
以上是生活随笔為你收集整理的MySQL笔记-MHA(Master High Availability)搭建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Java笔记-ConcurrentLin
- 下一篇: HTTPS|SSL笔记-SSL双向认证成