[Client] → [Amoeba Proxy:3306] → [Master:172.16.18.1:3306] (寫)
→ [Slave:172.16.18.2:3306] (讀)
source_id:transaction_id,全局唯一source_id = 服務器 server_uuid(128位隨機數)/usr/local/mysql
[mysqld]
binlog_format=row
server-id=1
log-slave-updates=true
gtid-mode=on
enforce-gtid-consistency=true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync-master-info=1
slave-parallel-workers=4
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
report-port=3306
report-host=node1.magedu.com
GRANT REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO 'rpuser'@'%' IDENTIFIED BY 'rppass';
FLUSH PRIVILEGES;
server-id=10
report-host=node2.magedu.com
CHANGE MASTER TO
MASTER_HOST='172.16.18.1',
MASTER_USER='rpuser',
MASTER_PASSWORD='rppass',
MASTER_AUTO_POSITION=1;
START SLAVE;
SHOW SLAVE STATUS\G
# 關鍵:Slave_IO_Running=Yes, Slave_SQL_Running=Yes, Auto_Position=1
# Retrieved_Gtid_Set / Executed_Gtid_Set 應一致
/usr/local/amoeba
3306
0.0.0.0
128
64
root
mypass
${amoeba.home}/conf/access_list.conf
node1
node1
node2
true
3306
test
root
mypass
500
500
10
192.168.18.1
192.168.18.2
amoeba start &
ss -tanl | grep 3306 # 應監聽 :::3306
mysql -uroot -h172.16.18.6 -pmypass
# Server version: 5.1.45-mysql-amoeba-proxy-2.2.0
SELECT VERSION(); -- 顯示 5.6.13-log,證明轉發至後端
# Master 抓寫
tcpdump -i eth0 -s0 -nn -A tcp dst port 3306 and dst host 192.168.18.1
# 出現 "create database yong"
# Slave 抓讀
tcpdump -i eth0 -s0 -nn -A tcp dst port 3306 and dst host 192.168.18.2
# 出現 "select User,Host from mysql.user"
| 中間件 | 特點 |
|---|---|
| ProxySQL | 高性能、動態配置、查詢重寫、鏡像、原生 GTID 支援 |
| MyCat | 分片/讀寫分離/多租戶、活躍社區 |
| ShardingSphere | Java 生態、分片/讀寫分離/影子表/加密 |
| MaxScale | MariaDB 官方、Binlog 路由、自動故障切換 |
新專案強烈建議 ProxySQL 或 MyCat,Amoeba 僅作歷史系統維護參考。