github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/scripts/canal/docker/start.sh (about)

     1  #!/bin/sh
     2  
     3  # This script file uses environment variable to create config of canal adapter. The format of config file `application.yml`
     4  # is only suitable for canal adapter release version v1.1.5-alpha-2, if you want build from latest master branch, please rewrite the
     5  # config file from canal/client-adapter/launcher/src/main/bin/conf/application.yml
     6  
     7  KAFKA_SERVER=${KAFKA_SERVER:-localhost:9092}
     8  ZOOKEEPER_SERVER=${ZOOKEEPER_SERVER:-localhost:2181}
     9  DB_NAME=${DB_NAME:-testdb}
    10  DOWNSTREAM_DB_HOST=${DOWNSTREAM_DB_HOST:-localhost}
    11  DOWNSTREAM_DB_PORT=${DOWNSTREAM_DB_PORT:-4000}
    12  echo "zookeeper server ${ZOOKEEPER_SERVER}"
    13  echo "kafka server ${KAFKA_SERVER}"
    14  echo "db name ${DB_NAME}"
    15  echo "downstream db host ${DOWNSTREAM_DB_HOST}"
    16  echo "downstream db port ${DOWNSTREAM_DB_PORT}"
    17  echo "use flatMessage: ${USE_FLAT_MESSAGE}"
    18  
    19  echo "Verifying downstream TiDB is started..."
    20  i=0
    21  while ! mysql -uroot -h${DOWNSTREAM_DB_HOST} -P${DOWNSTREAM_DB_PORT} --default-character-set utf8mb4 -e 'select * from mysql.tidb;'; do
    22  	i=$((i + 1))
    23  	if [ "$i" -gt 200 ]; then
    24  		echo 'Connection to downstream TiDB failed'
    25  		exit 2
    26  	fi
    27  	sleep 5
    28  done
    29  
    30  WORK_DIR=$(pwd)
    31  cat - >"${WORK_DIR}/conf/application.yml" <<EOF
    32  server:
    33    port: 8081
    34  spring:
    35    jackson:
    36      date-format: yyyy-MM-dd HH:mm:ss
    37      time-zone: GMT+8
    38      default-property-inclusion: non_null
    39  
    40  canal.conf:
    41    mode: kafka # tcp rocketMQ rabbitMQ
    42    flatMessage: ${USE_FLAT_MESSAGE}
    43    zookeeperHosts:
    44    syncBatchSize: 1000
    45    retries: 0
    46    timeout:
    47    accessKey:
    48    secretKey:
    49    consumerProperties:
    50      # kafka consumer
    51      kafka.bootstrap.servers: ${KAFKA_SERVER}
    52      kafka.enable.auto.commit: false
    53      kafka.auto.commit.interval.ms: 1000
    54      kafka.auto.offset.reset: latest
    55      kafka.request.timeout.ms: 40000
    56      kafka.session.timeout.ms: 30000
    57      kafka.isolation.level: read_committed
    58      kafka.max.poll.records: 1000
    59    canalAdapters:
    60    - instance: ${DB_NAME} # canal instance Name or mq topic name
    61      groups:
    62      - groupId: g1
    63        outerAdapters:
    64        - name: rdb
    65          key: mysql1
    66          properties:
    67            jdbc.driverClassName: com.mysql.jdbc.Driver
    68            jdbc.url: jdbc:mysql://${DOWNSTREAM_DB_HOST}:${DOWNSTREAM_DB_PORT}/${DB_NAME}
    69            jdbc.username: root
    70            jdbc.password:
    71  EOF
    72  
    73  cat - >"$WORK_DIR/conf/rdb/mytest_user.yml" <<EOF
    74  # Mirror schema synchronize config
    75  dataSourceKey: defaultDS
    76  destination: ${DB_NAME}
    77  groupId: g1
    78  outerAdapterKey: mysql1
    79  concurrent: true
    80  dbMapping:
    81    mirrorDb: true
    82    database: ${DB_NAME}
    83  EOF
    84  
    85  bash ./bin/stop.sh
    86  bash ./bin/startup.sh
    87  
    88  while true; do
    89  	sleep 30000
    90  done