溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

Maxscale介紹和應(yīng)用

發(fā)布時(shí)間:2020-08-03 22:28:44 來(lái)源:網(wǎng)絡(luò) 閱讀:176 作者:wjw555 欄目:系統(tǒng)運(yùn)維

本博文演示環(huán)境:
centos7.2 x86_64 最小化安裝。3臺(tái)vm 時(shí)間同步,關(guān)閉iptables,selinux.,firewalld。3臺(tái)rpm包安裝MariaDB10.5.1 .172.16.0.130機(jī)器單獨(dú)安裝 maxscale-2.3.7

172.16.0.130    master    maxscale
172.16.0.131    slave1
172.16.0.132    slave2

一.Maxscale簡(jiǎn)單介紹:

如何配置MariaDB MaxScale,并介紹了一些可能的使用方案。 MariaDB MaxScale在設(shè)計(jì)時(shí)考慮了靈活性,它由事件處理核心和各種支持功能以及可定制程序行為的插件模塊組成
MariaDB MaxScale是一種數(shù)據(jù)庫(kù)代理,可擴(kuò)展MariaDB Server的高可用性,可伸縮性和安全性,同時(shí)通過將其與基礎(chǔ)數(shù)據(jù)庫(kù)基礎(chǔ)架構(gòu)分離來(lái)簡(jiǎn)化應(yīng)用程序開發(fā)。
MariaDB MaxScale采用可擴(kuò)展的體系結(jié)構(gòu)進(jìn)行工程設(shè)計(jì),以支持插件,從而將其功能擴(kuò)展到透明負(fù)載平衡之外,從而成為例如數(shù)據(jù)庫(kù)防火墻。
借助用于多個(gè)路由器,過濾器和協(xié)議的內(nèi)置插件,可以將MariaDB MaxScale配置為轉(zhuǎn)發(fā)數(shù)據(jù)庫(kù)請(qǐng)求并根據(jù)業(yè)務(wù)和技術(shù)要求修改數(shù)據(jù)庫(kù)響應(yīng),例如,以屏蔽敏感數(shù)據(jù)或擴(kuò)展讀取

MariaDB MaxScale是一種數(shù)據(jù)庫(kù)代理,可將數(shù)據(jù)庫(kù)語(yǔ)句轉(zhuǎn)發(fā)到一個(gè)或多個(gè)數(shù)據(jù)庫(kù)服務(wù)器
使用基于數(shù)據(jù)庫(kù)語(yǔ)句的語(yǔ)義理解以及數(shù)據(jù)庫(kù)后端集群中服務(wù)器的角色的規(guī)則執(zhí)行轉(zhuǎn)發(fā)。
MariaDB MaxScale旨在向應(yīng)用程序透明地提供負(fù)載平衡和高可用功能。
MariaDB MaxScale具有可擴(kuò)展且靈活的體系結(jié)構(gòu),其插件組件可支持不同的協(xié)議和路由方法

MariaDB MaxScale充分利用了Linux操作系統(tǒng)的異步I / O功能以及固定數(shù)量的工作線程。
epoll用于為通過套接字的輸入和輸出提供事件驅(qū)動(dòng)的框架。
MariaDB MaxScale提供的許多服務(wù)都實(shí)現(xiàn)為在運(yùn)行時(shí)加載的外部共享對(duì)象模塊。
這些模塊支持固定接口,并通過由一組功能指針組成的結(jié)構(gòu)傳遞入口點(diǎn)。該結(jié)構(gòu)稱為“模塊對(duì)象”??梢詣?chuàng)建其他模塊以與MariaDB MaxScale一起使用。
常用的模塊類型是協(xié)議,路由器和過濾器。協(xié)議模塊實(shí)現(xiàn)了客戶端與MariaDB MaxScale之間以及MariaDB MaxScale與后端服務(wù)器之間的通信。
路由器檢查來(lái)自客戶端的查詢并確定目標(biāo)后端。這些決定通常基于路由規(guī)則和后端服務(wù)器狀態(tài)。
過濾器對(duì)通過MariaDB MaxScale傳遞的數(shù)據(jù)進(jìn)行處理。
篩選器通常用于記錄查詢或修改服務(wù)器響應(yīng)。

二.Maxscale 安裝:

支持源碼包編譯安裝,支持rpm包安裝,也支持二進(jìn)制tar包安裝
官方安裝文檔:
提問地址:
https://github.com/mariadb-corporation/MaxScale/tree/2.3/Documentation

反饋bug地址:
https://jira.mariadb.org/browse/MXS

本演示環(huán)境安裝的是maxscale 是2.3.7 ,下面是官方的安裝文檔介紹
https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-maxscale-installation-guide/

本博文采用的是rpm包安裝,最簡(jiǎn)單

 yum install libaio.x86_64 libaio-devel.x86_64 novacom-server.x86_64 libedit -y
 wget https://downloads.mariadb.com/MaxScale/centos/7/x86_64/maxscale-2.3.7-1.centos.7.x86_64.rpm
rpm -ivh maxscale-2.3.7-1.centos.7.x86_64.rpm

 關(guān)閉和啟動(dòng)命令:
  service maxscale status|start|stop|restart
  systemctl enable maxscale
  systemctl  status|start|stop maxscale
  maxadmin shutdown maxscale

maxscale 管理賬戶登錄: 默認(rèn)賬戶:admin 
[root@mgr01 ~]# maxadmin -h227.0.0.1 -P6603 -uadmin -p'mariadb'

三.配置文件介紹:

默認(rèn)配置文件在/etc/maxscale.cnf

官方模塊參數(shù)介紹地址:
https://mariadb.com/kb/en/mariadb-maxscale-23-contents/#routers
配置文件參數(shù)介紹:
https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-maxscale-configuration-usage-scenarios/

在名為[MaxScale]的部分中的全局設(shè)置允許調(diào)整影響整個(gè)MariaDB MaxScale的各種參數(shù)。此部分必須在默認(rèn)為/etc/maxscale.cnf的根配置文件中定義
參數(shù):threads 介紹:threads=[<number of threads> | auto ] 默認(rèn)是1,最好是根據(jù)實(shí)際需要來(lái)調(diào)整
將工作線程數(shù)量增加到超過處理器內(nèi)核數(shù)量并不會(huì)提高性能,反而可能降低性能,并且可能不必要地消耗資源。

演示成功的配置文件內(nèi)容:

[root@mgr03 ~]# cat /etc/maxscale.cnf
#https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-maxscale-configuration-usage-scenarios/
[maxscale]
#threads=auto
threads=1
log_info=1
logdir=/tmp/
auth_read_timeout=10 
#提取用戶身份驗(yàn)證數(shù)據(jù)時(shí),MySQL與后端數(shù)據(jù)庫(kù)的連接的讀取超時(shí)(以秒為單位)。增加此參數(shù)的值將導(dǎo)致在主動(dòng)獲取用戶數(shù)據(jù)時(shí),MariaDB MaxScale等待更長(zhǎng)的時(shí)間來(lái)等待來(lái)自后端服務(wù)器的響應(yīng)。如果身份驗(yàn)證失敗,并且您有大量的數(shù)據(jù)庫(kù)用戶和授權(quán),或者與后端服務(wù)器的連接速度很慢,則增加此值是個(gè)好主意。默認(rèn)為1秒.
auth_write_timeout=10
#提取用戶身份驗(yàn)證數(shù)據(jù)時(shí),MySQL與后端數(shù)據(jù)庫(kù)的連接的寫入超時(shí)(以秒為單位),當(dāng)前,MariaDB MaxScale不會(huì)在后端服務(wù)器中寫入或修改數(shù)據(jù)。默認(rèn)值為2秒。官方建議10s
query_retries=1
#被重試的內(nèi)部查詢的次數(shù)。默認(rèn)值為重試一次.中斷查詢是指任何因網(wǎng)絡(luò)錯(cuò)誤而中斷的查詢。連接超時(shí)包括在網(wǎng)絡(luò)錯(cuò)誤中,因此建議確保將query_retry_timeout的值設(shè)置為適當(dāng)?shù)闹怠?.3.0之后默認(rèn)開啟
query_retry_timeout=5
##任何重試查詢的總超時(shí)時(shí)間(以秒為單位)。默認(rèn)值為5秒,
ms_timestamp=1
#       ms_timestamp=<0|1>。
#       在日志文件中啟用或禁用高精度時(shí)間戳。啟用此選項(xiàng)可以為所有日志文件時(shí)間戳增加毫秒精度。
skip_permission_checks=false 
#默認(rèn)是false.
#當(dāng)您知道權(quán)限確定并且想要加快啟動(dòng)過程時(shí),此功能很有用。此參數(shù)為布爾值,默認(rèn)情況下處于禁用狀態(tài)
#建議不要禁用權(quán)限檢查,以便在啟動(dòng)maxscale時(shí)檢測(cè)到任何缺少的特權(quán)。如果由于在檢查權(quán)限時(shí)發(fā)生大量連接超時(shí)而導(dǎo)致MaxScale啟動(dòng)緩慢,則禁用權(quán)限檢查可以加快啟動(dòng)過程。

syslog=1
#       syslog=<0|1>. 
#啟用或禁用將消息記錄到syslog。默認(rèn)情況下,啟用到syslog的日志記錄
maxlog=1
# 啟用以禁用將消息記錄到MariaDB MaxScale的日志文件中. 默認(rèn)情況下,啟用對(duì)maxlog的日志記錄。
# 要啟用到MariaDB MaxScale日志文件的日志記錄,請(qǐng)使用值1,而禁用則使用值0。
log_warning=1
#       log_warning=<0|1>,
#       啟用或禁用系統(tǒng)日志優(yōu)先級(jí)為警告的消息的日志記錄。默認(rèn)情況下,啟用此優(yōu)先級(jí)的消息.
log_notice=1
#啟用或禁用系統(tǒng)日志優(yōu)先級(jí)為notice的消息的日志記錄。此優(yōu)先級(jí)的消息提供有關(guān)MariaDB MaxScale的功能的信息,并且默認(rèn)情況下處于啟用狀態(tài)。
##要禁用這些消息,請(qǐng)使用值0,而要啟用它們,請(qǐng)使用值1

log_debug=0
[server1]
type=server
address=172.16.0.131
port=3306
#protocol=MySQLBackend
protocol=MariaDBBackend
#server_weight=1
serversize=1
[server2]
type=server
address=172.16.0.132
port=3306
#protocol=MySQLBackend
protocol=MariaDBBackend
#server_weight=1
serversize=1
[server3]
type=server
address=172.16.0.130
port=3306
#protocol=MySQLBackend
protocol=MariaDBBackend
#server_weight=1
serversize=1

# https://mariadb.com/kb/en/mariadb-maxscale-23-mariadb-monitor/
[MySQL Monitor]
type=monitor
module=mariadbmon
servers=server1,server2,server3
user=maxmonuser
password=maxmonpwd
monitor_interval=10000
##monitor_interval=10000 #探測(cè)間隔,單位毫秒,默認(rèn)2000
auto_failover=true
#是否故障自動(dòng)切換
auto_rejoin=true
#故障實(shí)例恢復(fù)后自動(dòng)加入集群
detect_standalone_master=true
#探測(cè)獨(dú)立的master,是否允許集群中最后一個(gè)實(shí)例成為主庫(kù)
#switchover_on_low_disk_space=true
##為了使此參數(shù)生效,必須為服務(wù)器或監(jiān)視器指定disk_space_threshold。另外,必須為監(jiān)視器定義disk_space_check_interval

#allow_cluster_recovery=true
failcount=3 
#在集群中最后一個(gè)實(shí)例成為主庫(kù)前檢查其它從庫(kù)是否存活的次數(shù),默認(rèn)為5
detect_stale_master=true 
#此參數(shù)從2.0版本開始默認(rèn)就是開啟的,即使復(fù)制停止或配置錯(cuò)誤,也允許先前的主服務(wù)器可用。所有從屬服務(wù)器均不可訪問或復(fù)制由于某種原因而中斷,master依然可以繼續(xù)提供服務(wù)。
detect_stale_slave=true
#此參數(shù)默認(rèn)是開啟的,將沒有主服務(wù)器的正在運(yùn)行的從服務(wù)器視為有效的從服務(wù)器。slave丟失master時(shí),slave仍可用于讀取。
failover_timeout=90
#此參數(shù)默認(rèn)是90s,如果在配置的時(shí)間段內(nèi)未成功進(jìn)行故障轉(zhuǎn)移/切換,則會(huì)記錄一條消息,并禁用自動(dòng)故障轉(zhuǎn)移。這樣可以防止對(duì)行為異常的群集進(jìn)行進(jìn)一步的自動(dòng)修改.
verify_master_failure=true
master_failure_timeout=10
#啟用其他主服務(wù)器故障驗(yàn)證以進(jìn)行自動(dòng)故障轉(zhuǎn)移.verify_master_failure默認(rèn)開啟,是布爾值,master_failure_timeout默認(rèn)是10.

script=/tmp/reset_slave.sh
events=master_down 
#檢查到master掛掉的話,執(zhí)行上面的腳本/tmp/reset_slave.sh

# https://mariadb.com/kb/en/mariadb-maxscale-23-readconnroute/
[Read-Only-Service]
type=service
router=readconnroute
servers=server1,server2,server3
user=maxuser
password=maxpwd
router_options=slave
#router_options=master,slave
#weightby=server_weight
# ReadWriteSplit documentation:
# https://mariadb.com/kb/en/mariadb-maxscale-23-readwritesplit/

[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=maxuser
password=maxpwd
#max_slave_connections=100%
max_slave_connections=2
#設(shè)置路由器會(huì)話隨時(shí)使用的最大從站數(shù)量。默認(rèn)值是每個(gè)客戶端連接最多使用255個(gè)從屬連接。在舊版本中,默認(rèn)設(shè)置是不加限制地使用所有可用的從站。
# 例如,如果您為MaxScale配置了一個(gè)主機(jī)和三個(gè)從機(jī),并設(shè)置max_slave_connections = 2,則對(duì)于每個(gè)客戶端連接,將打開到主機(jī)的連接和兩個(gè)從機(jī)連接。然后,在這兩個(gè)從屬服務(wù)器之間完成讀查詢負(fù)載平衡,并將寫操作發(fā)送到主服務(wù)器.
max_slave_replication_lag=4
#指定從站被允許落后于主站多少秒。如果滯后時(shí)間大于配置的值,則不能使用從站進(jìn)行路由.
master_accept_reads=true
#默認(rèn)讀是不被路由到master的。允許將主服務(wù)器用于讀取。如果您使用的服務(wù)器數(shù)量較少,并且希望也使用主服務(wù)器進(jìn)行讀取,則啟用此選項(xiàng)非常有用
#weightby=server_weight

# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://mariadb.com/kb/en/mariadb-maxscale-23-maxadmin-admin-interface/

[MaxAdmin-Service]
type=service
router=cli

[Read-Only-Listener]
type=listener
service=Read-Only-Service
#protocol=MySQLClient
protocol=MariaDBClient
port=4008

[Read-Write-Listener]
type=listener
service=Read-Write-Service
#protocol=MySQLClient
protocol=MariaDBClient
port=4006

[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
#socket=default
port=6603

四.提前配置好Mariadb 1主2從:

4.1配置基于gitd的主從復(fù)制

注意:在配置主從復(fù)制時(shí),maxscale監(jiān)控集群不識(shí)別主機(jī)名,只識(shí)別ip地址
所以在 CHANGE MASTER TO MASTER_HOST='172.16.0.130',MASTER_PORT=3306,MASTER_USER='repuser',MASTER_PASSWORD='JuwoSdk21TbUser',master_use_gtid=slave_pos;start slave;show slave status\G 時(shí),記得MASTER_HOST必須填寫ip地址,
否則會(huì)導(dǎo)致監(jiān)控主從復(fù)制集群失敗。

例如slave上:

CHANGE MASTER TO MASTER_HOST='mgr01',MASTER_PORT=3306,MASTER_USER='repuser',MASTER_PASSWORD='JuwoSdk21TbUser',master_use_gtid=slave_pos;start slave;show slave status\G
[root@mgr01 ~]#  maxadmin -h227.0.0.1 -P6603 -uadmin -p'mariadb'
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server             | Address         | Port  | Connections | Status              
-------------------+-----------------+-------+-------------+--------------------
server1            | 172.16.0.131    |  3306 |           0 | Master, Slave of External Server, Running
server2            | 172.16.0.132    |  3306 |           0 | Slave of External Server, Running
server3            | 172.16.0.130    |  3306 |           0 | Slave, Running
-------------------+-----------------+-------+-------------+--------------------

Master, Slave of External Server, Running 像這樣的代表監(jiān)控主從復(fù)制集群關(guān)系失敗。
Slave of External Server, Running

例如slave上:


CHANGE MASTER TO MASTER_HOST='172.16.0.130',MASTER_PORT=3306,MASTER_USER='repuser',MASTER_PASSWORD='JuwoSdk21TbUser',master_use_gtid=slave_pos;start slave;show slave status\G

[root@mgr01 ~]# maxadmin -h227.0.0.1 -P6603 -uadmin -p'mariadb'
MaxScale> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server             | Address         | Port  | Connections | Status              
-------------------+-----------------+-------+-------------+--------------------
server1            | 172.16.0.131    |  3306 |           0 | Slave, Running
server2            | 172.16.0.132    |  3306 |           0 | Slave, Running
server3            | 172.16.0.130    |  3306 |           0 | Master, Running
-------------------+-----------------+-------+-------------+--------------------

以上status代表正常

4.2 數(shù)據(jù)庫(kù)賬戶創(chuàng)建和授權(quán):

1.監(jiān)控后端mysql服務(wù)的狀態(tài)
2.復(fù)制集群操作(failover,switchover,rejoin,reset-replication)

要求監(jiān)視用戶具有以下特權(quán):

create user 'maxmonuser'@'%' identified by 'maxmonpwd';
grant super, REPLICATION SLAVE,replication client, reload, process, show databases,event on *.* to 'maxmonuser'@'%';

權(quán)限作用介紹:

SUPER, to modify slave connections and set globals such as read_only
REPLICATION CLIENT, to list slave connections
RELOAD, to flush binary logs
PROCESS, to check if the event_scheduler process is running
SHOW DATABASES and EVENT, to list and modify server events

授權(quán)注意事項(xiàng):

grant super, replication client, reload, process, show databases,event on *.* to 'maxmonuser'@'172.16.0.%';
MariaDB不支持上述方式的授權(quán),只能采用下面方法授權(quán)。
grant super, replication client, reload, process, show databases,event on *.* to 'maxmonuser'@'%';

五.讀寫分離配置和測(cè)試:

創(chuàng)建讀寫分離操作后端mysql服務(wù)的賬戶:

create user 'maxuser'@'172.16.0.%' identified by 'maxpwd';
grant SELECT on mysql.* to 'maxuser'@'172.16.0.%';
GRANT SHOW DATABASES,super  ON *.* TO 'maxuser'@'172.16.0.%';
select user,host from mysql.user;

創(chuàng)建測(cè)試用戶:

grant all on *.* to 'maxscale'@'172.16.0.%' identified by 'maxscalepass'; flush privileges;
或者
grant all on *.* to 'maxscale'@'%' identified by 'maxscalepass'; flush privileges;

通過maxscale機(jī)器ip 和maxscale.cnf配置文件中指定的4006端口來(lái)登錄進(jìn)行讀寫庫(kù)
mysql -umaxscale -p'maxscalepass' -h 172.16.0.130 -P4006

讀寫分離配置:
https://mariadb.com/kb/en/mariadb-maxscale-23-readwritesplit/#readwritesplit

讀寫分割路由決策:
下面的動(dòng)作會(huì)被路由到master上:

write statements,
all statements within an open transaction,
stored procedure calls
user-defined function calls
DDL statements (DROP|CREATE|ALTER TABLE … etc.)
EXECUTE (prepared) statements that modify the database
all statements using temporary tables

如果用max_slave_replication_lag參數(shù)配置了readwritesplit服務(wù),并且如果所有從屬服務(wù)器都遭受過多的復(fù)制滯后,則語(yǔ)句將被路由到主服務(wù)器或者其他的slave上。
加入設(shè)定為:max_slave_replication_lag=4
#指定從站被允許落后于主站多少秒。如果滯后時(shí)間大于配置的值,則不能使用從站進(jìn)行路由.
日志內(nèi)容warning如下:

2020-02-28 21:52:59.040   info   : (4) Route query to master: server3   [172.16.0.130]:3306 <
2020-02-28 21:52:59.057   info   : (4) Reply complete, last reply from server3
2020-02-28 21:52:59.059   info   : (4) > Autocommit: [enabled], trx is [not open], cmd: (0x03) COM_QUERY, plen: 29, type: QUERY_TYPE_READ, stmt: select * from test_event 
2020-02-28 21:52:59.059   info   : (4) Route query to slave: server1    [172.16.0.131]:3306 <
2020-02-28 21:52:59.060   info   : (4) Reply complete, last reply from server1
2020-02-28 21:52:59.495   info   : (4) > Autocommit: [enabled], trx is [not open], cmd: (0x03) COM_QUERY, plen: 90, type: QUERY_TYPE_WRITE, stmt: insert into test_event(username,password,create_time) values("李四","tomcat",now()) 
2020-02-28 21:52:59.495   info   : (4) Route query to master: server3   [172.16.0.130]:3306 <
2020-02-28 21:52:59.511   info   : (4) Reply complete, last reply from server3
2020-02-28 21:52:59.513   info   : (4) > Autocommit: [enabled], trx is [not open], cmd: (0x03) COM_QUERY, plen: 29, type: QUERY_TYPE_READ, stmt: select * from test_event 
2020-02-28 21:52:59.513   warning: (4) Replication lag of 'server1' is 48s, which is above the configured limit 4s. 'server1' is excluded from query routing.
2020-02-28 21:52:59.514   info   : (4) Route query to slave: server2    [172.16.0.132]:3306 <
2020-02-28 21:52:59.535   info   : (4) Reply complete, last reply from server2
2020-02-28 21:52:59.906   info   : (4) > Autocommit: [enabled], trx is [not open], cmd: (0x03) COM_QUERY, plen: 90, type: QUERY_TYPE_WRITE, stmt: insert into test_event(username,password,create_time) values("李四","tomcat",now()) 
2020-02-28 21:52:59.908   info   : (4) Route query to master: server3   [172.16.0.130]:3306 <
2020-02-28 21:52:59.929   info   : (4) Reply complete, last reply from server3
2020-02-28 21:52:59.935   info   : (4) > Autocommit: [enabled], trx is [not open], cmd: (0x03) COM_QUERY, plen: 29, type: QUERY_TYPE_READ, stmt: select * from test_event 
2020-02-28 21:52:59.935   info   : (4) Route query to slave: server2    [172.16.0.132]:3306 <
2020-02-28 21:52:59.950   info   : (4) Reply complete, last reply from server2
2020-02-28 21:53:00.304   info   : (4) > Autocommit: [enabled], trx is [not open], cmd: (0x03) COM_QUERY, plen: 90, type: QUERY_TYPE_WRITE, stmt: insert into test_event(username,password,create_time) values("李四","tomcat",now()) 

被路由到slave上的情況:

可以路由到從站的查詢必須是自動(dòng)提交的,并且屬于以下組之一
read-only database queries,
read-only queries to system, or user-defined variables,
SHOW statements
system function calls.

六.故障自動(dòng)切換:

A: Failover故障自動(dòng)轉(zhuǎn)移將發(fā)生故障的主節(jié)點(diǎn)替換為正在運(yùn)行的從節(jié)點(diǎn)。它執(zhí)行以下操作:

6.1選擇舊主機(jī)的最新從機(jī)作為新主機(jī)。選擇標(biāo)準(zhǔn)按降序排列


1.gtid_IO_pos (latest event in relay log)
2.gtid_current_pos (most processed events)
3.log_slave_updates is on
4.disk space is not low

6.2如果新的主服務(wù)器具有未處理的中繼日志項(xiàng)目,請(qǐng)取消并稍后重試

6.3 準(zhǔn)備新的master

1.從舊的主服務(wù)器上刪除新主服務(wù)器用來(lái)復(fù)制的從服務(wù)器連接。
2.關(guān)閉新master上的read_only參數(shù)
3.啟用計(jì)劃的服務(wù)器事件(如果啟用了事件處理)。僅啟用在舊主機(jī)上啟用的事件
4運(yùn)行promotion_sql_file中的命令
5.如果存在外部主服務(wù)器,則開始復(fù)制

6.4重定向所有其他從屬服務(wù)器以從新的主服務(wù)器復(fù)制

STOP SLAVE and RESET SLAVE
CHANGE MASTER TO
START SLAVE

6.5檢查所有從屬是否正在復(fù)制
如果步驟6.1到6.3成功,則故障轉(zhuǎn)移被視為成功,因?yàn)槿杭辽倬哂幸粋€(gè)有效的主服務(wù)器

B: Switchover手動(dòng)切換將正在運(yùn)行的master與正在運(yùn)行的slave交換。它執(zhí)行以下操作:

1.準(zhǔn)備降級(jí)的舊的master:

Stop any external replication.
Kill connections from super-users since read_only does not affect them.
Enable the read_only-flag to stop writes.
Disable scheduled server events (if event handling is on).
Run the commands in demotion_sql_file.
Flush the binary log (FLUSH LOGS) so that all events are on disk.

2.等待新的master趕上舊的master
3.像故障轉(zhuǎn)移步驟3和4一樣,升級(jí)新的主服務(wù)器并重定向從服務(wù)器。還要重定向已降級(jí)的舊主服務(wù)器
4.檢查所有從屬是否正在復(fù)制

提示:Failover/switchover requires MariaDB 10.0.2 or later

七.自動(dòng)重新加入到集群:

Rejoin將獨(dú)立服務(wù)器加入群集,或重定向從非主服務(wù)器復(fù)制的從服務(wù)器。獨(dú)立服務(wù)器通過以下方式加入:

Run the commands in demotion_sql_file.
Enable the read_only-flag.
Disable scheduled server events (if event handling is on).
Start replication: CHANGE MASTER TO and START SLAVE.

從錯(cuò)誤的主服務(wù)器復(fù)制的服務(wù)器僅通過STOP SLAVE,RESET SLAVE,CHANGE MASTER TO和START SLAVE命令進(jìn)行重定向

八.數(shù)據(jù)庫(kù)賬戶權(quán)限:

提示數(shù)據(jù)庫(kù)賬戶權(quán)限:

(root@'mgr03':mysql.sock)[(none)]>show grants for maxmonuser@'%';
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| Grants for maxmonuser@%                                                                                                                                  |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
| GRANT RELOAD, SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO `maxmonuser`@`%` IDENTIFIED BY PASSWORD '*DE290C4A038E4E06BB0AF2C0B8B01ABB51572796' |
+----------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

(root@'mgr03':mysql.sock)[(none)]>show grants for maxscale@'%';
+------------------------------------------------------------------------------------------------------------------+
| Grants for maxscale@%                                                                                            |
+------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO `maxscale`@`%` IDENTIFIED BY PASSWORD '*E7ACDE28142BFC311A2CE191B3CB3E510A27EB60' |
+------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

(root@'mgr03':mysql.sock)[(none)]>show grants for maxuser@'172.16.0.%';
+---------------------------------------------------------------------------------------------------------------------------------+
| Grants for maxuser@172.16.0.%                                                                                                   |
+---------------------------------------------------------------------------------------------------------------------------------+
| GRANT SHOW DATABASES, SUPER ON *.* TO `maxuser`@`172.16.0.%` IDENTIFIED BY PASSWORD '*5EDBD32E469DAE0CE10E6999C3899DEFCB9F12E0' |
| GRANT SELECT ON `mysql`.* TO `maxuser`@`172.16.0.%`                                                                             |
+---------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

(root@'mgr03':mysql.sock)[(none)]>show grants for repuser@'172.16.0.%';
+-----------------------------------------------------------------------------------------------------------------------------+
| Grants for repuser@172.16.0.%                                                                                               |
+-----------------------------------------------------------------------------------------------------------------------------+
| GRANT REPLICATION SLAVE ON *.* TO `repuser`@`172.16.0.%` IDENTIFIED BY PASSWORD '*15BB449A1D5BDA166BB45F5989B2417834A13C23' |
+-----------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

參考文檔資料:
https://blog.51cto.com/linzhijian/1913794
http://udn.yyuap.com/thread-38241-1-1.html
https://downloads.mariadb.com/MaxScale/centos/7/x86_64/
https://blog.csdn.net/weixin_34194551/article/details/92492325
https://blog.csdn.net/thundermeng/article/details/83900503
https://www.jianshu.com/p/1ac435a6510e
http://www.ttlsa.com/mysql/maxscale-install-read-write-split/

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI