您好,登錄后才能下訂單哦!
MaxScale 是 MariaDB 的產(chǎn)品之一,可以很方便的實(shí)現(xiàn)讀寫分離方案;并且提供了讀寫分離的負(fù)載均衡和高可用性保障。
一、安裝配置
前提:先配置好mysql的主從,Maxscale會自動的根據(jù)主從復(fù)制信息來判斷Master和slave
注:不能配置mysql互為主從,如果互為主從,兩臺都會被認(rèn)為slave,在這種情況下,寫請求會被拒絕,只接受讀請求。
1.1.安裝
官網(wǎng)下載對應(yīng)的rpm包,
wget https://downloads.mariadb.com/MaxScale/2.0.3/centos/6server/x86_64/maxscale-2.0.3-1.centos.6.x86_64.rpm rpm -ivh maxscale-2.0.3-1.centos.6.x86_64.rpm
maxscale的配置文件為:/etc/maxscale.conf,配置文件由多個配置模塊組成
vi /etc/maxscale.conf #全局配置: [maxscale] threads=auto log_info=1 log_notice=1 log_warning=1 #后端mysql定義 [server1] type=server address=192.168.10.1 port=3306 protocol=MySQLBackend [server2] type=server address=192.168.10.2 port=3306 protocol=MySQLBackend #監(jiān)控配置 [MySQL Monitor] type=monitor module=mysqlmon #監(jiān)控模塊默認(rèn)使用mysqlmon,當(dāng)然還有其他可選擇的模塊 servers=server1,server2 user=admin #admin監(jiān)控后端mysql的復(fù)制狀況,必須具有REPLICATION CLIENT權(quán)限 passwd=123456 monitor_interval=10000 #觸發(fā)器定義 注意,以下兩句的上下順序不能變,不然無法生效 script=/opt/mysql_monitor.sh #定義事件觸發(fā)腳本執(zhí)行 events=master_down #事件觸發(fā)器當(dāng)master down時,執(zhí)行上面的腳本,maxscale內(nèi)置了很 多的events #讀寫分離service [Read-Write Service] type=service router=readwritesplit #讀寫分離路由模式 servers=server1,server2 user=maxscale #該用戶從后端mysql獲取用戶信息,對客戶端進(jìn)行身份驗(yàn)證,必須具有mysql.user table的select權(quán)限 passwd=maxscale max_slave_connections=100% max_slave_replication_lag=3600000 #當(dāng)slave的數(shù)據(jù)落后master小于3600秒時仍然可用 connection_timeout=300 router_options=master_failure_mode=error_on_write #允許master down掉,slave仍然可讀 #router_options=master_accept_reads=true #允許master接受讀請求 [Read-Write Listener] type=listener service=Read-Write Service protocol=MySQLClient port=3306 #管理服務(wù)配置 [MaxAdmin Service] type=service router=cli #管理服務(wù)監(jiān)聽 [MaxAdmin Listener] type=listener service=MaxAdmin Service protocol=maxscaled socket=default
二、管理
Maxscale提供了maxadmin命令用于查看管理
[root@server ~]# maxadmin list - Unknown or missing option for the list command. Valid sub-commands are: clients List all the client connections to MaxScale dcbs List all the DCBs active within MaxScale filters List all the filters defined within MaxScale listeners List all the listeners defined within MaxScale modules List all currently loaded modules monitors List all monitors services List all the services defined within MaxScale servers List all the servers defined within MaxScale sessions List all the active sessions within MaxScale threads List the status of the polling threads in MaxScale
[root@server ~]# maxadmin list servers Servers. -------------------+-----------------+-------+-------------+-------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+-------------------- server1 | 192.168.10.1 | 3306 | 0 | Master, Running server2 | 192.168.10.2 | 3306 | 0 | Slave, Running -------------------+-----------------+-------+-------------+--------------------
三、高可用性
Maxscale默認(rèn)只提供讀的高可用性,要實(shí)現(xiàn)寫的高可用性,可以使用兩種途徑:
1.需要使用Multi-MasterMonitor監(jiān)控模塊,不同于上文使用的mysqlmon模塊,該模塊是通過read_only參數(shù)來選舉Master和Slave,結(jié)合腳本可以實(shí)現(xiàn)在Master fail的時候,取消slave的read_only屬性,將slave提升為Master
2.使用高可用軟件MMM
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。