這篇文章主要介紹“怎么搭建MHA+MySQL”,在日常操作中,相信很多人在怎么搭建MHA+MySQL問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么搭建MHA+MySQL”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!
創(chuàng)新互聯(lián)建站長期為千余家客戶提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊從業(yè)經(jīng)驗10年,關(guān)注不同地域、不同群體,并針對不同對象提供差異化的產(chǎn)品和服務(wù);打造開放共贏平臺,與合作伙伴共同營造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為格爾木企業(yè)提供專業(yè)的網(wǎng)站建設(shè)、網(wǎng)站設(shè)計,格爾木網(wǎng)站改版等技術(shù)服務(wù)。擁有十載豐富建站經(jīng)驗和眾多成功案例,為您定制開發(fā)。
一主兩從,manager節(jié)點為vm3
master:10.0.0.2 vm1 node
slave1: 10.0.0.3 vm2 node
slave2: 10.0.0.4 vm3 manager
OS verision均為:CentOS release 6.5
1,從https://code.google.com/p/mysql-master-ha/wiki/Downloads?tm=2下載MHA安裝包
mha4mysql-node-0.56-0.el6.noarch.rpm
mha4mysql-manager-0.56-0.el6.noarch.rpm
node需要安裝mha4mysql-node-0.56-0.el6.noarch.rpm包,
manager節(jié)點需要安裝mha4mysql-manager-0.56-0.el6.noarch.rpm和mha4mysql-node-0.56-0.el6.noarch.rpm
或者從https://github.com/yoshinorim下載源碼包
2 給所有節(jié)點配置EPEL yum源。
rpm -ivh http://mirrors.opencas.cn/epel/6/i386/epel-release-6-8.noarch.rpm
yum clean all; yum makecache
3 為所有節(jié)點安裝mha4mysql-node-0.56-0.el6.noarch.rpm
yum -y install perl-DBD-MySQL ncftp
rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm
4 為manager節(jié)點安裝mha4mysql-manager-0.56-0.el6.noarch.rpm
yum -y install perl-Config-Tiny perl-Params-Validate perl-Log-Dispatch perl-Parallel-ForkManager
rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm
5 配置各節(jié)點間的ssh公鑰信任,實現(xiàn)免密鑰登錄。(manager to node, node to node)
vm1:
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.3
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.4
vm2:
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.2
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.4
vm3:
ssh-keygen -t rsa
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.2
ssh-copy-id -i /root/.ssh/id_rsa.pub root@10.0.0.3
分別從各個節(jié)點ssh登陸其他節(jié)點。(必須做,頭一次需要輸入yes確認(rèn))
6 在各mysql節(jié)點創(chuàng)建MHA的監(jiān)控用戶
grant all privileges on *.* to 'mha_monitor'@'10.0.0.%' identified by '123456';
mysql> select user,host from user;
+-------------+-----------+
| user | host |
+-------------+-----------+
| mha_monitor | 10.0.0.% |
| repl | 10.0.0.% |
7 配置mha conf文件
mkdir /etc/masterha
mkdir -p /masterha/app1
配置文件app1.cnf內(nèi)容如下
cat /etc/masterha/app1.cnf
[server default]
manager_workdir=/masterha/app1
manager_log=/masterha/app1/manager.log
ssh_user=root ##OS ssh登陸用戶
user=mha_monitor ##mha登陸mysql主從的用戶
password=123456 ##mha登陸mysql主從的用戶密碼
repl_user=repl ##主從復(fù)制用戶
repl_password=p4ssw0rd ##主從復(fù)制用戶的密碼
ping_interval=1
shutdown_script=""
#master_ip_failover_script="/usr/local/bin/master_ip_failover"
master_ip_online_change_script=""
report_script=""
[server1]
hostname=10.0.0.2
master_binlog_dir="/data/mysql3306"
port=3306
candidate_master=1
[server2]
hostname=10.0.0.3
master_binlog_dir="/data/mysql3306"
port=3306
candidate_master=1
[server3]
hostname=10.0.0.4
master_binlog_dir="/data/mysql3306"
port=3306
no_master=1
8 啟動
nohup masterha_manager --conf=/etc/masterha/app1.cnf > /tmp/mha_manager.log < /dev/null 2>&1 &
shutdown 掉master后,可以順利切換。
但是masterha_check_ssh會報錯,只是不影響功能:
[root@vm3 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
Wed Apr 6 15:56:05 2016 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Apr 6 15:56:05 2016 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Wed Apr 6 15:56:05 2016 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Wed Apr 6 15:56:05 2016 - [info] Starting SSH connection tests..
Wed Apr 6 15:56:05 2016 - [debug]
Wed Apr 6 15:56:05 2016 - [debug] Connecting via SSH from root@vm1(10.0.0.2:22) to root@vm2(10.0.0.3:22)..
Wed Apr 6 15:56:05 2016 - [debug] ok.
Wed Apr 6 15:56:05 2016 - [debug] Connecting via SSH from root@vm1(10.0.0.2:22) to root@10.0.0.4(10.0.0.4:22)..
Wed Apr 6 15:56:05 2016 - [debug] ok.
Wed Apr 6 15:56:06 2016 - [debug]
Wed Apr 6 15:56:05 2016 - [debug] Connecting via SSH from root@vm2(10.0.0.3:22) to root@vm1(10.0.0.2:22)..
Wed Apr 6 15:56:06 2016 - [debug] ok.
Wed Apr 6 15:56:06 2016 - [debug] Connecting via SSH from root@vm2(10.0.0.3:22) to root@10.0.0.4(10.0.0.4:22)..
Wed Apr 6 15:56:06 2016 - [debug] ok.
Wed Apr 6 15:56:06 2016 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln63]
Wed Apr 6 15:56:06 2016 - [debug] Connecting via SSH from root@10.0.0.4(10.0.0.4:22) to root@vm1(10.0.0.2:22)..
Warning: Permanently added '10.0.0.4' (RSA) to the list of known hosts.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
Wed Apr 6 15:56:06 2016 - [error][/usr/share/perl5/vendor_perl/MHA/SSHCheck.pm, ln111] SSH connection from root@10.0.0.4(10.0.0.4:22) to root@vm1(10.0.0.2:22) failed!
SSH Configuration Check Failed!
at /usr/bin/masterha_check_ssh line 44中間
9 最后shutdown掉master,模擬failover:
----- Failover Report -----
app1: MySQL Master failover vm1(10.0.0.2:3306) to vm2(10.0.0.3:3306) succeeded
Master vm1(10.0.0.2:3306) is down!
Check MHA Manager logs at vm3:/masterha/app1/manager.log for details.
Started automated(non-interactive) failover.
Selected vm2(10.0.0.3:3306) as a new master.
vm2(10.0.0.3:3306): OK: Applying all logs succeeded.
10.0.0.4(10.0.0.4:3306): OK: Slave started, replicating from vm2(10.0.0.3:3306)
vm2(10.0.0.3:3306): Resetting slave info succeeded.
主從切換成功。
##########################################
##########################################
關(guān)于masterha_check_ssh報錯的問題,MHA官網(wǎng)上發(fā)現(xiàn)類似問題的帖子有人給的解釋如下:
#3 dba.abde...@gmail.com As mentioned here in the tutorial:
https://code.google.com/p/mysql-master-ha/wiki/Tutorial
You shouldn't add an entry for the manager host. If you have 4 hosts, 1,
2, 3 and 4 (manager), you should add host entries for the first 3 ones
only (1, 2 & 3) then it should work without any problems.
他的結(jié)構(gòu)是:
master:10.10.105.9
slave1:10.10.105.10
slave2:10.10.105.11
slave3+mha_manage:10.10.105.12
和我的結(jié)構(gòu)類似。
到此,關(guān)于“怎么搭建MHA+MySQL”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>
網(wǎng)站標(biāo)題:怎么搭建MHA+MySQL
本文鏈接:http://weahome.cn/article/psgipo.html