2 Star 3 Fork 1

acgist/muses

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

日志记录服务

使用canal监听MySQL数据变化并记录,同时实现数据对比和日志输出。

Canal

同步变化数据

https://github.com/alibaba/canal

MySQL配置

https://github.com/alibaba/canal/wiki/QuickStart

# 配置
[mysqld]
# 配置 ServerID
server_id=1
# 开启 binlog
log-bin=binlog
# 选择 ROW 模式
binlog-format=ROW

# 查询
show variables like '%log_bin%'

# 授权
CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
# 如果权限问题登陆不了使用下面授权语句
-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;

Canal配置

# 配置数据连接(instance.properties):example -> muses
canal.instance.mysql.slaveId=2
canal.instance.master.address=127.0.0.1:3306
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
# 过滤表名
canal.instance.filter.regex=muses\\.t_.*
canal.mq.topic=log-topic

# 配置Kafka(instance.properties)
canal.serverMode=kafka
canal.destinations=muses
kafka.bootstrap.servers=127.0.0.1:9092

Kafka

传输变化数据

# 创建Topic
kafka-topics.sh --zookeeper zookeeper:2181 --topic topic-log --create --partitions 3 --replication-factor 3

# 配置Kafka
spring:
  cloud:
    stream:
      binders:
        log:
          type: kafka
      default-binder: log
      function:
        definition: logRecord
      bindings:
        logRecord-in-0:
          group: ${spring.application.name}
          binder: log
          destination: ${system.topic.log:topic-log}
#         content-type: text/plain

ElasticSearch

记录变化数据

模板

差异模板输出

默认使用insert.ftl/update.ftl/delete.ftl,如果数据库表需要使用自定义模板需要在表名目录下面新增相应模板文件即可。

马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/acgist/muses.git
git@gitee.com:acgist/muses.git
acgist
muses
muses
master

搜索帮助