version: '2'
services: 
  redis:
    image: redis
    ports:
      # 端口映射
      - 6379:6379
    container_name: redis
    volumes:
      # 目录映射
      - "./redis/redis.conf:/usr/local/etc/redis/redis.conf"
      - "./redis/data:/data"
    restart: always
    networks:
      - my-network
    command:
      # 执行的命令
      redis-server /usr/local/etc/redis/redis.conf
      
  mysql:
    image: registry.cn-shanghai.aliyuncs.com/dy_docker/mysql:5.7
    restart: always
    container_name: mysql
    ports:
      - 3306:3306
    environment: 
       TZ: Asia/Shanghai
       MYSQL_ROOT_PASSWORD: 123123*
    volumes:
      - ./mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
      - ./mysql/data:/var/lib/mysql
      - ./mysql/init/:/docker-entrypoint-initdb.d/
    networks:
      - my-network

  canal-server:
    image: registry.cn-shanghai.aliyuncs.com/dy_docker/canal:v1.1.3
    container_name: canal-server
    ports:
      - "11111:11111"
    volumes:
      - ./canal/example/:/home/admin/canal-server/conf/example/
      - ./canal/canal-server-logs/:/home/admin/canal-server/logs/
    depends_on:
      - mysql
    networks:
      - my-network  

networks:
  my-network:
    driver: bridge
[root@localhost canal-service]# tree
.
├── canal-server-logs
│   ├── canal
│   │   └── canal.log
│   └── example
│       ├── example.log
│       └── meta.log
├── docker-compose.yml
├── example
│   ├── instance.properties
│   └── meta.dat
├── mysql
│   ├── init
│   │   └── init.sql
│   └── mysqld.cnf
└── var
    └── lib
        └── mysql

instance.properties

# enable gtid use true/false
canal.instance.gtidon=false
# position info
canal.instance.master.address=mysql:3306
canal.instance.master.journal.name=mysql-bin.000001
canal.instance.master.position=154

# table meta tsdb info
canal.instance.tsdb.enable=false
# username/password
canal.instance.dbUsername=canal
canal.instance.dbPassword=canal
canal.instance.connectionCharset=UTF-8

# table regex
canal.instance.filter.regex=.*\\..*
# table black regex
canal.instance.filter.black.regex=
#################################################
                                                           

init.sql

CREATE USER canal IDENTIFIED BY 'canal';
GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
FLUSH PRIVILEGES;

CREATE DATABASE `test`;

USE test;


CREATE TABLE `test` (
        `id` INT(11) NOT NULL,
        `name` VARCHAR(50) NOT NULL
)
ENGINE=InnoDB
;

mysqld.cnf

[mysqld_safe]
socket          = /var/run/mysqld/mysqld.sock
nice            = 0

[mysqld]
#
# * Basic Settings
#
user            = mysql
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
port            = 3306
basedir         = /usr
datadir         = /var/lib/mysql
tmpdir          = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address            = 0.0.0.0

key_buffer_size         = 16M
max_allowed_packet      = 16M
thread_stack            = 192K
thread_cache_size       = 8

myisam-recover-options  = BACKUP
#max_connections        = 100
#table_cache            = 64
#thread_concurrency     = 10
#
# * Query Cache Configuration
#
query_cache_limit       = 1M
query_cache_size        = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file        = /var/log/mysql/mysql.log
#general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#log_slow_queries       = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
server-id               = 1
log_bin                 = /var/log/mysql/mysql-bin
binlog-format=ROW
expire_logs_days        = 10
max_binlog_size   = 100M

最后修改:2020 年 02 月 13 日
如果觉得我的文章对你有用,请随意赞赏