当前位置:Gxlcms > 数据库问题 > MySQL容量规划之tcpcopy应用之道

MySQL容量规划之tcpcopy应用之道

时间:2021-07-01 10:21:17 帮助过:10人阅读

0 > /proc/sys/net/ipv4/ip_forward

具体操作

online server

/usr/local/src/tcpcopy/objs/tcpcopy -x 3306-1.1.1.2:3306 -s 1.1.1.3 -c 1.1.1.4 -n 3 -d
# 如果是多实例,sourcePort-targetIP:targetPort,以逗号分隔
/usr/local/src/tcpcopy/objs/tcpcopy -x 3306-1.1.1.2:3306,3307-1.1.1.2:3307 -s 1.1.1.3 -c 1.1.1.4 -n 3 -d

 

tcpcopy会捕获当前主机的‘3306’报文,更改客户端的IP为1.1.1.4,发送这些报文到target server 1.1.1.2的目标端口‘3306’,并连接1.1.1.3询问intercept 将响应包传递给自己 -n 3 是复制3倍份流量到target,tcpcopy会处理冲突的部分

target server

/usr/local/src/intercept/objs/intercept -i eth0 -F tcp and src port 3306 -d
ntercept会从eth0网卡捕获监听3306端口的tcp包

assistant server

 route add -host 1.1.1.4 gw 1.1.1.3

 

路由客户端的所有响应包到assistant server 模拟客户端流量 online server
# mysql -h1.1.1.1 -uadmin -p123123 -P3306
# 创建带有主键的表t2
CREATE TABLE `t2` ( `id` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 # 创建无约束字段的表t3 CREATE TABLE `t3` ( `id` int(11) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8
# 然后在两个表中分别插入一条数据
insert into t2 values(1);
insert into t3 values(1);

 target server

mysql> show processlist;
+------+-------------+---------------------+------+---------+---------+--------------------------------------------------------+------------------+
| Id   | User        | Host                | db   | Command | Time    | State                                                  | Info             |
+------+-------------+---------------------+------+---------+---------+--------------------------------------------------------+------------------+
|   11 | system user |                     | NULL | Connect | 3044244 | Slave has read all relay log; waiting for more updates | NULL             |
|   12 | system user |                     | NULL | Connect | 3044248 | Waiting for an event from Coordinator                  | NULL             |
|   13 | system user |                     | NULL | Connect | 3044248 | Waiting for an event from Coordinator                  | NULL             |
|   14 | system user |                     | NULL | Connect | 3044248 | Waiting for an event from Coordinator                  | NULL             |
|   15 | system user |                     | NULL | Connect | 3044248 | Waiting for an event from Coordinator                  | NULL             |
| 3961 | root        | localhost           | NULL | Query   |       0 | starting                                               | show processlist |
| 3962 | admin       | 1.1.1.4:24695       | NULL | Sleep   |       5 |                                                        | NULL             |
| 3963 | admin       | 1.1.1.4:24286       | NULL | Sleep   |       5 |                                                        | NULL             |
| 3964 | admin       | 1.1.1.4:24759       | NULL | Sleep   |       5 |                                                        | NULL             |
+------+-------------+---------------------+------+---------+---------+--------------------------------------------------------+------------------+
9 rows in set (0.00 sec)

mysql> select * from t2;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)

mysql> select * from t3;
+------+
| id   |
+------+
|    1 |
|    1 |
|    1 |
+------+
3 rows in set (0.00 sec)

 

可以看到同时3倍的流量复制效应,对应的是3个回话;表t2有约束,tcpcopy会处理冲突的部分,

所以最后看到的是t1表中只有一条数据,而t2表中则是3倍流量复制的结果

 

MySQL容量规划之tcpcopy应用之道

标签:mysq   抓取   images   code   wait   快速定位   官方文档   流量   alt   

人气教程排行