当前位置:网站首页>Canal安装配置

Canal安装配置

2022-06-24 06:39:00 Angryshark_128

资源下载

链接:https://pan.baidu.com/s/1wKqJ0VypFxKd6WnJxIoEqg

提取码:wrmf

配置Mysql

新建canal库

CREATE USER canal IDENTIFIED BY 'canal';
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';
FLUSH PRIVILEGES;

解压至目录

> tar -xf canal.deployer-1.1.5-SNAPSHOT.tar.gz -C /pandora/soft/canal-1.1.5

修改配置文件

> vi /pandora/soft/canal-1.1.5/conf/canal.properties

# 设置数据库实例
canal.destinations = oidd

> cp -R example/ oidd

> cd /pandora/soft/canal-1.1.5/conf/oidd

> vi instance.properties

# 要监控的数据库地址
canal.instance.master.address=127.0.0.1:30000

# 数据库用户名
canal.instance.dbUsername = canal
# 数据库密码
canal.instance.dbPassword = canal
# 指定需要同步的数据库
canal.instance.defaultDatabaseName = oidd
# 指定编码方式
canal.instance.connectionCharset = UTF-8 

启动Canal

> cd /pandora/soft/cannal-1.1.5/bin
> ./startup.sh

打开Canal样例项目运行

在这里插入图片描述
在这里插入图片描述

修改参数:IP 端口 数据库 用户名 密码

package com.alibaba.otter.canal.example;

import java.net.InetSocketAddress;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import com.alibaba.otter.canal.common.utils.AddressUtils;

/**
 * 单机模式的测试例子
 *
 * @author jianghang 2013-4-15 下午04:19:20
 * @version 1.0.4
 */
public class SimpleCanalClientTest extends AbstractCanalClientTest {

    public SimpleCanalClientTest(String destination) {
        super(destination);
    }

    public static void main(String[] args) {
        // 根据ip,直接创建链接,无HA的功能

        String destination = "oidd";
        String ip = "106.13.73.198";
        Integer port = 11111;
        String userName = "canal";
        String password = "canal";

        CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress(ip, port),
                destination,
                userName,
                password);

        final SimpleCanalClientTest clientTest = new SimpleCanalClientTest(destination);
        clientTest.setConnector(connector);
        clientTest.start();
        Runtime.getRuntime().addShutdownHook(new Thread() {

            public void run() {
                try {
                    logger.info("## stop the canal client");
                    clientTest.stop();
                } catch (Throwable e) {
                    logger.warn("##something goes wrong when stopping canal:", e);
                } finally {
                    logger.info("## canal client is down.");
                }
            }

        });
    }

}

创建新表

use oidd;


CREAETE TABLE ***

可以看到最新的LOG

在这里插入图片描述

原网站

版权声明
本文为[Angryshark_128]所创,转载请带上原文链接,感谢
https://pandora.blog.csdn.net/article/details/108704590