第 2 章 启动服务
使用 Debezium 需要带有 Kafka 和 Kafka Connect 的 AMQ Streams、数据库和 Debezium 连接器服务。要为本教程运行服务,您必须:
2.1. 部署 MySQL 数据库
部署包含示例 inventory
数据库的 MySQL 数据库服务器,其中包含预填充数据的几个表。Debezium MySQL 连接器将捕获示例表中发生的更改,并将更改事件记录传送到 Apache Kafka 主题。
流程
运行以下命令启动 MySQL 数据库,它会启动一个使用示例
inventory
数据库配置的 MySQL 数据库服务器:$ oc new-app -l app=mysql --name=mysql quay.io/debezium/example-mysql:latest
运行以下命令,为 MySQL 数据库配置凭证,该命令更新 MySQL 数据库的部署配置,以添加用户名和密码:
$ oc set env deployment/mysql MYSQL_ROOT_PASSWORD=debezium MYSQL_USER=mysqluser MYSQL_PASSWORD=mysqlpw
运行以下命令验证 MySQL 数据库是否正在运行,该命令后跟显示 MySQL 数据库正在运行,并且 pod 是否已就绪:
$ oc get pods -l app=mysql NAME READY STATUS RESTARTS AGE mysql-1-2gzx5 1/1 Running 1 23s
打开一个终端,再登录
示例清单
数据库。此命令在 pod 中打开一个运行 MySQL 数据库的 MySQL 命令行客户端。客户端使用之前配置的用户名和密码:
$ oc exec mysql-1-2gzx5 -it -- mysql -u mysqluser -pmysqlpw inventory mysql: [Warning] Using a password on the command line interface can be insecure. Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 7 Server version: 5.7.29-log MySQL Community Server (GPL) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
列出
inventory
数据库中的表:mysql> show tables; +---------------------+ | Tables_in_inventory | +---------------------+ | addresses | | customers | | geom | | orders | | products | | products_on_hand | +---------------------+ 6 rows in set (0.00 sec)
探索数据库并查看它包含的数据,例如查看 customer
表
:mysql> select * from customers; +------+------------+-----------+-----------------------+ | id | first_name | last_name | email | +------+------------+-----------+-----------------------+ | 1001 | Sally | Thomas | sally.thomas@acme.com | | 1002 | George | Bailey | gbailey@foobar.com | | 1003 | Edward | Walker | ed@walker.com | | 1004 | Anne | Kretchmar | annek@noanswer.org | +------+------------+-----------+-----------------------+ 4 rows in set (0.00 sec)