您好,登錄后才能下訂單哦!
這篇文章主要介紹“怎么搭建MHA+MySQL”,在日常操作中,相信很多人在怎么搭建MHA+MySQL問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么搭建MHA+MySQL”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
一主兩從,manager節點為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節點需要安裝mha4mysql-manager-0.56-0.el6.noarch.rpm和mha4mysql-node-0.56-0.el6.noarch.rpm
或者從https://github.com/yoshinorim下載源碼包
2 給所有節點配置EPEL yum源。
rpm -ivh http://mirrors.opencas.cn/epel/6/i386/epel-release-6-8.noarch.rpm
yum clean all; yum makecache
3 為所有節點安裝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節點安裝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 配置各節點間的ssh公鑰信任,實現免密鑰登錄。(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
分別從各個節點ssh登陸其他節點。(必須做,頭一次需要輸入yes確認)
6 在各mysql節點創建MHA的監控用戶
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內容如下
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 ##主從復制用戶
repl_password=p4ssw0rd ##主從復制用戶的密碼
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.
主從切換成功。
##########################################
##########################################
關于masterha_check_ssh報錯的問題,MHA官網上發現類似問題的帖子有人給的解釋如下:
#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.
他的結構是:
master:10.10.105.9
slave1:10.10.105.10
slave2:10.10.105.11
slave3+mha_manage:10.10.105.12
和我的結構類似。
到此,關于“怎么搭建MHA+MySQL”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。