<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    java學習

    java學習

     

    canal簡單安裝使用

    1、數(shù)據(jù)庫配置

    首先使用canal需要修改數(shù)據(jù)庫配置

    [mysqld] 
    log-bin=mysql-bin # 開啟
    binlog binlog-format=ROW # 選擇 ROW 模式
    server_id=1 # 配置 MySQL replaction 需要定義,不要和 canal 的 slaveId 重復

    創(chuàng)建canal數(shù)據(jù)庫用戶

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

     

    2、安裝canal

    下載:https://github.com/alibaba/canal/releases

    解壓(修改版本號):tar zxvf canal.deployer-1.1.4.tar.gz -C ./canal

    配置開放服務器端口:11110、11111、11112

    修改canal配置文件(這里設置了兩個instance,即兩個數(shù)據(jù)庫):

    vi canal/conf/canal.properties 
    canal.destinations
    = example1,example2

     配置instance:

    cp -R canal/conf/example conf/example1
    mv conf/example conf/example2

    第一個數(shù)據(jù)庫配置

    vi canal/conf/example1/instance.properties
    canal.instance.master.address
    =32.1.2.140:3306

    第二個數(shù)據(jù)庫配置

    vi canal/conf/example2/instance.properties
    canal.instance.master.address
    =32.1.2.140:3307

    #如果需要新增一個instance,只需要修改canal.properties文件,并新增一個instance配置即可,無需重啟canal。

    運行:

    sh canal/bin/startup.sh # 查看日志
    cat canal/logs/canal/canal

     

    3、Java使用樣例

    引入pom依賴,需要與安裝的canal版本一致

    復制代碼
    <dependencies>     <dependency>         <groupId>com.alibaba.otter</groupId>         <artifactId>canal.client</artifactId>         <version>1.1.4</version>     </dependency> </dependencies>
    復制代碼

    示例代碼(異步打印兩個數(shù)據(jù)庫的修改內容):

    復制代碼
    package cn.spicybar.dblog;  import com.alibaba.otter.canal.client.CanalConnector; import com.alibaba.otter.canal.client.CanalConnectors; import com.alibaba.otter.canal.protocol.CanalEntry.Entry; import com.alibaba.otter.canal.protocol.CanalEntry.EntryType; import com.alibaba.otter.canal.protocol.CanalEntry.RowChange; import com.alibaba.otter.canal.protocol.Message;  import java.net.InetSocketAddress; import java.util.List;  public class CanalClient {      public static void main(String[] args) {         new Thread(() -> initConnector("example1")).start();         new Thread(() -> initConnector("example2")).start();     }      private static void initConnector(String destination) {         CanalConnector connector = CanalConnectors.newSingleConnector(new InetSocketAddress("32.1.0.237", 11111), destination, "", "");         try {             connector.connect();             connector.subscribe(".*\\..*");             connector.rollback();             while (true) {                 Message message = connector.getWithoutAck(1000);                 if (message.getId() != -1 && message.getEntries().size() > 0) {                     printEntry(message.getEntries());                 }                 connector.ack(message.getId());             }         } finally {             connector.disconnect();         }     }      private static void printEntry(List<Entry> entries) {         for (Entry entry : entries) {             if (entry.getEntryType() == EntryType.TRANSACTIONBEGIN || entry.getEntryType() == EntryType.TRANSACTIONEND) {                 continue;             }             try {                 RowChange rowChange = RowChange.parseFrom(entry.getStoreValue());                 System.out.println(rowChange.getSql());             } catch (Exception e) {                 throw new RuntimeException("ERROR ## parser error, data:" + entry.toString(), e);             }         }     }

    posted on 2020-08-31 10:55 楊軍威 閱讀(673) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     

    導航

    統(tǒng)計

    常用鏈接

    留言簿

    隨筆檔案

    搜索

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲国产精品不卡在线电影| 亚洲日韩乱码中文无码蜜桃 | 亚洲福利电影一区二区?| 亚洲日本成本人观看| 中国国语毛片免费观看视频| 一二三四在线观看免费高清中文在线观看| 亚洲第一视频在线观看免费| 亚洲麻豆精品果冻传媒| 边摸边脱吃奶边高潮视频免费| 小日子的在线观看免费| 日本免费一区二区三区最新vr| 婷婷亚洲综合五月天小说| 国产午夜亚洲精品不卡电影| 91久久青青草原线免费| 亚洲国产一级在线观看 | 精品久久洲久久久久护士免费| 精品国产_亚洲人成在线高清| 亚洲日韩精品A∨片无码加勒比| 久久一区二区免费播放| 成人五级毛片免费播放| 亚洲av色福利天堂| 粉色视频免费入口| 成年黄网站色大免费全看| 日日噜噜噜噜夜夜爽亚洲精品| 亚洲中文字幕无码一去台湾 | 免费在线观看的黄色网址| 亚洲女人18毛片水真多| a毛片成人免费全部播放| 成人免费视频试看120秒| 久久亚洲AV午夜福利精品一区| 亚洲人成网亚洲欧洲无码| 久久精品人成免费| 亚洲精品美女久久久久99| 免费看内射乌克兰女| 免费无码又爽又高潮视频| 亚洲国产视频一区| 久久精品一区二区免费看| 久久亚洲国产成人精品无码区| 久久精品国产亚洲AV电影网| 在线观看视频免费完整版| 亚洲黄网在线观看|