加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

MaxScale 配置及测试

(2015-01-16 18:26:12)
标签:

it

分类: MySQL
、背景:
MaxScale是有原SkySQL(现MariaDB Corporation)主导开发的一个插件式MySQL中间件,其主要设计目标是提升灵活性与可定制性。下图是MaxScale的架构设计图,其详细地展现了MaxScale可提供的功能。

同时MaxScale相较于其他中间件而言提供了另一个优势就是可以通过monitor模块达到主从自动切换,宕机自动离线恢复后自动上线等功能,因此对于DBA、开发更为友好。可以说和Oracle提供的Fabric一块会给后续的运维带来极大的遍历。
2、演示:
2.1、安装MaxScale提供的RPM包:
先增加MAXSCALE的秘钥


rpm --import  http://downloads.mariadb.com/software/MaxScale/MaxScale-GPG-KEY.public

创建文件/etc/yum.repos.d/maxscale.repo,并编辑

[maxscale]
name = maxscale
baseurl = http://downloads.mariadb.com/software/MaxScale/maxscale-1.0.4/RPM/rhel6
enabled=1
gpgcheck=true
然后可以直接通过YUM 进行安装了:

yum install maxscale
2.2、在安装完MaxScale后我们还需要在数据库建一个用于monitor的用户,同时建好后面测试的用户:
mysql> grant all privileges on *.* to 'max'@'%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
2.4、此时便可以开始修改MaxScale.cnf配置文件了,默认在/usr/local/skysql/maxscale/etc目录下有一个模板文件,稍作修改即可:
[maxscale]
threads=1
[MySQL Monitor]
type=monitor
module=mysqlmon
servers=server1,server2,server3
user=max
passwd=123456
[RW Split Router]
type=service
router=readwritesplit
servers=server2,server3
user=max
passwd=123456
use_sql_variables_in=all
max_slave_connections=50%
max_slave_replication_lag=30
router_options=slave_selection_criteria=LEAST_BEHIND_MASTER
[Read Connection Router]
type=service
router=readconnroute
router_options=slave
servers=server3
user=max
passwd=123456
[HTTPD Router]
type=service
router=testroute
servers=server1,server2,server3
[Debug Interface]
type=service
router=debugcli
[RW Split Listener]
type=listener
service=RW Split Router
protocol=MySQLClient
port=4006
socket=/tmp/rwsplit.sock
[Read Connection Listener]
type=listener
service=Read Connection Router
protocol=MySQLClient
port=4008
[Debug Listener]
type=listener
service=Debug Interface
protocol=telnetd
port=4442
[HTTPD Listener]
type=listener
service=HTTPD Router
protocol=HTTPD
port=6444
[server1]
type=server
address=192.168.192.169
port=3000
protocol=MySQLBackend
user=max
passwd=123456
[server2]
type=server
address=192.168.192.148
port=3306
protocol=MySQLBackend
user=max
passwd=123456
[server3]
type=server
address=192.168.192.171
port=3306
protocol=MySQLBackend
user=max
passwd=123456

2.5、此时便可以启动MaxScale服务了:


service maxscale start
2.6、在启动MaxScale服务后便可以使用telnet登录MaxScale的管理控制台进行管理操作了:密码skysql。
telnet 127.0.0.1 4442
Trying 127.0.0.1...
Connected to 127.0.0.1.
MaxScale login: admin
Password:
MaxScale>

2.7、以下是简要的MaxScale管理命令:
首先可以使用help命令查看当前MaxScale版本提供了哪些命令:
Available

commands:
    add user
    clear server
    disable [heartbeat|log|root]
    enable [heartbeat|log|root]
    list [clients|dcbs|filters|listeners|modules|monitors|services|servers|sessions|threads]
    reload [config|dbusers]
    remove user
    restart [monitor|service]
    set server
    show [dcbs|dcb|dbusers|epoll|filter|filters|modules|monitor|monitors|server|servers|services|service|session|sessions|threads|users]
    shutdown [maxscale|monitor|service]
 
Type help command to see details of each command.
Where commands require names as arguments and these names contain
whitespace either the \ character may be used to escape the whitespace
or the name may be enclosed in double quotes ".
 
MaxScale>

以下list命令分别列出当前MaxScale提供了哪些模块和后端注册的MySQL服务:

Modules.
----------------+-------------+---------+-------+-------------------------
Module Name     | Module Type | Version | API   | Status
----------------+-------------+---------+-------+-------------------------
MySQLBackend    | Protocol    | V2.0.0  | 1.0.0 | GA
maxscaled       | Protocol    | V1.0.0  | 1.0.0 | GA
telnetd         | Protocol    | V1.0.1  | 1.0.0 | GA
MySQLClient     | Protocol    | V1.0.0  | 1.0.0 | GA
mysqlmon        | Monitor     | V1.4.0  | 1.0.0 | GA
galeramon       | Monitor     | V1.4.0  | 1.0.0 | GA
readconnroute   | Router      | V1.1.0  | 1.0.0 | GA
readwritesplit  | Router      | V1.0.2  | 1.0.0 | GA
debugcli        | Router      | V1.1.1  | 1.0.0 | GA
cli             | Router      | V1.0.0  | 1.0.0 | GA
----------------+-------------+---------+-------+-------------------------

MaxScale> list servers
Servers. -------------------+-----------------+-------+-------------+-------------------- Server | Address | Port | Connections | Status -------------------+-----------------+-------+-------------+-------------------- server1 | 192.168.192.171 | 3306 | 0 | Master, Running server2 | 192.168.192.148 | 3306 | 0 | Running server3 | 192.168.192.169 | 3306 | 0 | Running -------------------+-----------------+-------+-------------+--------------------
2.8、以下则通过MaxScale做读写分离测试:

在主从数据库上创建同库,但有不同表。如MASTER 有table 1,但slave上只有table 2。
使用命令:
mysql -umax -p123456 -h 192.168.192.171 -P 4006 -e 'use cccc;show tables;'
命令的结果,只会显示从库的table2的表,并不会显示主库的table1的表,这意味着读写分离。
同样使用写入命令insert into table1(id) values (1);也会执行成功,但该条命令会插入MASTER服务器上。



0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有