MySQL数据库的MNA集群环境配置
1 案例1:準(zhǔn)備MHA集群環(huán)境
1.1 問題
? 準(zhǔn)備6臺虛擬機,并按照本節(jié)規(guī)劃配置好IP參數(shù)
? 在這些虛擬機之間實現(xiàn)SSH免密登錄
? 在相應(yīng)節(jié)點上安裝好MHA相關(guān)的軟件包
1.2 方案
使用6臺RHEL 7虛擬機,如圖-1所示。準(zhǔn)備集群環(huán)境,安裝依賴包,授權(quán)用戶,配置ssh密鑰對認(rèn)證登陸,所有節(jié)點之間互相以root秘鑰對認(rèn)證登錄,管理主機以root密鑰對認(rèn)證登錄所有數(shù)據(jù)節(jié)點主機,配置mha集群。
圖-1
IP規(guī)劃,如圖-2所示:
圖-2
1.3
1.4 步驟
實現(xiàn)此案例需要按照如下步驟進行。
步驟一: 準(zhǔn)備集群環(huán)境
1)修改主機名,配置IP(其余幾臺請按照圖-2修改IP和主機名,這里以master51為例)
2)在所有主機上安裝Perl依賴包(51-56操作)
1. [root@zlz ~]# cd mysql/mha-soft-student/ 2. [root@zlz ~]# yum -y install perl-*.rpm3)在所有數(shù)據(jù)庫服務(wù)器上安裝mha-node包(51-55操作)
1. [root@zlz mha-soft-student]# yum -y install perl-DBD-mysql perl-DBI 2. [root@zlz mha-soft-student]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm 3. Preparing... ################################# [100%] 4. Updating / installing... 5. 1:mha4mysql-node-0.56-0.el6 ################################# [100%]4)在管理主機上安裝mha_node 和 mha-manager包(56操作)
1. [root@zlz mha-soft-student]# yum -y install perl-DBD-mysql perl-DBI 2. [root@zlz mha-soft-student]# rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm 3. Preparing... ################################# [100%] 4. Updating / installing... 5. 1:mha4mysql-node-0.56-0.el6 ################################# [100%] 6. [root@zlz mha-soft-student]# yum -y install perl-ExtUtils-* perl-CPAN-* 7. [root@zlz mha-soft-student]# tar -zxf mha4mysql-manager-0.56.tar.gz 8. [root@zlz mha-soft-student]# cd mha4mysql-manager-0.56/ 9. [root@zlz mha4mysql-manager-0.56]# perl Makefile.PL 10. *** Module::AutoInstall version 1.03 11. *** Checking for Perl dependencies... 12. [Core Features] 13. - DBI ...loaded. (1.627) 14. - DBD::mysql ...loaded. (4.023) 15. - Time::HiRes ...loaded. (1.9725) 16. - Config::Tiny ...loaded. (2.14) 17. - Log::Dispatch ...loaded. (2.41) 18. - Parallel::ForkManager ...loaded. (1.18) 19. - MHA::NodeConst ...loaded. (0.56) 20. *** Module::AutoInstall configuration finished. //配置完成 21. Checking if your kit is complete... 22. Looks good 23. Writing Makefile for mha4mysql::manager 24. Writing MYMETA.yml and MYMETA.json 25. [root@zlz mha4mysql-manager-0.56]# make 26. [root@zlz mha4mysql-manager-0.56]# make install步驟二: 配置ssh密鑰對認(rèn)證登陸
1)所有節(jié)點之間可以互相以ssh密鑰對方式認(rèn)證登陸以(以51為例)
6)配置56主機 無密碼ssh登錄所有數(shù)據(jù)節(jié)點主機
1. [root@zlz mha4mysql-manager-0.56]# ssh-keygen 2. [root@zlz mha4mysql-manager-0.56]# ssh-copy-id 192.168.4.51 3. //除傳給51外,還要傳給52-552 案例2:配置MHA集群環(huán)境
2.1 問題
? 配置主節(jié)點 master51
? 配置兩個備用主節(jié)點 master52、master53
? 配置兩個從節(jié)點 slave54、slave55
? 配置管理節(jié)點 mgm56
2.2 步驟
實現(xiàn)此案例需要按照如下步驟進行。
步驟一:配置mha集群環(huán)境
1)安裝數(shù)據(jù)庫(51-55同樣操作,以51為例)
2)master51 數(shù)據(jù)庫服務(wù)器配置文件
1. [root@zlz mysql]# vim /etc/my.cnf 2. plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 3. rpl-semi-sync-master-enabled = 1 4. rpl-semi-sync-slave-enabled = 1 5. server_id=51 6. log-bin=master51 7. binlog-format="mixed" 8. 9. [root@zlz mysql]# systemctl restart mysqld 10. 11. [root@zlz mysql]# mysql -u root -p123456 12. 13. mysql> set global relay_log_purge=off; //不自動刪除本機的中繼日志文件 14. Query OK, 0 rows affected (0.00 sec) 15. 16. mysql> grant replication slave on *.* to repluser@"%" identified by "123456"; 17. //添加主從同步授權(quán)用戶 18. Query OK, 0 rows affected, 1 warning (10.01 sec) 19. 20. mysql> show master status; 21. +-----------------+----------+--------------+------------------+-------------+ 22. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | 23. +-----------------+----------+--------------+------------------+--------------+ 24. | master51.000003 | 441 | | | | 25. +-----------------+----------+--------------+------------------+--------------+ 26. 1 row in set (0.00 sec)3)master52數(shù)據(jù)庫服務(wù)器配置文件
1. [root@zlz mysql]# vim /etc/my.cnf 2. plugin-load ="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 3. rpl-semi-sync-master-enabled = 1 4. rpl-semi-sync-slave-enabled = 1 5. server_id=52 6. log-bin=master52 7. binlog-format="mixed" 8. 9. [root@zlz mysql]# systemctl restart mysqld 10. [root@zlz mysql]# mysql -u root -p123456 11. mysql> set global relay_log_purge=off; 12. mysql> change master to 13. -> master_host="192.168.4.51", 14. -> master_user="repluser", 15. -> master_password="123456", 16. -> master_log_file="master51.000003", 17. -> master_log_pos=441; 18. Query OK, 0 rows affected, 2 warnings (0.01 sec) 19. mysql> start slave; 20. Query OK, 0 rows affected (0.01 sec) 21. mysql> show slave status\G; 22. ... 23. Slave_IO_Running: Yes 24. Slave_SQL_Running: Yes 25. ...4)master53數(shù)據(jù)庫服務(wù)器配置文件
1. [root@zlz mysql]# vim /etc/my.cnf 2. plugin-load ="rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so" 3. rpl-semi-sync-master-enabled = 1 4. rpl-semi-sync-slave-enabled = 1 5. server_id=53 6. log-bin=master53 7. binlog-format="mixed" 8. 9. [root@zlz mysql]# systemctl restart mysqld 10. [root@zlz mysql]# mysql -u root -p123456 11. mysql> set global relay_log_purge=off; 12. Query OK, 0 rows affected (0.00 sec) 13. 14. mysql> change master to 15. -> master_host="192.168.4.51", 16. -> master_user="repluser", 17. -> master_password="123456", 18. -> master_log_file="master51.000003", 19. -> master_log_pos=441; 20. Query OK, 0 rows affected, 2 warnings (0.01 sec) 21. mysql> start slave; 22. Query OK, 0 rows affected (0.00 sec) 23. mysql> show slave status\G; 24. ... 25. Slave_IO_Running: Yes 26. Slave_SQL_Running: Yes 27. ...5)slave54 數(shù)據(jù)庫服務(wù)器配置文件
1. [root@zlz mysql]# vim /etc/my.cnf 2. server_id=54 3. [root@zlz mysql]# systemctl restart mysqld 4. [root@zlz mysql]# mysql -u root -p123456 5. mysql> change master to 6. -> master_host="192.168.4.51", 7. -> master_user="repluser", 8. -> master_password="123456", 9. -> master_log_file="master51.000003", 10. -> master_log_pos=441; 11. Query OK, 0 rows affected, 2 warnings (0.01 sec) 12. mysql> start slave; 13. Query OK, 0 rows affected (0.00 sec) 14. mysql> show slave status\G; 15. ... 16. Slave_IO_Running: Yes 17. Slave_SQL_Running: Yes 18. ...6)slave55 數(shù)據(jù)庫服務(wù)器配置文件
1. [root@zlz mysql]# vim /etc/my.cnf 2. server_id=55 3. 4. [root@master55 mysql]# systemctl restart mysqld 5. [root@master55 mysql]# mysql -u root -p123456 6. mysql> change master to 7. -> master_host="192.168.4.51", 8. -> master_user="repluser", 9. -> master_password="123456", 10. -> master_log_file="master51.000003", 11. -> master_log_pos=441; 12. Query OK, 0 rows affected, 2 warnings (0.01 sec) 13. mysql> start slave; 14. Query OK, 0 rows affected (0.00 sec) 15. mysql> show slave status\G; 16. ... 17. Slave_IO_Running: Yes 18. Slave_SQL_Running: Yes 19. ...7)配置管理主機4.56
1. [root@zlz ~]# cd mysql/mha-soft-student/mha4mysql-manager-0.56/ 2. [root@zlz mha4mysql-manager-0.56]# cp bin/* /usr/local/bin/ 3. //提示覆蓋,說明安裝的時候有,沒有可以拷貝過來 4. [root@mgm56 mha4mysql-manager-0.56]# mkdir /etc/mha_manager //創(chuàng)建工作目錄 5. [root@mgm56 mha4mysql-manager-0.56]# cp samples/conf/app1.cnf /etc/mha_manager 6. //建立樣板文件 7. [root@mgm56 mha4mysql-manager-0.56]# vim /etc/mha_manager/app1.cnf 8. //編輯主配置文件app1.cnf 9. [server default] 10. manager_workdir=/etc/mha_manager 11. manager_log=/etc/mha_manager/manager.log 12. master_ip_failover_script=/usr/local/bin/master_ip_failover 13. 14. ssh_user=root 15. ssh_port=22 16. repl_user=repluser 17. repl_password=123456 18. user=root 19. password=123456 20. 21. [server1] 22. hostname=192.168.4.51 23. port=3306 24. 25. [server2] 26. hostname=192.168.4.52 27. port=3306 28. candidate_master=1 29. 30. [server3] 31. hostname=192.168.4.53 32. port=3306 33. candidate_master=1 34. 35. [server4] 36. hostname=192.168.4.54 37. no_master=1 38. 39. [server5] 40. hostname=192.168.4.55 41. no_master=1 42. [root@mgm56 mha4mysql-manager-0.56]# cp samples/scripts/master_ip_failover 43. /usr/local/bin/ //創(chuàng)建故障切換的腳本3 案例3:測試MHA集群
3.1 問題
? 查看MHA集群狀態(tài)
? 測試節(jié)點之間的SSH登錄
? 測試集群VIP的故障切換功能
3.2 步驟
實現(xiàn)此案例需要按照如下步驟進行。
步驟一:驗證配置
1)檢查配置環(huán)境,在主機52,53檢查是否有同步數(shù)據(jù)的用戶repluser
主機52:
主機53:
1. mysql> select user,host from mysql.user where user="repluser"; 2. +----------+------+ 3. | user | host | 4. +----------+------+ 5. | repluser | % | 6. +----------+------+ 7. 1 row in set (0.00 sec) 8. 9. mysql> show grants for repluser@"%"; 10. +--------------------------------------------------+ 11. | Grants for repluser@% | 12. +--------------------------------------------------+ 13. | GRANT REPLICATION SLAVE ON *.* TO 'repluser'@'%' | +--------------------------------------------------+ 1. 1 row in set (0.00 sec)2)在51的主機上做root的授權(quán),其他的會同步(如果不做,在驗證數(shù)據(jù)節(jié)點的主從同步配置時會出錯)
1. mysql> grant all on *.* to root@"%" identified by "123456"; 2. mysql> select user,host from mysql.user where user="root"; 3. +------+-----------+ 4. | user | host | 5. +------+-----------+ 6. | root | % | 7. | root | localhost | 8. +------+-----------+ 9. 2 rows in set (0.00 sec)3)驗證ssh 免密登陸數(shù)據(jù)節(jié)點主機
1. [root@zlz mha4mysql-manager-0.56]# cd /usr/local/bin/ 2. [root@zlz bin]# masterha_check_ssh --conf=/etc/mha_manager/app1.cnf 3. Wed Sep 19 09:09:33 2018 - [info] All SSH connection tests passed successfully. 4. //出現(xiàn)這個為成功4)驗證數(shù)據(jù)節(jié)點的主從同步配置(先把自動failover時候的切換腳本注釋掉)
1. [root@zlz bin]# masterha_check_repl --conf=/etc/mha_manager/app1.cnf 2. MySQL Replication Health is OK. //驗證成功5)啟動管理服務(wù)MHA_Manager
–remove_dead_master_conf //刪除宕機主庫配置
–ignore_last_failover //忽略xxx.health文件
6)查看狀態(tài)(另開一個終端)
1. [root@zlz ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf 2. app1 (pid:15745) is running(0:PING_OK), master:192.168.4.517)停止服務(wù)
1. [root@zlz ~]# masterha_stop --conf=/etc/mha_manager/app1.cnf 2. Stopped app1 successfully.步驟二:測試故障轉(zhuǎn)移
1)在主庫51上面配置VIP地址
2)在配置文件里面把自動failover時候的切換腳本去掉注釋
3)修改 master_ip_failover 腳本,設(shè)置如下內(nèi)容
4)啟動服務(wù)
1. [root@zlz bin]# masterha_manager --conf=/etc/mha_manager/app1.cnf \ 2. --remove_dead_master_conf --ignore_last_failover 3. Wed Sep 19 09:50:33 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping. 4. Wed Sep 19 09:50:33 2018 - [info] Reading application default configuration from /etc/mha_manager/app1.cnf.. 5. Wed Sep 19 09:50:33 2018 - [info] Reading server configuration from /etc/mha_manager/app1.cnf..5)查看狀態(tài)
1. [root@zlz ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf 2. app1 master is down and failover is running(50:FAILOVER_RUNNING). master:192.168.4.52驗證數(shù)據(jù)節(jié)點的主從同步配置報錯,如圖-3所示:
1. [root@zlz bin]# masterha_check_repl --conf=/etc/mha_manager/app1.cnf圖-3
解決辦法:
root用戶沒有授權(quán),默認(rèn)只能本地連接,在主機51上面授權(quán)root用戶可以遠(yuǎn)程登錄,其他主機會同步
總結(jié)
以上是生活随笔為你收集整理的MySQL数据库的MNA集群环境配置的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 3D动画概述暨骨骼动画实现
- 下一篇: 电子血压计方案提供模块芯片开发服务