安装nginx-kafka插件
- 1.安装git
yum install -y git
复制代码
- 2.切换到/usr/local/src目录,然后将kafka的c客户端源码clone到本地
cd /usr/local/src
如果git下载失败使用这个命令
报错内容: fatal: unable to access 'https://github.com/edenhill/librdkafka.git/': Peer reports incompatible or unsupported protocol version.
解决:yum update -y nss curl libcurl
git clone https://github.com/edenhill/librdkafka
复制代码
- 3.进入到librdkafka,然后进行编译
cd librdkafka
yum install -y gcc gcc-c++ pcre-devel zlib-devel
./configure
make && make install
复制代码
- 4.安装nginx整合kafka的插件,进入到/usr/local/src,clone nginx整合kafka的源码
cd /usr/local/src
git clone https://github.com/brg-liuwei/ngx_kafka_module
复制代码
- 5.进入到nginx的源码包目录下 (编译nginx,然后将将插件同时编译)
cd /usr/local/src/nginx-1.12.2
./configure --add-module=/usr/local/src/ngx_kafka_module/
make
make install
复制代码
-
6.修改nginx的配置文件,详情请查看当前目录的nginx.conf
-
7.启动zk和kafka集群(创建topic)
/bigdata/zookeeper-3.4.9/bin/zkServer.sh start
/bigdata/kafka_2.11-0.10.2.1/bin/kafka-server-start.sh -daemon /bigdata/kafka_2.11-0.10.2.1/config/server.properties
复制代码
创建topic:
./kafka-topics.sh --create --zookeeper spark1:2181,spark2:2181,spark3:2181 --replication-factor 3 --partitions 3 --topic track
./kafka-topics.sh --create --zookeeper spark1:2181,spark2:2181,spark3:2181 --replication-factor 3 --partitions 3 --topic user
复制代码
消费者:
./kafka-console-consumer.sh --bootstrap-server spark1:9092,spark2:9092,spark3:9092 --topic user --from-beginning
复制代码
- 查看数据是否同步;
./kafka-topics.sh --describe --zookeeper spark1:2181,spark2:2181,spark3:2181 --topic track
复制代码
- 8.启动nginx,报错,找不到kafka.so.1的文件
error while loading shared libraries: librdkafka.so.1: cannot open shared object file: No such file or directory
复制代码
- 9.加载so库
echo "/usr/local/lib" >> /etc/ld.so.conf
ldconfig
复制代码
- 10.重新加载nginx
usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
复制代码
- 11.测试,向nginx中写入数据,然后观察kafka的消费者能不能消费到数据
curl localhost/kafka/track -d "message send to kafka topic"
curl localhost/kafka/track -d "老赵666"
复制代码