源碼編譯安裝zookeeperphp
下載地址:https://archive.apache.org/dist/zookeeper/git
cd /usr/local/github
wget https://archive.apache.org/dist/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gzapache
tar -zxf zookeeper-3.4.9.tar.gzjson
cd zookeeper-3.4.9/src/cvim
./configure --prefix=/usr/local/zookeeper-3.4.9/bash
makemarkdown
make installcomposer
設置全局變量curl
vim ~/.bash_profile
最後一行加入
export PATH=/usr/local/zookeeper-3.4.9/bin:$PATH
使之生效
source ~/.bash_profile
配置文件位置
/usr/local/zookeeper-3.4.9/conf/zoo.cfg
注意:默認配置文件並無,直有一個案例文件 zoo_sample.cfg
使用的時候要 自行復制一個
cp /usr/local/zookeeper-3.4.9/conf/zoo_sample.cfg /usr/local/zookeeper-3.4.9/conf/zoo.cfg
2.安裝php zookeeper擴展
wget http://pecl.php.net/get/zookeeper-0.2.2.tgz
tar -zxvf zookeeper-0.2.2.tgz
cd zookeeper-0.2.2
./configure --with-php-config=/opt/lampp/bin/php-config --with-libzookeeper-dir=/usr/local/zookeeper-3.4.9/
make
make install
3.安裝librdkafka
cd /usr/local/src #進入安裝包存放目錄
wget https://github.com/edenhill/librdkafka/archive/master.zip #下載
mv master.zip librdkafka-master.zip #修改包名
unzip librdkafka-master.zip #解壓
cd librdkafka-master #進入安裝文件夾
./configure #配置
make #編譯
make install #安裝
4.安裝phpkafka
cd /usr/local/src #進入安裝包存放目錄
wget https://github.com/EVODelavega/phpkafka/archive/master.zip #下載
mv master.zip phpkafka-master.zip #修改包名
unzip phpkafka-master.zip #解壓
cd phpkafka-master #進入安裝文件夾
/usr/local/php/bin/phpize #加載php擴展模塊
./configure --enable-kafka --with-php-config=/usr/local/php/bin/php-config #配置
make #編譯
make install #安裝
5.配置擴展
vim php.ini
末尾增長
extension=zookeeper.so
extension=kafka.so
注意:先查找 extension_dir 是否已經配置過,若是沒有配置,請自行配置。
每一個擴展編譯安裝成功後都會輸出(相似以下)
Installing shared extensions: /安裝目錄/php5.6.23/lib/php/extensions/no-debug-non-zts-20131226/
只要把地址複製,改爲以下格式,加入到php.ini裏
extension_dir=/安裝目錄/php5.6.23/lib/php/extensions/no-debug-non-zts-20131226/
6.查看是否安裝完成
在 phpinfo(); 裏面查看 是否有 kafka,zookeeper 擴展,若是有表示安裝成功
7.安裝composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
八、composer 安裝 nmred/kafka-php
使用 :進入composer.json 所在的目錄 執行:composer install
composer.json 內容以下:
{
"repositories": {
"packagist": {
"type": "composer",
"url": "https://packagist.phpcomposer.com"
}
},
"require": {
"nmred/kafka-php": "0.1.*"
}
}
repositories的做用是使得 composer安裝的時候 速度更快
require 則是須要下載的類庫
八、PHP 調用下載的類庫
require 'vendor/autoload.php';$consumer = \Kafka\Consumer::getInstance('localhost:2181/kafka');$consumer->setGroup(1);$consumer->setPartition('topicName',0,9);while(true){$result = $consumer->fetch();if($result){foreach ($result as $topicName => $topic) {foreach ($topic as $partId => $partition) {foreach ($partition as $message) {var_dump((string)$message);}}}}sleep(1);}