maxScale

 ·  ☕ 2  · 👀...

介绍

运维

安装(CentOS7)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
$ cd /usr/local
$ wget \
https://downloads.mariadb.com/MaxScale/2.3.2/centos/7/x86_64/maxscale-2.3.2-1.centos.7.x86_64.rpm
BashCopy
$ yum localinstall maxscale-2.3.2-1.centos.7.x86_64.rpm
# 启动
$ systemctl start maxscale
# 检查
$ ps -ef | grep maxscale
$ netstat -ntelp

在数据库创建账号信息

创建监控账号

1
2
3
mysql> CREATE USER 'monitor'@'172.17.0.%' IDENTIFIED BY '123456';
mysql> GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO 'monitor'@'172.17.0.%' ;
SQL

创建获取数据库用户信息账号

1
2
mysql> CREATE USER 'maxscale'@'172.17.0.%' IDENTIFIED BY '123456';
mysql> GRANT SELECT ON mysql.* TO 'maxscale'@'172.17.0.%' ;

对创建的用户的密码进行加密

1
2
3
4
5
6
7
# 生成key
$ maxkeys
Generating .secrets file in /var/lib/maxscale.
$ chown  maxscale.maxscale /var/lib/maxscale/ -R
# 生成加密密码
$ maxpasswd /var/lib/maxscale/ 123456
F53FC4561BFAAA07591FB1EA121C8909

配置maxScale

$ vi /etc/maxscale.cnf
########## 配置内容 ##########
[maxscale]
# 配置线程数,如果设置为auto根据CPU数量来调整
threads=auto
# 连接超时,默认时间为3秒
auth_connect_timeout=3
# MySQL连接到后端数据库的读取超时,默认时间1秒;
auth_read_timeout=1
# MySQL连接到后端数据库的写入超时,默认时间2秒;
auth_write_timeout=2
# 启用此选项可为所有日志文件时间戳添加毫秒精度;
ms_timestamp=0
# 默认情况下,启用日志记录到syslog。
syslog = 1
# 启用以禁用将消息记录到MaxScale的日志文件。
maxlog = 1
# 指定日志目录
logdir=/var/log/
# 配置日志级别:[log_warning|log_notice|log_info|log_debug]
log_warning=1

# 添加节点1(master)
[server1]
type=server
address=192.168.100.101
port=3306
protocol=MariaDBBackend
#配置权重为3(可不配置权重)
serv_weight = 3

#添加节点2(slave):172.17.0.57
[server2]
type = server
address = 172.17.0.57
port = 3306
protocol = MySQLBackend
serv_weight = 7

# 配置maxscale监控信息
[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=server1,server2
user=monitor
password=F53FC4561BFAAA07591FB1EA121C8909
monitor_interval=2000

# 配置读服务器
mariadb-maxscale-22-readconnroute/

[Read-Only-Service]
type=service
router=readconnroute
servers=server1
user=myuser
password=mypwd
router_options=slave
# 设置监控的时间间隔,默认单位:毫秒
monitor_interval=1000

# 配置读写分离模块
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1,server2
user=maxscale
password=F53FC4561BFAAA07591FB1EA121C8909
# 主从延迟最大秒
max_slave_replication_lag=3

# 管理模块的配置(默认即可)
[MaxAdmin-Service]
type=service
router=cli

# 配置读写分离监听模块
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=3306

# 配置管理端监控模块
[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
socket=default
#############################

maxScale管理端使用

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# 连接maxScale(方式1)
$ maxadmin -S /var/run/maxscale/maxadmin.sock
# 连接maxScale(方式2)
$ maxadmin --user=maxscale --password=123456
# 列出数据库节点节信
$ list servers
# 列出连接数据库信息
$ list sessions
# 列出连接的客户端信息
$ list clients
# 查看缓存在读写分离模块的数据库用户信息
$ show dbusers "Read-Write Service"

Wanglibing
Wanglibing
Engineer,Lifelong learner