Mysql 主从复制+MHA搭建
Mysql半雙工主從復(fù)制
https://blog.csdn.net/qq_35349982/article/details/108558868
繼續(xù)主從復(fù)制之后的MHA搭建
master-1 192.168.182.128
slave-1 192.168.182.132
slave-2 192.168.182.130
mha-1 192.168.182.133
準(zhǔn)備工作
關(guān)閉防火墻
1.機(jī)器都要做關(guān)閉防火墻:
systemctl stop firewalld.servicesystemctl disable firewalld.servicesystemctl status firewalld.service2. ssh互通環(huán)境
實(shí)現(xiàn)遠(yuǎn)程控制及數(shù)據(jù)管理功能:
在Manager節(jié)點(diǎn)生成密鑰對(duì)兒,并設(shè)置其可遠(yuǎn)程連接本地主機(jī)后, 將私鑰文件及authorized_keys文件復(fù)制給余下的所有節(jié)點(diǎn)即可。
#master (在root目錄下創(chuàng)建密鑰,不需要輸密鑰,一路回車(chē)鍵) ssh-keygen -t rsa #一定要用root用戶執(zhí)行,否則權(quán)限不夠 #復(fù)制給其他節(jié)點(diǎn)的時(shí)候,還要再輸入服務(wù)器的密碼 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.132 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.130 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.133 ##復(fù)制給其他節(jié)點(diǎn) #salve1 ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.130 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.128 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.133 #salve2 ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.132 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.128 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.133 #mh1 ssh-keygen -t rsa ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.132 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.128 ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.182.130補(bǔ)充
#查看生成公鑰 cat ~/.ssh/id_rsa.pub參考:
https://www.jianshu.com/p/4d3888e116b2
MHA搭建
前提:ssh互通環(huán)境
1. MHA安裝之前需要先安裝這兩個(gè)查詢依賴,不然可能會(huì)安裝失敗
yum install perl-ExtUtils-MakeMaker yum install perl-Test-Simple2. 四個(gè)節(jié)點(diǎn)都需安裝node(mha服務(wù)額外安裝一個(gè)mannger服務(wù))
yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpmmaster節(jié)點(diǎn)與連兩個(gè)slave節(jié)點(diǎn)需要安裝perl包(三個(gè)節(jié)點(diǎn)都執(zhí)行)
#(進(jìn)入mysql授權(quán)命令)MHA的管理賬號(hào) grant all privileges on *.* to 'mhamanger'@'%' identified by 'mhamanger'; flush privileges;3. 在MHA節(jié)點(diǎn)上安裝(二選一)
有兩個(gè)安裝方法:選一個(gè)就行,我是用的方案二,安裝的特別慢
- 安裝MHA方案一:
安裝本地的mha4mysql-manager-0.58-0.el7.centos.noarch.rpm的文件
yum install perl-DBD-MySQL -y rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm yum install -y epel-release #安裝perl包依賴的時(shí)候,可能會(huì)報(bào)錯(cuò),執(zhí)?以下命令即可: sed -i 's#https://#http://#g' /etc/yum.repos.d/epel*repo yum install -y perl-Config-Tiny perl-Log-Dispatch perl-ParallelForkManager perl-Time-HiRes rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm- 安裝MHA方案二:
去官網(wǎng)下載,tar的安裝包,初始化安裝
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes # 去下載manger的版本 https://github.com/yoshinorim/mha4mysql-manager/releases ##mha4mysql-manager-0.58.tar.gz cd /usr/local/src ##解壓 tar xf mha4mysql-node-0.57.tar.gz #進(jìn)目錄 cd mha4mysql-node-0.57 ##下面這步可能會(huì)失敗,要安裝一個(gè) perl perl Makefile.PL ##初始化 make && make install4. 創(chuàng)建配置文件
#配置?件?錄 mkdir -p /etc/mha #日志目錄 mkdir -p /var/log/mha/app1 #創(chuàng)建配置文件 vi /etc/mha/app1.cnf [server default] manager_log=/var/log/mha/app1/manager manager_workdir=/var/log/mha/app1 master_binlog_dir=/var/lib/mysql password=root ping_interval=2 repl_password=root repl_user=root ssh_user=root user=root [server1] hostname=192.168.182.128 port=3306 [server2] hostname=192.168.182.132 port=3306 [server3] hostname=192.168.182.130 port=33065.對(duì)節(jié)點(diǎn)進(jìn)行檢測(cè)( 驗(yàn)證SSH通信)
masterha_check_ssh --conf=/etc/mha/app1.cnf如果最后一行顯示為[info]All SSH connection tests passed successfully.則表示成功
5.檢查管理的MySQL復(fù)制集群的連接配置參數(shù)是否OK
masterha_check_repl --conf=/etc/mha/app1.cnf6.開(kāi)啟MHA Manager監(jiān)控
nohup masterha_manager --conf=/etc/mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null> /var/log/mha/app1/manager.log 2>&1 &–remove_dead_master_conf //該參數(shù)代表當(dāng)發(fā)生主從切換后,老的主庫(kù)的ip將會(huì)從配置文件中移除。
–manger_log //日志存放位置
- 關(guān)閉監(jiān)控
7.查看master節(jié)點(diǎn)狀態(tài)
masterha_check_status -conf=/etc/mha/app1.cnf查看日志(報(bào)錯(cuò)的話,方便查日志)
```shell tail -200 /etc/mha_master/manager.log ```8.模擬宕機(jī)狀態(tài)
##在master節(jié)點(diǎn)上運(yùn)行 systemctl stop mysqld ## 觀察mhamanger節(jié)點(diǎn)?志: tail -f /var/log/mha/app1/manager9. 主機(jī)修復(fù)后,需要在mha中從新添加服務(wù)器節(jié)點(diǎn)
## master節(jié)點(diǎn) systemctl start mysqld ##mha的配置文件,從新添加修復(fù)后的服務(wù)器節(jié)點(diǎn),然后重新啟動(dòng)MHA服務(wù)器 [server1] hostname=192.168.182.128 port=3306完整的配置
- MHA的配置
- master節(jié)點(diǎn)的配置
- slave1的配置
- slave2的配置
參考
https://blog.csdn.net/qq_23830637/article/details/106968615####mha官網(wǎng) https://github.com/yoshinorim/mha4mysql-manager/releases #####mha安裝前rpm https://www.cnblogs.com/ding2016/p/9102052.html問(wèn)題:
https://blog.csdn.net/superbfly/article/details/75287741
Failed to issue method call: Unit ssh.service failed to load: No such file or directory.
systemctl enable sshd.servicesystemctl start sshd.servicesystemctl status sshd.servicehttps://blog.csdn.net/mengjiangtao/article/details/24195523
manager_log=/var/log/mha/app1/manager manager_workdir=/var/log/mha/app1 master_binlog_dir=/var/lib/mysql password=root ping_interval=2 repl_password=root repl_user=root ssh_user=root user=root [server1] hostname=192.168.182.128 port=3306 [server2] hostname=192.168.182.132 port=3306 [server3] hostname=192.168.182.130 port=3306 #將來(lái)可不可以成為master候選節(jié)點(diǎn)/主節(jié)點(diǎn) #candidate_master=1 # master候選人,master掛掉后,這個(gè)節(jié)點(diǎn)成為master # condidate_master=1################以下的了解即可 #設(shè)置master 保存binlog的位置,以便MHA可以找到master的日志 master_binlog_dir=/opt/mysql_data manager_workdir=/var/log/mha_master/app1.log #設(shè)置master 保存binlog的位置,以便MHA可以找到master的日志,我這里的也就是mysql的數(shù)據(jù)目錄 manager_log=/var/log/mha_master/manager.log #設(shè)置自動(dòng)failover時(shí)候的切換腳本 master_ip_failover_script="/etc/mha_master/scripts/master_ip_failover" #設(shè)置手動(dòng)切換時(shí)候的切換腳本 master_ip_online_change_script="/etc/mha_master/scripts/master_ip_online_change" #//設(shè)置發(fā)生切換后發(fā)送的報(bào)警的腳本 report_script="/etc/mha_master/scripts/send_report" #設(shè)置遠(yuǎn)端mysql在發(fā)生切換時(shí)binlog的保存位置 remote_workdir=/tmp ##實(shí)現(xiàn)多路由監(jiān)測(cè)Master的可用性 secondary_check_script= /usr/local/bin/masterha_secondary_check -s 10.0.20.201 -s 10.0.20.202 -s 10.0.20.203 -s 10.0.20.204 shutdown_script="" ################以下的了解即可參考
https://blog.csdn.net/qq_23830637/article/details/106968615
https://www.cnblogs.com/panwenbin-logs/p/8306906.html#autoid-0-0-0
http://www.ttlsa.com/mysql/step-one-by-one-deploy-mysql-mha-cluster/
https://www.cnblogs.com/shengdimaya/p/6949882.html
https://blog.csdn.net/qq_23830637/article/details/106968615
https://www.cnblogs.com/panwenbin-logs/p/8306906.html#autoid-0-0-0
http://www.ttlsa.com/mysql/step-one-by-one-deploy-mysql-mha-cluster/
https://www.cnblogs.com/shengdimaya/p/6949882.html
總結(jié)
以上是生活随笔為你收集整理的Mysql 主从复制+MHA搭建的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Mysql半双工主从复制
- 下一篇: zookeeper笔记+源码刨析