Chapter 2. Starting the services
Using Debezium requires AMQ Streams and the Debezium connector service. To start the services needed for this tutorial, you must:
2.1. Setting up a Kafka cluster Copy linkLink copied to clipboard!
You use AMQ Streams to set up a Kafka cluster. This procedure deploys a single-node Kafka cluster.
Procedure
In your OpenShift 4.x cluster, create a new project:
oc new-project debezium-tutorial
$ oc new-project debezium-tutorial
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Change to the directory where you downloaded the AMQ Streams 1.6 OpenShift installation and example files.
Deploy the AMQ Streams Cluster Operator.
The Cluster Operator is responsible for deploying and managing Kafka clusters within an OpenShift cluster. This command deploys the Cluster Operator to watch just the project that you created:
sed -i 's/namespace: .*/namespace: debezium-tutorial/' install/cluster-operator/*RoleBinding*.yaml oc apply -f install/cluster-operator -n debezium-tutorial
$ sed -i 's/namespace: .*/namespace: debezium-tutorial/' install/cluster-operator/*RoleBinding*.yaml $ oc apply -f install/cluster-operator -n debezium-tutorial
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the Cluster Operator is running.
This command shows that the Cluster Operator is running, and that all of the Pods are ready:
oc get pods
$ oc get pods NAME READY STATUS RESTARTS AGE strimzi-cluster-operator-5c6d68c54-l4gdz 1/1 Running 0 46s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the Kafka cluster.
This command uses the
kafka-ephemeral-single.yaml
Custom Resource to create an ephemeral Kafka cluster with three ZooKeeper nodes and one Kafka node:oc apply -f examples/kafka/kafka-ephemeral-single.yaml
$ oc apply -f examples/kafka/kafka-ephemeral-single.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the Kafka cluster is running.
This command shows that the Kafka cluster is running, and that all of the Pods are ready:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
2.2. Deploying Kafka Connect Copy linkLink copied to clipboard!
After setting up a Kafka cluster, you deploy Kafka Connect in a custom container image for Debezium. This service provides a framework for managing the Debezium MySQL connector.
Prerequisites
- Podman or Docker is installed and you have sufficient rights to create and manage containers.
Procedure
- Download the Debezium MySQL Connector 1.4 archive from the Red Hat Integration download site.
Extract the Debezium MySQL connector archive to create a directory structure for the connector plug-in, for example:
tree ./my-plugins/ ./my-plugins/ ├── debezium-connector-mysql │ ├── ...
tree ./my-plugins/ ./my-plugins/ ├── debezium-connector-mysql │ ├── ...
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create and publish a custom image that runs Kafka Connect with the Debezium MySQL connector:
Create a new
Dockerfile
by usingregistry.redhat.io/amq7/amq-streams-kafka-26-rhel7:1.6.0
as the base image. In the following example, you would replacemy-plugins
with the name of your plug-ins directory:FROM registry.redhat.io/amq7/amq-streams-kafka-26-rhel7:1.6.0 USER root:root COPY ./my-plugins/ /opt/kafka/plugins/ USER 1001
FROM registry.redhat.io/amq7/amq-streams-kafka-26-rhel7:1.6.0 USER root:root COPY ./my-plugins/ /opt/kafka/plugins/ USER 1001
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Before Kafka Connect starts running the connector, Kafka Connect loads any third-party plug-ins that are in the
/opt/kafka/plugins
directory.Build the container image. For example, if you saved the
Dockerfile
that you created in the previous step asdebezium-container-for-mysql
, and if theDockerfile
is in the current directory, enter one of the following command:podman build -t debezium-container-for-mysql:latest .
podman build -t debezium-container-for-mysql:latest .
Copy to Clipboard Copied! Toggle word wrap Toggle overflow docker build -t debezium-container-for-mysql:latest .
docker build -t debezium-container-for-mysql:latest .
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Push your custom image to your container registry. Enter one of the following commands:
podman push <my_registry.io>/debezium-container-for-mysql:latest
podman push <my_registry.io>/debezium-container-for-mysql:latest
Copy to Clipboard Copied! Toggle word wrap Toggle overflow docker push <my_registry.io>/debezium-container-for-mysql:latest
docker push <my_registry.io>/debezium-container-for-mysql:latest
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Point to the new container image by editing the
spec.image
property of theKafkaConnect
custom resource. If this property is set, its value overrides theSTRIMZI_DEFAULT_KAFKA_CONNECT_IMAGE
variable in the Cluster Operator. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Results
Kafka Connect is now running. The container has a Debezium MySQL connector but this connector is not yet configured to capture changes in a database.
2.3. Deploying a MySQL database Copy linkLink copied to clipboard!
At this point, you have deployed a Kafka cluster and the Kafka Connect service with the Debezium MySQL database connector. However, you still need a database server from which Debezium can capture changes. In this procedure, you start a MySQL server with an example database.
Procedure
Start a MySQL database by running the following command, which starts a MySQL database server configured with an example
inventory
database:oc new-app --name=mysql quay.io/debezium/example-mysql:latest
$ oc new-app --name=mysql quay.io/debezium/example-mysql:latest
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Configure credentials for the MySQL database by running the following command, which updates the deployment configuration for the MySQL database to add the user name and password:
oc set env dc/mysql MYSQL_ROOT_PASSWORD=debezium MYSQL_USER=mysqluser MYSQL_PASSWORD=mysqlpw
$ oc set env dc/mysql MYSQL_ROOT_PASSWORD=debezium MYSQL_USER=mysqluser MYSQL_PASSWORD=mysqlpw
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the MySQL database is running by invoking the following command, which is followed by the output that shows that the MySQL database is running, and that the pod is ready:
oc get pods -l app=mysql
$ oc get pods -l app=mysql NAME READY STATUS RESTARTS AGE mysql-1-2gzx5 1/1 Running 1 23s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Open a new terminal and log into the sample
inventory
database.This command opens a MySQL command line client in the pod that is running the MySQL database. The client uses the user name and password that you previously configured:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow List the tables in the
inventory
database:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Explore the database and view the data that it contains, for example, view the
customers
table:Copy to Clipboard Copied! Toggle word wrap Toggle overflow