此MGR+ProxySql MySql集群架構,目的是為了解決目前DMS系統數據庫單機環境對高并發支撐不足,數據庫經常出現阻塞,導致系統卡頓的問題。此次搭建可選擇在凌晨業務不繁忙時間,預計搭建時間3個小時。
MySQL是目前較流行的關系型開源數據庫之一,支持完整的事務支持,支持標準的SQL以及支持跨平臺部署。Proxysql是基于MySQL的一款開源的中間件的產品,是一個靈活的MySQL代理層,可以實現讀寫分離,支持Query路由功能,支持動態指定某個SQL進行緩存,支持動態加載(無需重啟ProxySQL服務),故障切換和SQL過濾功能。
序號 | 軟件 | 版本 |
2 | MySQL | 5.7.28 |
3 | ProyxSql | 2.0.12 |
本次搭建共需要在生產環境新增主機2臺,以下為需要的具體配置信息:
序號 | 操作系統 | CPU | 內存 | 磁盤 | 部署軟件 | 數量 | 備注 |
1 | CentOS7.4 | 32c | 128G | 1T | ProxySql | 1臺 | |
2 | CentOS7.4 | 32c | 128G | 2T | MySQL | 1臺 |
需要在其中proxysql主機開放6032、6033端口供應用程序訪問及監控使用。
環境檢查,主要檢查硬件信息是否符合申請的指標以及軟件版本信息
主機 | CPU | 磁盤 | 內存 | 網絡 | 軟件版本 |
NODE | 滿足 | 滿足 | 滿足 | 滿足 | 滿足 |
MGR集群實現數據庫復制功能及高可用。Proxysql對應用程序提供訪問,對MGR集群進行讀寫分離,集群狀態檢測,實現故障切換。
先將新增的一臺服務器搭建MySQL數據庫,將DMS主數據庫的備份數據傳送到服務器上,搭建主從使目前3臺數據庫的數據保持一致,為搭建MGR作準備。
156:
server-id = 156 #以服務器ip設置,
log-bin = /usr/local/mysql/log/mysql-bin.log --開啟binlog
###MGR setting####
master_info_repository=TABLE
relay_log_info_repository=TABLE
slave_preserve_commit_order=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name=0f4ecd37-afa1-11ea-80a8-00505683effffd
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="11.11.11.156:33061"
loose-group_replication_group_seeds="11.11.11.156:33061,11.11.11.157:33062,11.11.11.244:33063"
loose-group_replication_ip_whitelist="11.11.11.156,11.11.11.157,11.11.11.244"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=true
loose-group_replication_enforce_update_everywhere_checks=false
157:
server-id = 157 #以服務器ip設置,
log-bin = /usr/local/mysql/log/mysql-bin.log --開啟binlog
###MGR setting####
master_info_repository=TABLE
relay_log_info_repository=TABLE
slave_preserve_commit_order=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name=0f4ecd37-afa1-11ea-80a8-00505683effffd
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="11.11.11.157:33062"
loose-group_replication_group_seeds="11.11.11.156:33061,11.11.11.157:33062,11.11.11.244:33063"
loose-group_replication_ip_whitelist="11.11.11.156,11.11.11.157,11.11.11.244"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=true
loose-group_replication_enforce_update_everywhere_checks=false
244:
server-id = 244 #以服務器ip設置,
log-bin = /usr/local/mysql/log/mysql-bin.log
server-id = 156 #以服務器ip設置,
log-bin = /usr/local/mysql/log/mysql-bin.log --開啟binlog
###MGR setting####
master_info_repository=TABLE
relay_log_info_repository=TABLE
slave_preserve_commit_order=ON
binlog_checksum=NONE
transaction_write_set_extraction=XXHASH64
loose-group_replication_group_name=0f4ecd37-afa1-11ea-80a8-00505683effffd
loose-group_replication_start_on_boot=off
loose-group_replication_local_address="11.11.11.156:33061"
loose-group_replication_group_seeds="11.11.11.156:33061,11.11.11.157:33062,11.11.11.244:33063"
loose-group_replication_ip_whitelist="11.11.11.156,11.11.11.157,11.11.11.244"
loose-group_replication_bootstrap_group= off
loose-group_replication_single_primary_mode=true
loose-group_replication_enforce_update_everywhere_checks=false
修改主機名
hostnamectl set-hostname mgr_node1
hostnamectl set-hostname mgr_node2
hostnamectl set-hostname mgr_node3
hostnamectl set-hostname proxysql
修改hosts文件
11.11.11.156 mgr_node1
11.11.11.157 mgr_node2
11.11.11.244 mgr_node3
開啟MGR
主節點:
CHANGE MASTER TO MASTER_USER=repl, MASTER_PASSWORD=Rest!101 FORCHANNEL group_replication_recovery;
installplugin group_replication soname group_replication.so; --安裝gr插件
#設置group_replication_bootstrap_group為ON是為了標示以后加入集群的服務器以這臺服務器為基準,以后加入的就不需要設置。
setglobal group_replication_bootstrap_group=on;
開啟組復制
startgroup_replication;
setglobal group_replication_bootstrap_group=off;
節點1:
CHANGE MASTER TO MASTER_USER=repl, MASTER_PASSWORD=Rest!101 FORCHANNEL group_replication_recovery;
installplugin group_replication soname group_replication.so;
setglobal group_replication_allow_local_disjoint_gtids_join=ON;
startgroup_replication;
節點2:
CHANGE MASTER TO MASTER_USER=repl, MASTER_PASSWORD=Rest!101 FORCHANNEL group_replication_recovery;
installplugin group_replication soname group_replication.so;
setglobal group_replication_allow_local_disjoint_gtids_join=ON;
startgroup_replication;
查看是否搭建成功
#查詢組成員
select* from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
|CHANNEL_NAME | MEMBER_ID |MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
|group_replication_applier | 38ed8610-aca0-11ea-8482-00505683effffd |mgr_node1 | 3306 | ONLINE |
|group_replication_applier | 9d5c531c-b075-11ea-9d27-005056839787 |mgr_node2 | 3306 | ONLINE |
|group_replication_applier | dc4bd6bb-b076-11ea-96f6-005056835c02 |mgr_node3 | 3306 | ONLINE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
#查詢主節點
selectvariable_value from performance_schema.global_status wherevariable_name=group_replication_primary_member;
+--------------------------------------+
| variable_value |
+--------------------------------------+
| 38ed8610-aca0-11ea-8482-00505683effffd |
+--------------------------------------+
在mgr集群上創建proxysql所需的賬號
#proxysql的監控賬戶
createuser monitor@% identified by Monitor@123;
grantall privileges on *.* to monitor@% with grant option;
#proxysql的對外訪問賬戶
createuser proxysql@% identified by Proxysql@123;
grantall privileges on *.* to proxysql@% with grant option;
搭建yum環境,安裝proxysql軟件
搭建yum源
cat<
[proxysql_repo]
name=ProxySQL YUM repository
baseurl=http://repo.proxysql.com/ProxySQL/proxysql-2.0.x/centos/$releasever
gpgcheck=1
gpgkey=http://repo.proxysql.com/ProxySQL/repo_pub_key
EOF
安裝依賴
yum-y install perl.x86_64
yuminstall -y libaio.x86_64
yum-y install net-tools.x86_64
yuminstall perl-DBD-MySQL -y
安裝Proxysql
Yuminstall -y proxysql
啟動proxySql
systemctlstart proxysql
netstat-anlp | grep proxysql
6032是ProxySQL的管理端口號,6033是對外服務的端口號
ProxySQL的用戶名和密碼都是默認的admin
配置proxySql:配置訪問賬號及監控監控,在mgr主節點執行監控腳本。
管理員登錄ProxySQL
/usr/local/mysql/bin/mysql-uadmin -padmin -h 127.0.0.1 -P 6032
#配置監控賬號
setmysql-monitor_username=monitor;
setmysql-monitor_password=Monitor@123;
#配置默認組信息
insertintomysql_group_replication_hostgroups(writer_hostgroup,backup_writer_hostgroup,reader_hostgroup,offline_hostgroup,active,writer_is_also_reader)values(10,20,30,40,1,1);
#配置用戶(主要是添加程序端的這個用戶,也就是run,將其設置到寫組10里面)
insertinto mysql_users(username,password,default_hostgroup)values(proxysql,Proxysql@123,10);
主節點定義為寫組10,從節點定義為只讀組30
insertintomysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment)values (10,10.2.159.35,3306,1,3000,10,mgr_node1);
insertintomysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment)values (30,10.2.159.36,3306,2,3000,10,mgr_node2);
insertintomysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment)values (30,10.2.159.46,3306,2,3000,10,mgr_node3);
insertintomysql_servers(hostgroup_id,hostname,port,weight,max_connections,max_replication_lag,comment)values (30,10.2.159.35,3306,1,3000,10,mgr_node1);
規劃讀寫組,添加節點設置讀寫分離規則,查看節點狀態。
#配置讀寫分離參數
insertintomysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply)values(1,1,^SELECT.*FORUPDATE$,10,1);
insertintomysql_query_rules(rule_id,active,match_digest,destination_hostgroup,apply)values(2,1,^SELECT,30,1);
save使內存數據永久存儲到磁盤,load使內存數據加載到runtime生效:
savemysql users to disk;
savemysql servers to disk;
savemysql query rules to disk;
savemysql variables to disk;
saveadmin variables to disk;
loadmysql users to runtime;
loadmysql servers to runtime;
loadmysql query rules to runtime;
loadmysql variables to runtime;
loadadmin variables to runtime;
在MGR主節點執行監控腳本
USEsys;
DELIMITER$$
CREATEFUNCTION IFZERO(a INT, b INT)
RETURNSINT
DETERMINISTIC
RETURNIF(a = 0, b, a)$$
CREATEFUNCTION LOCATE2(needle TEXT(10000), haystack TEXT(10000), offsetINT)
RETURNSINT
DETERMINISTIC
RETURNIFZERO(LOCATE(needle, haystack, offset), LENGTH(haystack) + 1)$$
CREATEFUNCTION GTID_NORMALIZE(g TEXT(10000))
RETURNSTEXT(10000)
DETERMINISTIC
RETURNGTID_SUBTRACT(g, )$$
CREATEFUNCTION GTID_COUNT(gtid_set TEXT(10000))
RETURNSINT
DETERMINISTIC
BEGIN
DECLAREresult BIGINT DEFAULT 0;
DECLAREcolon_pos INT;
DECLAREnext_dash_pos INT;
DECLAREnext_colon_pos INT;
DECLAREnext_comma_pos INT;
SETgtid_set = GTID_NORMALIZE(gtid_set);
SETcolon_pos = LOCATE2(:, gtid_set, 1);
WHILEcolon_pos != LENGTH(gtid_set) + 1 DO
SETnext_dash_pos = LOCATE2(-, gtid_set, colon_pos + 1);
SETnext_colon_pos = LOCATE2(:, gtid_set, colon_pos + 1);
SETnext_comma_pos = LOCATE2(,, gtid_set, colon_pos + 1);
IFnext_dash_pos < next_colon_pos AND next_dash_pos
SETresult = result +
SUBSTR(gtid_set,next_dash_pos + 1,
LEAST(next_colon_pos,next_comma_pos) - (next_dash_pos + 1)) -
SUBSTR(gtid_set,colon_pos + 1, next_dash_pos - (colon_pos + 1)) + 1;
ELSE
SETresult = result + 1;
ENDIF;
SETcolon_pos = next_colon_pos;
ENDWHILE;
RETURNresult;
END$$
CREATEFUNCTION gr_applier_queue_length()
RETURNSINT
DETERMINISTIC
BEGIN
RETURN(SELECT sys.gtid_count( GTID_SUBTRACT( (SELECT
Received_transaction_setFROM performance_schema.replication_connection_status
WHEREChannel_name = group_replication_applier ), (SELECT
@@global.GTID_EXECUTED))));
END$$
CREATEFUNCTION gr_member_in_primary_partition()
RETURNSVARCHAR(3)
DETERMINISTIC
BEGIN
RETURN(SELECT IF( MEMBER_STATE=ONLINE AND ((SELECT COUNT(*) FROM
performance_schema.replication_group_membersWHERE MEMBER_STATE != ONLINE) >=
((SELECTCOUNT(*) FROM performance_schema.replication_group_members)/2) = 0),
YES,NO ) FROM performance_schema.replication_group_members JOIN
performance_schema.replication_group_member_statsUSING(member_id));
END$$
CREATEVIEW gr_member_routing_candidate_status AS SELECT
sys.gr_member_in_primary_partition()as viable_candidate,
IF((SELECT (SELECT GROUP_CONCAT(variable_value) FROM
performance_schema.global_variablesWHERE variable_name IN (read_only,
super_read_only))!= OFF,OFF), YES, NO) as read_only,
sys.gr_applier_queue_length()as transactions_behind, Count_Transactions_in_queue astransactions_to_cert fromperformance_schema.replication_group_member_stats;$$
DELIMITER;
查看各節點狀態
SELECT* FROM sys.gr_member_routing_candidate_status;
selecthostname,port,viable_candidate,read_only,transactions_behind,errorfrom mysql_server_group_replication_log order by time_start_us desclimit 6;
SELECT* FROM monitor.mysql_server_connect_log ORDER BY time_start_us DESCLIMIT 10 ;
SELECT* FROM monitor.mysql_server_ping_log ORDER BY time_start_us DESCLIMIT 10;
在應用端驗證讀寫分離是否可用;驗證mgr故障轉移是否可用
測試讀負載均衡
fori in `seq 1 10`; do /usr/local/mysql/bin/mysql -uproxysql-pProxysql@123 -h127.0.0.1 -P6033 -e "select * fromperformance_schema.global_variables where variable_name=server_id;"; done | grep server
fori in `seq 1 10`; do /usr/local/mysql/bin/mysql -uproxysql-pProxysql@123 -h10.2.159.47 -P6033 -e "select * fromperformance_schema.global_variables where variable_name=server_id;"; done | grep server
驗證系統各功能是否正常
本次集群搭建中若出現問題,或搭建成功后系統功能不可用,可采用應用端保持連接原始數據庫,或切換回原始數據庫鏈接,以此確保架構改造失敗的回退安全性。
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/130200.html
摘要:利用快速構建系統。構建系統和的安裝本文不再贅述,直接開始動手構建系統。分別為和,用于讀寫組,用于只讀組。最后配置的監控服務可選,非必須至此,一個全部基于開源應用的簡易系統就構建好了。利用ProxySQL、MySQL、ClickHouse快速構建HTAP系統。1. 關于ClickHouse企業里隨著數據量的增加,以及日趨復雜的分析性業務需求,主要適用于OLTP場景的MySQL壓力越來越大。多年...
摘要:我這里的實驗環境單機單主,已經配置好了讀寫分離策略。這些都不是本文的重點,就一帶而過吧。我下面只貼基于指紋的阻斷的配置。我這里的實驗環境:單機proxysql+mgr單主,已經配置好了讀寫分離策略。這些都不是本文的重點,就一帶而過吧。我下面只貼基于sql指紋的阻斷的配置。我們這里先查看下當前proxysql的 query rule表nonerule_idactivedigestmatch_p...
摘要:我這里的實驗環境單機單主,已經配置好了讀寫分離策略。這些都不是本文的重點,就一帶而過吧。我下面只貼基于指紋的阻斷的配置。我這里的實驗環境:單機proxysql+mgr單主,已經配置好了讀寫分離策略。這些都不是本文的重點,就一帶而過吧。我下面只貼基于sql指紋的阻斷的配置。我們這里先查看下當前proxysql的 query rule表nonerule_idactivedigestmatch_p...
摘要:讀寫分離中間件具有獨立的。變量語句將被廣播考慮到節點間數據一致性問題,只會分發到主節點。節點健康檢查,提升數據庫系統可用性。UCloud MySQL云數據庫讀寫分離 背景 數據顯示,關系型數據庫在OLTP業務下96.87%都在等待讀I/O,而處理器計算僅僅占了5.3%,這說明要提高數據庫的QPS性能,關鍵的一點是提高系統的IO能力。 另一個數據表明, 大多數業務對數據庫的訪...
摘要:第一次接觸集群,感謝官方的指導文檔和許多網友提供的教程,糊糊涂涂算是把集群部署起來了。應該為每個運行的機器添加一個,否則集群處于狀態。至此的集群搭建算是完成了,下一步會進行塊設備的搭建。參考分布式存儲部署手冊如何在中安裝存儲集群部署版 第一次接觸ceph集群,感謝官方的指導文檔和許多網友提供的教程,糊糊涂涂算是把集群部署起來了。由于Luminous12.2剛發布不久,部署起來跟舊版本還...
MySQL集群MGR升級實施測試方案 img{ display:block; margin:0 auto !important; width:100%; } body{ width:75%; ...
閱讀 1351·2023-01-11 13:20
閱讀 1696·2023-01-11 13:20
閱讀 1209·2023-01-11 13:20
閱讀 1901·2023-01-11 13:20
閱讀 4160·2023-01-11 13:20
閱讀 2739·2023-01-11 13:20
閱讀 1393·2023-01-11 13:20
閱讀 3662·2023-01-11 13:20