操作系統(tǒng):CentOS Linux release 7.3.1611 (Core)
數(shù)據(jù)庫:MariaDB-10.2.6-linux-glibc_214-x86_64
MaxScale服務(wù)器:10.200.10.55
主服務(wù)器:172.16.8.56
從服務(wù)器:172.16.8.57
從服務(wù)器:172.16.8.58
1.maxscale的安裝方式有很多盐固,例如源碼安裝、rpm、二進(jìn)制構(gòu)建等挣菲,我選擇二進(jìn)制進(jìn)行安裝。
根據(jù)場景需要下載相對應(yīng)的版本网持,下載地址荚恶;https://mariadb.com/downloads/maxscale
[root@localhost ~]# groupadd maxscale
[root@localhost ~]# useradd -g maxscale maxscale
[root@localhost ~]# cd /usr/local
[root@localhost local]# wget https://downloads.mariadb.com/MaxScale/2.1.3/centos/7server/x86_64/maxscale-2.1.3.centos.7.tar.gz
[root@localhost local]# tar zxvf maxscale-2.1.3.centos.7.tar.gz
[root@localhost local]# ln -s maxscale-2.1.3.centos.7 maxscale
[root@localhost local]# cd maxscale
[root@zhu56 maxscale]# chown -R maxscale var
建議創(chuàng)建軟連接,這樣有助于以后的版本升級及后期維護(hù)试吁。
2.首次安裝maxscale需要創(chuàng)建日志相關(guān)目錄
[root@localhost ~]# mkdir /var/log/maxscale
[root@localhost ~]# mkdir /var/lib/maxscale
[root@localhost ~]# mkdir /var/run/maxscale
[root@localhost ~]# mkdir /var/cache/maxscale
3.以下目錄必須具備maxscala用戶權(quán)限
[root@localhost ~]# chown maxscale /var/log/maxscale
[root@localhost ~]# chown maxscale /var/lib/maxscale
[root@localhost ~]# chown maxscale /var/run/maxscale
[root@localhost ~]# chown maxscale /var/cache/maxscale
4.為了能讓Maxscale能順利啟動棺棵,還需要創(chuàng)建配置文件楼咳,在Maxscale目錄下有配置文件模板拷貝到etc下即可。
[root@localhost ~]# cp /usr/local/maxscale/etc/maxscale.cnf.template /etc/maxscale.cnf
5.在修改配置文件之前烛恤,需要在主服務(wù)器上創(chuàng)建一個用戶并給予授權(quán)母怜,而這個用戶用于MySQL監(jiān)控、路由功能
MariaDB [(none)]> create user 'jiankongdb'@'%' identified by 'jiankong123';
MariaDB [(none)]> grant SELECT on mysql.user to 'jiankongdb'@'%';
MariaDB [(none)]> GRANT SELECT ON mysql.db TO 'jiankongdb'@'%';
MariaDB [(none)]> GRANT SELECT ON mysql.tables_priv TO 'jiankongdb'@'%';
MariaDB [(none)]> GRANT SHOW DATABASES ON *.* TO 'jiankongdb'@'%';
MariaDB [(none)]> grant REPLICATION CLIENT on *.* to 'jiankongdb'@'%';
MariaDB [(none)]> GRANT replication slave, replication client,SELECT ON *.* TO jiankongdb@'%';
6.查看授權(quán)情況
MariaDB [(none)]> SHOW GRANTS FOR'jiankong'@'%';
7.接下來就開始修改maxscale.cnf配置文件缚柏,否則無法啟動苹熏。
[root@localhost ~]# vim /etc/maxscale.cnf
# MaxScale documentation on GitHub:
# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Documentation-Contents.md
# Global parameters
#
# Complete list of configuration options:
# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Getting-Started/Configuration-Guide.md
#全局配置
[maxscale]
threads=1
# Server definitions
#
# Set the address of the server to the network
# address of a MySQL server.
#
[server1]
type=server
address=172.16.8.56
port=3306
protocol=MySQLBackend
serv_weight=1
[server2]
type=server
address=172.16.8.57
port=3306
protocol=MySQLBackend
serv_weight=3
[server3]
type=server
address=172.16.8.58
port=3306
protocol=MySQLBackend
serv_weight=3
# Monitor for the servers
#
# This will keep MaxScale aware of the state of the servers.
# MySQL Monitor documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Monitors/MySQL-Monitor.md
#MariaDB狀態(tài)監(jiān)控
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3
user=jiankong
passwd=jiankong123
monitor_interval=10000
detect_stale_master=true #即使從全掛掉,保證主擔(dān)任讀寫
# Service definitions
#
# Service Definition for a read-only service and
# a read/write splitting service.
#
# ReadConnRoute documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadConnRoute.md
#讀
[Read-Only Service]
type=service
router=readconnroute
servers=server1,server2,server3
user=jiankong
passwd=jiankong123
router_options=slave
enable_root_user=1 #允許root用戶登錄執(zhí)行
weightby=serv_weight #主從權(quán)重
# ReadWriteSplit documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Routers/ReadWriteSplit.md
#寫
[Read-Write Service]
type=service
router=readwritesplit
servers=server1,server2,server3
user=jiankong
passwd=jiankong123
max_slave_connections=100%
use_sql_variables_in=master #保證會話的一致性
enable_root_user=1 #允許root登錄
max_slave_replication_lag=3600 #允許從超出主的同步時間,超出則不路由
# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://github.com/mariadb-corporation/MaxScale/blob/2.1/Documentation/Reference/MaxAdmin.md
[MaxAdmin Service]
type=service
router=cli
# Listener definitions for the services
#
# These listeners represent the ports the
# services will listen on.
#
[Read-Only Listener]
type=listener
service=Read-Only Service
protocol=MySQLClient
port=4008
[Read-Write Listener]
type=listener
service=Read-Write Service
protocol=MySQLClient
port=4006
[MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
socket=default
保存并退出。
8.下面創(chuàng)建啟動腳本
[root@localhost ~]# cp /usr/local/maxscale-2.1.3.centos.7/share/maxscale.service /usr/lib/systemd/system/
[root@localhost ~]# vim /usr/lib/systemd/system/maxscale.service
9.修改maxscale.service中的ExecStart=///bin/maxscale為ExecStart=/usr/local/maxscale/bin/maxscale
[root@localhost ~]# chmod 755 /usr/lib/systemd/system/maxscale.service
[root@localhost ~]# systemctl enable maxscale
[root@localhost ~]# systemctl daemon-reload
[root@localhost ~]# systemctl start maxscale
10.添加變量值
[root@localhost ~]# vi /etc/profile //最后一行添加以下內(nèi)容保存退出币喧!
PATH=$PATH:/usr/local/maxscale/bin
export PATH
[root@localhost ~]# source /etc/profile //使其變量立即生效
11.接下來就可以使用MaxAdmin進(jìn)行管理轨域。MaxAdmin是一個簡單的客戶端管理界面,可用于與MariaDB MaxScale服務(wù)器進(jìn)行交互杀餐,可以顯示MariaDB MaxScale內(nèi)部的統(tǒng)計信息狀態(tài)以及對MariaDB MaxScale操作的控制干发。詳情:
https://mariadb.com/kb/en/mariadb-enterprise/maxadmin-admin-interface/
[root@localhost ~]# maxadmin //回車
MaxScale> list servers
Servers.
---------------+--------------+-------+-------------+-----------------
Server | Address | Port | Connections | Status
---------------+--------------+-------+-------------+-----------------
server1 | 172.16.8.56 | 3306 | 0 | Master, Running
server2 | 172.16.8.57 | 3306 | 0 | Slave, Running
server2 | 172.16.8.58 | 3306 | 0 | Slave, Running
---------------+--------------+-------+-------------+-----------------
12.至此MaxScale已經(jīng)配置完成。現(xiàn)在就可以使用客戶端連接Maxscale服務(wù)器端 端口為4006史翘。
版權(quán)聲明:本站原創(chuàng)文章枉长,歡迎任何形式的轉(zhuǎn)載。
轉(zhuǎn)載請注明:MariaDB MaxScale 2.1.3中間件數(shù)據(jù)庫讀寫分離安裝配置 | 任我樂