Example of integrating Kafka with Nginx

Example of integrating Kafka with Nginx

background

nginx-kafka-module is a plug-in for nginx that can integrate Kafka into nginx to facilitate the collection of data from front-end pages in web projects. If data is embedded on the front-end page, some user access and request data can be sent directly to the message middleware Kafka through http requests. The backend can consume messages in Kafka through programs to perform real-time calculations. For example, SparkStream can be used to consume data in Kafka in real time to analyze user PV, UV, some user behaviors, and the funnel model conversion rate of the page to better optimize the system or conduct real-time dynamic analysis of visiting users.

Specific integration steps

1. Install git

yum install -y git

2. Switch to the /usr/local/src directory and clone the Kafka C client source code to the local

cd /usr/local/src
git clone https://github.com/edenhill/librdkafka

3. Enter librdkafka and compile

cd librdkafka
yum install -y gcc gcc-c++ pcre-devel zlib-devel
./configure
make && make install

4. Install the nginx integrated kafka plug-in, enter /usr/local/src, clone nginx integrated kafka source code

cd /usr/local/src
git clone https://github.com/brg-liuwei/ngx_kafka_module

5. Enter the nginx source package directory (compile nginx, and then compile the plug-in at the same time)

cd /usr/local/src/nginx-1.12.2
./configure --add-module=/usr/local/src/ngx_kafka_module/
make && make install

6. Modify the nginx configuration file: set a location and kafka topic. For details, please see nginx.conf in the current directory

#Add configuration (2 places)
kafka;
kafka_broker_list f1:9092 f2:9092 f3:9092;

location = /kafka/access {
kafka_topic access888;
}

As shown below:

7. Start zk and kafka clusters (create topics)

zkServer.sh start
kafka-server-start.sh -daemon config/server.properties

8. Start nginx, report an error, and cannot find the kafka.so.1 file

error while loading shared libraries: librdkafka.so.1: cannot open shared object file: No such file or directory

9. Load the so library

#Load the library under /usr/local/lib at boot time echo "/usr/local/lib" >> /etc/ld.so.conf
#Manually load ldconfig

10. Test, write data to nginx, and then observe whether Kafka consumers can consume the data

curl http://localhost/kafka/access -d "message send to kafka topic"
curl http://localhost/kafka/access -d "Xiaowei666" test

You can also simulate the page embedding request interface to send information:

The background Kafka consumption information is as follows:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Spring Boot WebSocket integration and nginx configuration
  • How to install and configure FastDFS and integrate it with Nginx-1.13.3
  • Detailed explanation of the installation and configuration of Nginx+Tomcat integration under Linux
  • Detailed explanation of the integration process of centos6.4+nginx+mysql+php+phpmyadmin
  • How to Integrate Redmine and SVN into Nginx in Linux

<<:  js to implement verification code interference (static)

>>:  js to implement verification code interference (dynamic)

Recommend

MySql learning day03: connection and query details between data tables

Primary Key: Keyword: primary key Features: canno...

The difference between KEY, PRIMARY KEY, UNIQUE KEY, and INDEX in MySQL

The problem raised in the title can be broken dow...

Object.entries usage you don't know in JavaScript

Table of contents Preface 1. Use for...of to iter...

Getting Started Tutorial for Beginners ④: How to bind subdirectories

To understand what this means, we must first know ...

MySQL 8.0.13 installation and configuration method graphic tutorial

This article shares the installation and configur...

MySQL batch adding and storing method examples

When logging in to the stress test, many differen...

Simple implementation method of vue3 source code analysis

Table of contents Preface 🍹Preparation 🍲vue3 usag...

Detailed tutorial for upgrading zabbix monitoring 4.4 to 5.0

1. Zabbix backup [root@iZ2zeapnvuohe8p14289u6Z /]...

Detailed explanation of HTML onfocus gain focus and onblur lose focus events

HTML onfocus Event Attributes Definition and Usag...

How to build YUM in Centos7 environment

1. Enter the configuration file of the yum source...

MySQL Optimization: Cache Optimization (Continued)

There are caches everywhere inside MySQL. When I ...

LINUX Checks whether the port is occupied

I have never been able to figure out whether the ...