|
| 1 | +# Kafka UI & Kafka Connect Setup with OCI OpenSearch |
| 2 | + |
| 3 | +This guide documents how to set up **Kafka UI** and **Apache Kafka Connect** on an OCI instance, configure it to run as a service, and use the **OpenSearch Sink Connector** to stream Kafka topic data into an OCI OpenSearch index. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## 1. Prerequisites |
| 8 | + |
| 9 | +- Allow port 8080, 8083 in OCI security lists. |
| 10 | + - Enable firewall within instance |
| 11 | + * sudo firewall-cmd --permanent --add-port=8080/tcp |
| 12 | + * sudo firewall-cmd --permanent --add-port=8083/tcp |
| 13 | + |
| 14 | + |
| 15 | +- install java-11-openjdk , jq, upzip, podman |
| 16 | + |
| 17 | + * **Java (java-11-openjdk)** - required runtime for Kafka and Kafka Connect |
| 18 | + |
| 19 | + * **unzip** - to extract connector plugin packages (e.g., OpenSearch sink) |
| 20 | + |
| 21 | + * **jq** - command-line tool to pretty-print JSON responses from the Kafka Connect REST API |
| 22 | + |
| 23 | + * **Podman** - container runtime used to run Kafka UI |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## 2. Set Up Kafka UI using podman |
| 28 | + |
| 29 | +```bash |
| 30 | +podman run -d \ |
| 31 | + --name kafka-ui \ |
| 32 | + -p 8080:8080 \ |
| 33 | + -e DYNAMIC_CONFIG_ENABLED=true \ |
| 34 | + --restart=always \ |
| 35 | + docker.io/provectuslabs/kafka-ui |
| 36 | +``` |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## 3. Start Kafka UI |
| 41 | + |
| 42 | +```bash |
| 43 | +podman start kafka-ui |
| 44 | +``` |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## 4. Set Up Kafka Cluster through UI |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +## 5. Download and extract Kafka |
| 54 | + |
| 55 | +```bash |
| 56 | +curl -L -o kafka_2.13-3.7.0.tgz \ |
| 57 | + https://archive.apache.org/dist/kafka/3.7.0/kafka_2.13-3.7.0.tgz |
| 58 | + |
| 59 | +tar -xvzf kafka_2.13-3.7.0.tgz |
| 60 | +``` |
| 61 | + |
| 62 | +--- |
| 63 | + |
| 64 | +## 6. Set environment variables |
| 65 | + |
| 66 | +```bash |
| 67 | +echo 'export KAFKA_HOME=$HOME/kafka_2.13-3.7.0' >> ~/.bashrc |
| 68 | +echo 'export PATH=$KAFKA_HOME/bin:$PATH' >> ~/.bashrc |
| 69 | +source ~/.bashrc |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## 7. Create base folders |
| 75 | + |
| 76 | +```bash |
| 77 | +mkdir -p /home/opc/kafka/{logs,plugins} |
| 78 | +``` |
| 79 | + |
| 80 | +- `logs/` → holds Kafka Connect worker logs |
| 81 | +- `plugins/` → holds connector JARs (e.g., OpenSearch sink) |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## 8. Configure Kafka Connect Worker |
| 86 | + |
| 87 | +Copy the default distributed properties file: |
| 88 | + |
| 89 | +```bash |
| 90 | +cp $KAFKA_HOME/config/connect-distributed.properties \ |
| 91 | + /home/opc/kafka/connect-distributed.properties |
| 92 | +nano /home/opc/kafka/connect-distributed.properties |
| 93 | +``` |
| 94 | + |
| 95 | +Edit the following: |
| 96 | + |
| 97 | +```properties |
| 98 | +# Kafka Cluster |
| 99 | +bootstrap.servers=bootstrap-clstr-...:9092 |
| 100 | + |
| 101 | +# Worker group |
| 102 | +group.id=connect-cluster |
| 103 | + |
| 104 | +# Security |
| 105 | +security.protocol=SASL_SSL |
| 106 | +sasl.mechanism=SCRAM-SHA-512 |
| 107 | +sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="super-user-..." password="..."; |
| 108 | +# Connect Internal Topics created through Console under Kafka Connect Configurations |
| 109 | +config.storage.topic=...-config |
| 110 | +offset.storage.topic=...-offset |
| 111 | +status.storage.topic=...-status |
| 112 | +# REST API |
| 113 | +rest.host.name=0.0.0.0 |
| 114 | +rest.port=8083 |
| 115 | +rest.advertised.host.name=<VM Public IP> |
| 116 | + |
| 117 | +# Plugins |
| 118 | +plugin.path=/home/opc/kafka/plugins |
| 119 | +``` |
| 120 | + |
| 121 | +--- |
| 122 | + |
| 123 | +## 9. Create Systemd Service |
| 124 | + |
| 125 | +Create `/etc/systemd/system/kafka-connect.service`: |
| 126 | + |
| 127 | +```ini |
| 128 | +[Unit] |
| 129 | +Description=Kafka Connect Distributed |
| 130 | +After=network.target |
| 131 | + |
| 132 | +[Service] |
| 133 | +User=opc |
| 134 | +Environment="KAFKA_HOME=/home/opc/kafka_2.13-3.7.0" |
| 135 | +ExecStart=/bin/bash -lc '/home/opc/kafka_2.13-3.7.0/bin/connect-distributed.sh /home/opc/kafka/connect-distributed.properties >> /home/opc/kafka/logs/connect.log 2>&1' |
| 136 | +Restart=always |
| 137 | +RestartSec=5 |
| 138 | + |
| 139 | +[Install] |
| 140 | +WantedBy=multi-user.target |
| 141 | +``` |
| 142 | + |
| 143 | +Reload and enable: |
| 144 | + |
| 145 | +```bash |
| 146 | +sudo systemctl daemon-reload |
| 147 | +sudo systemctl enable --now kafka-connect |
| 148 | +systemctl status kafka-connect --no-pager |
| 149 | +``` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## 10. Add Kafka Connect Connection details in Kafka UI |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## 11. Install OpenSearch Sink Plugin |
| 160 | + |
| 161 | +```bash |
| 162 | +mkdir -p /home/opc/kafka/plugins/opensearch |
| 163 | + |
| 164 | +curl -fL -o /home/opc/opensearch-sink.zip \ |
| 165 | + "https://github.com/Aiven-Open/opensearch-connector-for-apache-kafka/releases/download/v3.1.1/opensearch-connector-for-apache-kafka-3.1.1.zip" |
| 166 | + |
| 167 | +unzip -o /home/opc/opensearch-sink.zip -d /home/opc/kafka/plugins/opensearch |
| 168 | +``` |
| 169 | + |
| 170 | +Restart Kafka Connect: |
| 171 | + |
| 172 | +```bash |
| 173 | +sudo systemctl restart kafka-connect |
| 174 | +``` |
| 175 | + |
| 176 | +Verify the connector is loaded: |
| 177 | + |
| 178 | +```bash |
| 179 | +curl http://localhost:8083/connector-plugins | jq . |
| 180 | +``` |
| 181 | + |
| 182 | +--- |
| 183 | + |
| 184 | +## 12. Create OpenSearch Sink Connector |
| 185 | + |
| 186 | +Example connector config (`test-opensearch`): |
| 187 | + |
| 188 | +```json |
| 189 | +{ |
| 190 | + "name": "test-opensearch", |
| 191 | + "connector.class": "io.aiven.kafka.connect.opensearch.OpensearchSinkConnector", |
| 192 | + "tasks.max": "1", |
| 193 | + "topics": "connecter-test", |
| 194 | + |
| 195 | + "connection.url": "https://<opensearch-endpoint>:9200", |
| 196 | + "connection.username": "irine235", |
| 197 | + "connection.password": "******", |
| 198 | + |
| 199 | + "index": "${topic}", |
| 200 | + "key.ignore": "true", |
| 201 | + "schema.ignore": "true", |
| 202 | + |
| 203 | + "key.converter": "org.apache.kafka.connect.json.JsonConverter", |
| 204 | + "key.converter.schemas.enable": "false", |
| 205 | + "value.converter": "org.apache.kafka.connect.json.JsonConverter", |
| 206 | + "value.converter.schemas.enable": "false", |
| 207 | + |
| 208 | + "errors.tolerance": "all", |
| 209 | + "errors.log.enable": "true", |
| 210 | + |
| 211 | + "consumer.override.security.protocol": "SASL_SSL", |
| 212 | + "consumer.override.sasl.mechanism": "SCRAM-SHA-512", |
| 213 | + "consumer.override.ssl.endpoint.identification.algorithm": "https", |
| 214 | + "consumer.override.sasl.jaas.config": "org.apache.kafka.common.security.scram.ScramLoginModule required username=\"super-user-...\" password=\"...\";" |
| 215 | +} |
| 216 | +``` |
| 217 | + |
| 218 | +Submit via Kafka UI |
| 219 | + |
| 220 | +--- |
| 221 | + |
| 222 | +## 13. Produce Test Data |
| 223 | + |
| 224 | +Create topic connecter-test and /home/opc/kafka/client.properties with the following credentials: |
| 225 | + |
| 226 | +```bash |
| 227 | +security.protocol=SASL_SSL |
| 228 | +sasl.mechanism=SCRAM-SHA-512 |
| 229 | +sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required username="super-user-..." password="..."; |
| 230 | +``` |
| 231 | + |
| 232 | +Produce message: |
| 233 | + |
| 234 | +```bash |
| 235 | +$KAFKA_HOME/bin/kafka-console-producer.sh \ |
| 236 | + --bootstrap-server bootstrap-clstr-...:9092 \ |
| 237 | + --producer.config /home/opc/kafka/client.properties \ |
| 238 | + --topic connecter-test |
| 239 | +``` |
| 240 | + |
| 241 | +Enter messages: |
| 242 | + |
| 243 | +```json |
| 244 | +{"order_id":1,"customer":"Nora","total":49.99} |
| 245 | +{"order_id":2,"customer":"Sam","total":79.99} |
| 246 | +``` |
| 247 | + |
| 248 | +--- |
| 249 | + |
| 250 | +## 14. Verify in OpenSearch |
| 251 | + |
| 252 | +Check document count: |
| 253 | + |
| 254 | +```bash |
| 255 | +curl -u 'user:pass' "https://amaaaaaae....opensearch.eu-frankfurt-1.oci.oraclecloud.com:9200/connecter-test/_count?pretty" |
| 256 | + |
| 257 | + |
| 258 | +``` |
| 259 | + |
| 260 | +--- |
| 261 | + |
| 262 | + |
0 commit comments