【go-kafka】go对接kafka安装配置

前言

针对golang的 kafka client有很多开源package,例如sarama, confluent等等。

confluent-kafka-go,是kafka官网推荐的golang package。

官网地址: https://github.com/confluentinc/confluent-kafka-go

1.安装go

yum 安装

#安装go
[root@localhost ~]# yum install go -y

#创建GOPATH目录
[root@localhost ~]# mkdir /root/gowork

#配置GOPATH环境变量
[root@localhost ~]# vim /etc/profile
export GOPATH=/root/gowork

#使配置生效
[root@localhost ~]# source /etc/profile

#验证GOPATH
[root@localhost ~]# echo $GOPATH
/root/gowork

源码安装

2.安装beego
#安装beego框架
[root@localhost ~]# go get -u github.com/astaxie/beego

#安装bee工具
[root@localhost ~]# go get -u github.com/beego/bee

#查看安装结果
[root@localhost ~]# ll /root/gowork/
total 0
drwxr-xr-x. 2 root root 17 Jul  2 17:09 bin
drwxr-xr-x. 3 root root 25 Jul  2 17:06 pkg
drwxr-xr-x. 3 root root 24 Jul  2 17:05 src

#bin 存放可执行文件
#pkg 存放第三方库文件
#src 存放工程源码

#配置PATH环境变量
[root@localhost ~]# vim /etc/profile
export PATH=$GOPATH/bin:$PATH

#使配置生效
[root@localhost ~]# source /etc/profile
3.安装librdkafka库
#查看zlib-devel依赖包是否存在
[root@localhost ~]# rpm -qa|grep zlib
zlib-1.2.7-17.el7.x86_64
zlib-devel-1.2.7-17.el7.x86_64

#如果不存在需要安装
[root@localhost ~]# yum install zlib-devel -y

#从github上克隆源码
[root@localhost ~]# git clone https://github.com/edenhill/librdkafka.git

#进入librdkafka目录
[root@localhost ~]# cd librdkafka

#初始化配置,安装到/usr目录
[root@localhost librdkafka]# ./configure --prefix=/usr

#编译源码
[root@localhost librdkafka]# make

#安装
[root@localhost librdkafka]# make install
4.安装go对接kafka客户端
配置PKG_CONFIG_PATH:
#在~/.bashrc文件尾部追加
[root@localhost ~]# vim ~/.bashrc
export PKG_CONFIG_PATH=/usr/lib/pkgconfig

#使配置生效
[root@localhost ~]# source ~/.bashrc

#验证配置
[root@localhost ~]# echo $PKG_CONFIG_PATH
/usr/lib/pkgconfig
安装客户端:
[root@localhost librdkafka]# go get -u github.com/confluentinc/confluent-kafka-go/kafka

5.参考文章

https://github.com/confluentinc/confluent-kafka-go
https://blog.csdn.net/lanyang123456/article/details/78377152

你可能感兴趣的:(kafka,go,go,kafka)