安装依赖 librdkafka
//定义安装版本 (请根据自己情况修改版本号)
export DOWNLOAD_LIBRDKAFKA_VERSION=1.4.0
wget https://github.com/edenhill/librdkafka/archive/v$DOWNLOAD_LIBRDKAFKA_VERSION.tar.gz -O /tmp/v$DOWNLOAD_LIBRDKAFKA_VERSION.tar.gz
mkdir -p /tmp/librdkafka-v$DOWNLOAD_LIBRDKAFKA_VERSION
tar -zxvf /tmp/v$DOWNLOAD_LIBRDKAFKA_VERSION.tar.gz -C /tmp/librdkafka-v$DOWNLOAD_LIBRDKAFKA_VERSION --strip-components=1
rm /tmp/v$DOWNLOAD_LIBRDKAFKA_VERSION.tar.gz \
&& cd /tmp/librdkafka-v$DOWNLOAD_LIBRDKAFKA_VERSION \
&& ./configure \
&& sudo make \
&& sudo make install
//是否删除安装包目录 默认先注释,根据自己需要打开
// rm -r /tmp/librdkafka-v$DOWNLOAD_LIBRDKAFKA_VERSION
查看安装位置
[xxx@xxx ~]$ whereis librdkafka
librdkafka: /usr/local/lib/librdkafka.a /usr/local/lib/librdkafka.so\
查看环境php版本
[xxx@xxx ~]$ php -v
PHP 7.4.1 (cli) (built: Dec 18 2019 14:46:18) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.1, Copyright (c), by Zend Technologies
php扩展 rdkafka
- 进入页面跟进windows 还是linux 以及php版本选择最新的stable版本
pecl地址: http://pecl.php.net/package/rdkafka
[xxx@xxx ~]$ pecl install rdkafka
Build process completed successfully
Installing '/usr/local/php/lib/php/extensions/no-debug-non-zts-20170718/rdkafka.so'
install ok: channel://pecl.php.net/rdkafka-4.0.3
Extension rdkafka enabled in php.ini
[xxx@xxx ~]$ wget http://pecl.php.net/get/rdkafka-4.0.3.tgz -O /tmp/rdkafka-v4.0.3.tar.gz \
&& mkdir -p /tmp/rdkafka-v4.0.3 \
&& tar -zxvf /tmp/rdkafka-v4.0.3.tar.gz -C /tmp/rdkafka-v4.0.3 --strip-components=1 \
&& rm /tmp/rdkafka-v4.0.3.tar.gz \
&& cd /tmp/rdkafka-v4.0.3 \
&& phpize \
&& ./configure \
&& sudo make \
&& sudo make install
- 最后在php.ini 增加 rdkafka.so 扩展重启fpm即可
vim php.ini
extension="rdkafka.so"
大功告成 查看安装版本
[xxx@xxx ~]$ php --ri rdkafka
rdkafka
rdkafka support => enabled
version => 4.0.3
build date => Aug 13 2020 10:29:54
librdkafka version (runtime) => 1.5.0
librdkafka version (build) => 1.5.0.255
如果出现问题 1. /bin/ld:librdkafka.lds:1: syntax error in VERSION script
- 将Makefile.config文件中的WITH_LDS=y这一行注释掉
有任何疑问都可以关注作者公众号点击菜单–>联系作者相互探讨交流