安装部署TiCDC

环境:
TIDB:V6.0.0
Mysql:5.7
OS:Centos 7

192.168.1.118 pd,tidb,tikv,tiflash,monitoring,grafana,alertmanager,pump,drainer
192.168.1.85 pd,tidb,tikv,tiflash,pump,ticdc
192.168.1.134 pd,tidb,tikv,pump

 

如果要添加 TiCDC 节点,IP地址为192.168.1.85 可以按照如下步骤进行操作,下面的操作在中控机(192.168.1.118)上执行

1.添加节点信息到scale-out.yaml文件
编写 scale-out.yaml 文件:

vi /tmp/scale-out.yaml
cdc_servers:
  - host: 192.168.1.85
    gc-ttl: 86400
    data_dir: /tidb-data/cdc-8300

 

2. 运行扩容命令
tiup cluster scale-out mytidb_cluster /tmp/scale-out.yaml

 

3.查看集群状态
#tiup cluster display mytidb_cluster

 

 

---------------------------------------------创建同步任务-------------------------------------

1.创建同步任务:

 

tiup ctl:v6.0.0 cdc changefeed create --pd=http://192.168.1.118:2379 --sink-uri="mysql://tidb_sync:mysql@192.168.1.134:13306/?time-zone=CST" --changefeed-id="simple-replication-task" --sort-engine="unified"

 

报错:
[CDC:ErrMySQLInvalidConfig]MySQL config invalid: unknown time zone CST

 

将时区留空time-zone=
tiup ctl:v6.0.0 cdc changefeed create --pd=http://192.168.1.118:2379 --sink-uri="mysql://tidb_sync:mysql@192.168.1.134:13306/?time-zone=" --changefeed-id="simple-replication-task" --sort-engine="unified"

 

2.查看状态

[root@localhost ~]# tiup ctl:v6.0.0 cdc changefeed list --pd=http://192.168.1.118:2379
Starting component `ctl`: /root/.tiup/components/ctl/v6.0.0/ctl /root/.tiup/components/ctl/v6.0.0/ctl cdc changefeed list --pd=http://192.168.1.118:2379
[
  {
    "id": "simple-replication-task",
    "summary": {
      "state": "normal",
      "tso": 433786531128541186,
      "checkpoint": "2022-06-09 16:44:54.161",
      "error": null
    }
  }
]

 

3.验证:
tidb上创建库和表,注意创建表有限制的(表需要要主键或是唯一性索引),否则无法同步

/opt/mysql5729/bin/mysql -h 192.168.1.118 -P4000 -uroot -p
create database db_cdc;

use db_cdc


mysql> CREATE TABLE tb_t1(
    -> id bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
    -> name varchar(20) NOT NULL COMMENT 'name',
    -> PRIMARY KEY (`id`) USING BTREE
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='测试';
Query OK, 0 rows affected (0.64 sec)

mysql> insert into tb_t1(name) values('name1');
Query OK, 1 row affected (0.11 sec)

mysql> insert into tb_t1(name) values('name2');
Query OK, 1 row affected (0.01 sec)

mysql> insert into tb_t1(name) values('name3');
Query OK, 1 row affected (0.02 sec)

mysql> select * from tb_t1;
+----+-------+
| id | name  |
+----+-------+
|  1 | name1 |
|  2 | name2 |
|  3 | name3 |
+----+-------+
3 rows in set (0.00 sec)

 

登陆到mysql查看

[root@localhost ~]# /opt/mysql5727/bin/mysql -h localhost -uroot -pmysql -S /opt/mysql5727/mysql.sock
mysql> use db_cdc;
Database changed
mysql> show tables;
+------------------+
| Tables_in_db_cdc |
+------------------+
| tb_t1            |
+------------------+
1 row in set (0.00 sec)

mysql> select * from tb_t1;
+----+-------+
| id | name  |
+----+-------+
|  1 | name1 |
|  2 | name2 |
|  3 | name3 |
+----+-------+
3 rows in set (0.00 sec)

 

 

 

 

posted @ 2022-06-06 13:46  slnngk  阅读(301)  评论(0编辑  收藏  举报