Docker安装Canal与RocketMQ

一、修改MySQL配置

1.1 修改my.cnf配置

对于自建 MySQL , 需要先开启 Binlog 写入功能,配置 binlog-format 为 ROW 模式,my.cnf 中配置如下

log-bin=mysql-bin 	# 开启 binlog
binlog-format=ROW 	# 选择 ROW 模式
server_id=1 		# 配置 MySQL replaction 需要定义,不要和 canal 的 slaveId 重复

修改后记得重启下MySQL。


1.2 新建MySQL用户

授权canal 链接MySQL 账号具有作为 MySQL slave 的权限, 如果已有账户可直接 grant

-- 新建用户
CREATE USER canal IDENTIFIED BY 'canal';  

-- GRANT ALL PRIVILEGES ON *.* TO 'canal'@'%' ;
GRANT SELECT, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'canal'@'%';

-- 刷新权限
FLUSH PRIVILEGES;

二、Docker安装Canal Admin

2.1 下载镜像与启动容器
# 拉取canal admin镜像
docker pull canal/canal-admin:v1.1.4

# 拉取启动脚本
wget https://raw.githubusercontent.com/alibaba/canal/master/docker/run_admin.sh

# 修改run_admin.sh第89行,增加docker镜像版本
cmd="docker run -d -it -h $LOCALHOST $CONFIG --name=canal-admin $VOLUMNS $NET_MODE $PORTS $MEMORY canal/canal-admin:v1.1.4"

# 运行脚本
sh run_admin.sh -e server.port=8089 \ -e canal.adminUser=admin \ -e canal.adminPasswd=admin

# 查看启动日志install docker logs canal-admin
DOCKER_DEPLOY_TYPE=VM
==> INIT /alidata/init/02init-sshd.sh
==> EXIT CODE: 0
==> INIT /alidata/init/fix-hosts.py
==> EXIT CODE: 0
==> INIT DEFAULT
Generating SSH1 RSA host key:                              [  OK  ]
Starting sshd:                                             [  OK  ]
Starting crond:                                            [  OK  ]
==> INIT DONE
==> RUN /home/admin/app.sh
==> START ...
start mysql ...
Starting mysqld:                                           [  OK  ]
start mysql successful
start admin ...
start canal successful
==> START SUCCESSFUL ...

2.2 查看Canal Admin UI页面

浏览器输入:http://localhost:8089/

默认用户名及密码:admin/123456
Docker安装Canal与RocketMQ_第1张图片


三、Docker安装Canal Server

3.1 下载镜像与启动容器
# 拉取canal server镜像
docker pull canal/canal-server:v1.1.4

# 拉取启动脚本
wget https://raw.githubusercontent.com/alibaba/canal/master/docker/run.sh

# 修改run.sh第100行,增加docker镜像版本
cmd="docker run -d -it -h $LOCALHOST $CONFIG --name=canal-server $VOLUMNS $NET_MODE $PORTS $MEMORY canal/canal-server:v1.1.4"

# 运行脚本
sh run.sh -e canal.admin.manager=10.10.10.100:8089 \
          -e canal.admin.port=11110 \
          -e canal.admin.user=admin \
          -e canal.admin.passwd=4ACFE3202A5FF5CF467898FC58AAB1D615029441

# 查看启动日志install docker logs canal-server
DOCKER_DEPLOY_TYPE=VM
==> INIT /alidata/init/02init-sshd.sh
==> EXIT CODE: 0
==> INIT /alidata/init/fix-hosts.py
==> EXIT CODE: 0
==> INIT DEFAULT
Generating SSH1 RSA host key:                              [  OK  ]
Starting sshd:                                             [  OK  ]
Starting crond:                                            [  OK  ]
==> INIT DONE
==> RUN /home/admin/app.sh
==> START ...
start canal ...
start canal successful
==> START SUCCESSFUL ...

3.2 查看Canal Admin

Docker安装Canal与RocketMQ_第2张图片
发现Canal Server已经注册到Admin。


3.3 新增Instance实例

Docker安装Canal与RocketMQ_第3张图片
Docker安装Canal与RocketMQ_第4张图片
查看日志,如果发现没有异常,则说明新建Instance成功。

四、Docker-Compose安装RocketMQ

关于docker-compose的安装,可以参考:https://my.oschina.net/teddyIH/blog/3082853

4.1 下载安装配置文件
git clone https://github.com/foxiswho/docker-rocketmq.git

4.2 修改配置文件
# cd进入docker-rocketmq/rmq/rmq/brokerconf/,修改broker.conf
# 将brokerIP1修改为宿主机IP
brokerIP1=10.10.10.100   

Docker安装Canal与RocketMQ_第5张图片


4.3 修改docker-compose.yml
# cd进入docker-rocketmq/rmq
# 修改docker-compose.yml文件
version: '3.7'

services:
  rmqnamesrv:
    image: foxiswho/rocketmq:server
    container_name: rmqnamesrv
    ports:
      - 9876:9876
    volumes:
      - ./rmq/logs:/opt/logs
      - ./rmq/store:/opt/store
    environment:
      JAVA_OPTS: " -Duser.home=/opt"
      JAVA_OPT_EXT: "-Xms128m -Xmx128m -Xmn128m"
    networks:
        rmq:
          aliases:
            - rmqnamesrv
  rmqbroker:
    image: foxiswho/rocketmq:broker
    container_name: rmqbroker
    ports:
      - 10909:10909
      - 10911:10911
    volumes:
      - ./rmq/logs:/opt/logs
      - ./rmq/store:/opt/store
      - ./rmq/brokerconf/broker.conf:/etc/rocketmq/broker.conf
    environment:
        NAMESRV_ADDR: "rmqnamesrv:9876"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
    command: mqbroker -c /etc/rocketmq/broker.conf
    depends_on:
      - rmqnamesrv
    networks:
      rmq:
        aliases:
          - rmqbroker

  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - 8180:8080
    environment:
        JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
    depends_on:
      - rmqnamesrv
    networks:
      rmq:
        aliases:
          - rmqconsole

networks:
  rmq:
    name: rmq
    driver: bridge

4.4 部署容器
# 运行容器
docker-compose -f ./docker-compose.yml up -d

# 查看容器状态
docker-compose -f ./docker-compose.yml ps

# 查看容器日志
docker-compose -f ./docker-compose.yml logs rmqnamesrv|rmqbroker|rmqconsole

浏览器访问:http://localhost:8180/ 可以进入RocketMQ控制台。
Docker安装Canal与RocketMQ_第6张图片

参考文档:
https://my.oschina.net/teddyIH/blog/3102095
https://my.oschina.net/teddyIH/blog/3103308

你可能感兴趣的:(综合实战)