安裝rpm
yum install gnutls libaio.x86_64 libaio-devel.x86_64 novacom-server.x86_64 libedit -y
wget https://downloads.mariadb.com/MaxScale/2.2.0/centos/7server/x86_64/maxscale-2.2.0-1.centos.7.x86_64.rpm
rpm -ivh maxscale-2.2.0-1.centos.7.x86_64.rpm
MaxScale服務器修改配置
vi /etc/maxscale.cnf
[maxscale]
threads=1
# 主服務器 3306
[server1]
type=server
address=192.168.91.108
port=3306
protocol=MySQLBackend
# 配置從服務器 3306
[server2]
type=server
address=192.168.91.109
port=3306
protocol=MySQLBackend
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2
user=root
passwd=123456
monitor_interval=10000
detect_stale_master=true
[Read-Write Service]
type=service
router=readwritesplit
servers=server1,server2
user=root
passwd=123456
max_slave_connections=100%
use_sql_variables_in=master
enable_root_user=1
max_slave_replication_lag=3600
[MaxAdmin Service]
type=service
router=cli
[Read-Write Listener]
type=listener
service=Read-Write Service
protocol=MySQLClient
port=3306
[MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
socket=default
啓動maxscale服務
maxscale --config=/etc/maxscale.cnf
netstat -ntelp #主要查詢3306 端口是否監聽
查看maxscale 服務狀態
maxadmin
> list servers
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server | Address | Port | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
server1 | 主服務器ip | 10336 | 0 | Master, Running
server2 | 從服務器ip | 10336 | 0 | Slave, Running
-------------------+-----------------+-------+-------------+--------------------
至此,完成MaxScale中間件實現MySQL讀寫分離。