搜索

第 3 章 启动服务

download PDF

使用 Debezium 需要 Kafka 和 Kafka Connect、数据库和 Debezium 连接器服务的 AMQ Streams。要为本教程运行服务,您必须:

3.1. 部署 MySQL 数据库

部署 MySQL 数据库服务器,其中包含带有数据预先填充的多个表的示例 inventory 数据库。Debezium MySQL 连接器将捕获示例表中发生的更改,并将更改事件记录传送到 Apache Kafka 主题。

流程

  1. 运行以下命令启动 MySQL 数据库,该命令启动配置了示例 inventory 数据库的 MySQL 数据库服务器:

    $ oc new-app -l app=mysql --name=mysql quay.io/debezium/example-mysql:latest
  2. 运行以下命令,为 MySQL 数据库配置凭证,该命令更新 MySQL 数据库的部署配置以添加用户名和密码:

    $ oc set env deployment/mysql MYSQL_ROOT_PASSWORD=debezium MYSQL_USER=mysqluser MYSQL_PASSWORD=mysqlpw
  3. 通过调用以下命令来验证 MySQL 数据库是否正在运行,该命令后跟显示 MySQL 数据库正在运行的输出,以及 pod 是否已就绪:

    $ oc get pods -l app=mysql
    NAME            READY   STATUS    RESTARTS   AGE
    mysql-1-2gzx5   1/1     Running   1          23s
  4. 打开一个新终端,再登录示例 inventory 数据库。

    此命令在运行 MySQL 数据库的 pod 中打开一个 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>
  5. 列出 inventory 数据库中的表:

    mysql> show tables;
    +---------------------+
    | Tables_in_inventory |
    +---------------------+
    | addresses           |
    | customers           |
    | geom                |
    | orders              |
    | products            |
    | products_on_hand    |
    +---------------------+
    6 rows in set (0.00 sec)
  6. 探索数据库并查看其包含的数据,例如,查看 customers 表:

    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)
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.