Http://blog.csdn.net/fenglailea/article/details/52458737#t3
directory (?) [-]
- Installing zookeeper
- 1 Direct installation zookeeper no need to compile
- 2 source code compilation installation Zookeeper
- Installing the PHP Zookeeper extension
- Note The latest version of Kafka please use 73 and 4PASS
- Installing Librdkafka
- Installing the Php-kafka Extension
- Configuring extensions
- See if the installation is complete
- Php-kafka Extensions 3 and 4 are not available when the installation is complete
The wind is coming. Fox
Installing zookeeper
Recommended 1.1 Direct copy
1.1. Install zookeeper directly (no need to compile)
: http://mirror.bit.edu.cn/apache/zookeeper/
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gztar -zxvf zookeeper-3.4.9.tar.gzmv zookeeper-3.4.9/ /usr/local/zookeeper/
Setting Global variables
vim ~/.bash_profile
Last line Join
PATH=/usr/local/zookeeper/bin:$PATH
Make it effective
source ~/.bash_profile
Configuration file Location
/usr/local
Note: The default profile does not have a case file directly zoo_sample.cfg
When you use it, copy one yourself.
cp /usr/local/zookeeper/conf/zoo_sample.cfg /usr/local/zookeeper/conf/zoo.cfg
1.2. Source code compilation Installation Zookeeper
: http://mirror.bit.edu.cn/apache/zookeeper/
wget http://mirror.bit .edu .cn /apache/zookeeper/zookeeper-3.4 .9 / Zookeeper-3.4 .9 .tar .gz tar-zxf zookeeper-3.4 .9 .tar .gz CD Zookeeper-3.4 .9 /src/c./configure-prefix=/usr /local/zookeeper/zookeeper-3.4 .9 /make & & Make install
Setting Global variables
vim ~/.bash_profile
Last line Join
PATH=/usr/local/zookeeper/zookeeper-3.4.9/bin:$PATH
Make it effective
source ~/.bash_profile
Configuration file Location
/usr/local/zookeeper/zookeeper-3.4.9
Note: The default profile does not have a case file directly zoo_sample.cfg
When you use it, copy one yourself.
cp /usr/local/zookeeper/zookeeper-3.4.9/conf/zoo_sample.cfg /usr/local/zookeeper/zookeeper-3.4.9/conf/zoo.cfg
2. Installing the PHP Zookeeper extension
wget http://pecl.php.net/get/zookeeper-0.2.2.tgzTar-ZXVFZookeeper-0.2. 2.TGZCD Zookeeper-0.2. 2Phpize./configure-with-php-config=/www/lanmps/php5. 6. at/bin/php-config -with-libzookeeper-dir=/usr/Local/zookeeper/zookeeper-3.4. 9/Make&&Make install
Note: Phpize is the phpize for your PHP version directory
Note The latest version of Kafka please use 7 (3 and 4PASS) 3. Install Librdkafka
wget https://github.com/edenhill/librdkafka/archive/master.zipmv master.zip librdkafka-master.zipunzip librdkafka-master.zipcd librdkafka-master./configuremakemake install
4. Installing the Php-kafka Extension
wget https://github.com/EVODelavega/phpkafka/archive/master.zipmv master.zip phpkafka-master.zipunzip phpkafka-master.zipcd phpkafka-masterphpize./configure --enable-kafka --with-php-config=/www/lanmps/php5.6.23/bin/php-configmake #编译make install #安装
Note: Phpize is the phpize for your PHP version directory
5. Configure the extension
Edit PHP configuration file
vim php.ini
End add
extension=zookeeper.soextension=kafka.so
Note: Find out if Extension_dir is already configured, and if not, configure it yourself.
Each extension compilation will output (similar to the following) when it is successfully installed
Installing shared extensions: /安装目录/php5.6.23/lib/php/extensions/no-debug-non-zts-20131226/
Just copy the address, change it to the following format, and add it to the php.ini.
extension_dir=/安装目录/php5.6.23/lib/php/extensions/no-debug-non-zts-20131226/
6. See if the installation is complete
In
Phpinfo ();
Inside view
If there is a kafka,zookeeper extension, if there is an indication that the installation was successful
7.php-kafka extensions (when 3 and 4 are not available after installation is complete)
https://github.com/nmred/kafka-php
Use this extension to support the latest version of Kafka
Here are the examples (under the example folder) that are installed using composer:
producer.php
<?Phprequire ' vendor/autoload.php ';$part =Mt_rand (0,1);$produce = \Kafka\Produce:: getinstance(' localhost:2181 ', the);//Get available partitions $partitions = $produce -Getavailablepartitions (' topic_name '); Var_dump ($partitions);//Send Message $produce -Setrequireack (-1);$produce -Setmessages (' topic_name ',0,Array(Date(' y-m-d h:i:s '));
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
consumer.php
require ' vendor/autoload.php ';$consumer = \Kafka\Consumer:: getinstance(' localhost:2181 ');$group = ' topic_name ';$consumer -Setgroup ($group);$consumer -Setfromoffset (true);$consumer -Settopic (' topic_name ',0);$consumer -Setmaxbytes (102400);$result = $consumer -Fetch ();p Rint_r ($result); foreach ($resultAs$topicName = $partition) {foreach ($partitionAs$partId = $messageSet) {Var_dump ($partition -Gethighoffset ()); foreach ($messageSetAs$message) {Var_dump (string)$message); } var_dump ($partition -Getmessageoffset ()); }}
Zookeeper and PHP zookeeper and Kafka extensions installation