MaxScale Binlog Server理想架构图
要点提示:
1、MX只能适合Mariadb自家的版本作为BINLOG ROUTER,其他DB都不适合
2、开通IPTABLES,避免端口呗过滤
3、使用MX服务收集BINLOG减少了M的IO压力
4、MX到SLAVE的数据同步延迟
5、Master到MX在大数据下写入有一定的延迟
安装过程:
1、已经有mariadb的MS架构
2、安装maxscale
a、yum -y install maxscale-2.0.1-2.CentOS.6.x86_64.rpm
b、添加用户useradd maxscale
c、添加从主库拷贝过来的binlog目录,并授权为maxscale
d、配置文件vim /etc/maxscale.cnf
[maxscale]
threads=16 ##根据CPU的物理核数来确定
[Replication]
type=service
router=binlogrouter
user=dlan
password=root123 #作为MAXSCALE的登录用户及maxscale同步主库的binlog日志
router_options=server_id=15575308,heartbeat=30,binlogdir=/home/maxscale,transaction_safety=1,mariadb10-compatibility=1,send_slave_heartbeat=1
[Replication Listener]
type=listener
service=Replication
protocol=MySQLClient
port=5308
[CLI]
type=service
router=cli
[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
port=6603
[MaxAdmin Service]
type=service
router=cli
[MaxAdmin Listener]
type=listener
service=MaxAdmin Service
protocol=maxscaled
port=336677
##部分参数介绍
# server_id设置maxscale的,记得不能与主和从库重复,要唯一
# heartbeat=30秒,意思为当maxscale在30秒内没有接收到主库推送的binlog日志,发送心跳检查
# binlogdir设置接收binlog的存放路径,目录属性chown -R maxscale.maxscale /data/binlog
# transaction_safety=1此参数用于启用binlog日志中的不完整事务检测。 当MariaDB MaxScale启动时,如果当前binlog文件已损坏或找到不完整的事务,则可能会出现错误消息。 在正常工作期间,binlog事件不会分配到从库,直到事务已经提交。 默认值为off,设置transaction_safety = on以启用不完全事务检测。
# send_slave_heartbeat=1开启心跳检查
3、在maxscale服务器上执行收集BINLOG信息,确保在主库上已经存在用户dlan的信息,不存在添加用户
mysql -udlan -proot123 -h192.168.1.251 -P5308
CHANGE MASTER TO MASTER_HOST='192.168.15.104',MASTER_USER='dlan',MASTER_PASSWORD='root123',MASTER_PORT=3306,MASTER_LOG_FILE='mysql-bin.000005',MASTER_LOG_POS=4;
mysql> start slave ;
Query OK, 0 rows affected (0.00 sec)
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Binlog Dump
Master_Host: 192.168.15.104
Master_User: dlan
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000005
Read_Master_Log_Pos: 10851096
Relay_Log_File: mysql-bin.000005
Relay_Log_Pos: 10823989
Relay_Master_Log_File: mysql-bin.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 10823989
Relay_Log_Space: 10823989
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 221023306
Master_UUID: 452ee7b4-bb7e-11e6-97da-f04da23ed470
Master_Info_File: /home/maxscale/master.ini
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave running
Master_Retry_Count: 1000
Master_Bind:
Last_IO_Error_TimeStamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position:
1 row in set (0.02 sec)
#同时在本地文件配置的收集BINLOG目录可以看到当前从主库收集过来的BINLOG日志及同步用户的信息
4、配置从库同步数据从MAXSCALE服务器获取,这里的master_log_file master_log_pos使用全备后的文件记录的信息,和MX同步的MASTER_LOG_FILE当前FILE不冲突
CHANGE MASTER TO MASTER_HOST='192.168.15.57',MASTER_USER='dlan',MASTER_PASSWORD='root123',MASTER_PORT=5308,MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=168680168;
###测试过程:
1、主库写入100W数据,到MX也有一定的延迟。