ngx_kafka_module模块对接kafka集群
# 编译部署librdkafka
#https://github.com/edenhill/librdkafka
unzip librdkafka-1.9.2.zip
cd librdkafka
./configure
make & make install
#加载so库
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
#编译部署nginx
#https://github.com/brg-liuwei/ngx_kafka_module
unzip ngx_kafka_module-0.9.1.zip
tar -zxvf nginx-1.20.1.tar.gz
cd /root/nginx-1.20.1
#添加ngx_kafka_module模块
./configure --add-module=/root/ngx_kafka_module
make & make install
#nginx配置
vim nginx.conf
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#
# ############### kafka config ###########################
kafka;
kafka_broker_list hadoop101:9092 hadoop102:9092 hadoop103:9092;
# ############### kafka config ###########################
server {
listen 80;
server_name node01;
#charset koi8-r;
#access_log logs/host.access.log main;
#location / {
# root html;
# index index.html index.htm;
#}
# ############### kafka config ###########################
location /kafka/test-segments {
kafka_topic test-segments;
}
location /kafka/test-managements {
kafka_topic test-managements;
}
# ############### kafka config ###########################
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
nginx -s reload
curl {IP}:{PORT}/kafka/{topic} -d 请求体
# 反向代理 负载均衡 nginx配置
upstream kafka{
server node01:8080;
server node02:9999;
}
server {
listen 80;
server_name node03;
location / {
proxy_pass http://kafka;
}
}
文章评论