[toc]
一、簡(jiǎn)介
是一款開源,對(duì)MySQL復(fù)制提供高可用、拓?fù)涞目梢暬芾砉ぞ?,采用go語言編寫,它能夠主動(dòng)發(fā)現(xiàn)當(dāng)前拓?fù)浣Y(jié)構(gòu)和主從復(fù)制狀態(tài),支持MySQL主從復(fù)制拓?fù)潢P(guān)系的調(diào)整、支持MySQL主庫(kù)故障自動(dòng)切換()、手動(dòng)主從切換()等功能。
后臺(tái)依賴于MySQL或者存儲(chǔ)元數(shù)據(jù),能夠提供Web界面展示MySQL集群的拓?fù)潢P(guān)系及實(shí)例狀態(tài)mysql集群高可用方式有哪些,通過Web界面可更改MySQL實(shí)例的部分配置信息,同時(shí)也提供命令行和api接口,以便更加靈活的自動(dòng)化運(yùn)維管理。 對(duì)MySQL主庫(kù)的故障切換分為自動(dòng)切換和手動(dòng)切換。手動(dòng)切換又分為、force--、force--以及--。
相比于MHA,更加偏重于復(fù)制拓?fù)潢P(guān)系的管理,能夠?qū)崿F(xiàn)MySQL任一復(fù)制拓?fù)潢P(guān)系的調(diào)整,并在此基礎(chǔ)上,實(shí)現(xiàn)MySQL高可用。另外,自身也可以部署多個(gè)節(jié)點(diǎn),通過raft分布式一致性協(xié)議,保證自身的高可用。
主要有以下幾個(gè)特征:
的地址:
的所有參數(shù):
官方建議的生產(chǎn)配置示例:
二、快速搭建環(huán)境
-- 拉取小麥苗的鏡像 docker pull registry.cn-hangzhou.aliyuncs.com/lhrbest/lhrorchestrator:1.0 -- 創(chuàng)建容器 docker run -d --name lhrorchestrator -h lhrorchestrator \ -p 233:22 -p 3087:3389 -p 3000:3000 \ --privileged=true lhrbest/lhrorchestrator:1.0 \ /usr/sbin/init -- 進(jìn)入容器 docker exec -it lhrorchestrator bash -- 啟動(dòng)后端存儲(chǔ)MySQL庫(kù) systemctl status mysqld MySQL用戶名和密碼:root/lhr -- 啟動(dòng)orchestrator systemctl start orchestrator systemctl status orchestrator -- web訪問: http://192.168.66.35:3000 用戶名和密碼:lhr/lhr-- 日志: tailf /var/log/messages -- 參數(shù)文件 /usr/local/orchestrator/orchestrator.conf.json
web界面如下所示:
三、添加主從環(huán)境
把配置好的復(fù)制實(shí)例加入到,因?yàn)閛rch可以自動(dòng)發(fā)現(xiàn)整個(gè)拓?fù)涞乃袑?shí)例mysql集群高可用方式有哪些,所以只需要添加任意一臺(tái)實(shí)例即可。
這里,我有一套1主2從的環(huán)境,拓?fù)鋱D如下所示:
[root@docker35 log]# mysqlrplshow --master=root:lhr@172.72.0.2:3306 --discover-slaves-login=root:lhr --verbose WARNING: Using a password on the command line interface can be insecure. # master on 172.72.0.2: ... connected. # Finding slaves for master: 172.72.0.2:3306 # Replication Topology Graph 172.72.0.2:3306 (MASTER) | +--- 172.72.0.3:3306 [IO: Yes, SQL: Yes] - (SLAVE) | +--- 172.72.0.4:3306 [IO: Yes, SQL: Yes] - (SLAVE)
下面開始把這套環(huán)境添加到中:
添加成功。
我們?cè)偬砑右惶纂p主雙從的環(huán)境:
選擇任意一臺(tái)MySQL服務(wù)器進(jìn)行操作,添加完成后,刷新頁(yè)面如下:
四、修改集群別名
修改完成后,刷新頁(yè)面:
注意:集群別名不支持中文。
五、拖動(dòng)界面修改主從關(guān)系
手動(dòng)修改主從關(guān)系:
六、自動(dòng)
要實(shí)現(xiàn)自動(dòng),需要修改2個(gè)參數(shù):
[root@lhrorchestrator orchestrator]# more orchestrator.conf.json | grep ClusterFilters "RecoverMasterClusterFilters": ["*"], "RecoverIntermediateMasterClusterFilters": ["*"],
這2個(gè)參數(shù)表示定義哪些集群可以自動(dòng)和。
自動(dòng)之前:
宕掉主庫(kù):
[root@lhrorchestrator /]# mysql -uroot -plhr -h172.72.0.2 -P3306 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11357 Server version: 5.7.30-log MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> shutdown ; Query OK, 0 rows affected (0.00 sec)
刷新頁(yè)面:
172.72.0.2自動(dòng)被剔除,新主庫(kù)變?yōu)?72.72.0.3。
172.72.0.4指向了新的主庫(kù)172.72.0.3。
172.72.0.2已宕機(jī),邊框?yàn)楹谏?/p>
接下來啟動(dòng)172.72.0.2,啟動(dòng)完成后:
需要我們手動(dòng)加入集群:
[root@docker35 log]# mysql -uroot -plhr -h172.72.0.2 -P3306 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 13 Server version: 5.7.30-log MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show slave hosts; Empty set (0.00 sec) mysql> show slave status; Empty set (0.00 sec) mysql> change master to -> master_host='172.72.0.3', -> master_port=3306, -> master_user='repl', -> master_password='lhr', -> master_auto_position=1; show slave status \G; Query OK, 0 rows affected, 1 warning (0.02 sec) mysql> mysql> start slave;Query OK, 0 rows affected (0.01 sec) mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Checking master version Master_Host: 172.72.0.3 Master_User: repl Master_Port: 3306 Connect_Retry: 60 Master_Log_File: Read_Master_Log_Pos: 4 Relay_Log_File: master-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 0 Relay_Log_Space: 154 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher:
Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 0 Master_UUID: Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: bacfcde8-69dc-11eb-b240-0242ac480002:1-70574, bc6d26f0-69dc-11eb-bfa7-0242ac480003:1-5 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) ERROR: No query specified mysql>
刷新頁(yè)面:
可以看到,又回到了一主2從的環(huán)境。
About Me