Zookeeper and PHP zookeeper and Kafka extended installation

Source: Internet
Author: User
Tags autoload zts

Http://blog.csdn.net/fenglailea/article/details/52458737#t3

directory (?) [-]

    1. Installing zookeeper
      1. 1 Direct installation zookeeper no need to compile
      2. 2 source code compilation installation Zookeeper
    2. Installing the PHP Zookeeper extension
    3. Note The latest version of Kafka please use 73 and 4PASS
    4. Installing Librdkafka
    5. Installing the Php-kafka Extension
    6. Configuring extensions
    7. See if the installation is complete
    8. 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/
    • 1
    • 2
    • 3
    • 4
    • 1
    • 2
    • 3
    • 4

Setting Global variables

vim ~/.bash_profile
    • 1
    • 1

Last line Join

PATH=/usr/local/zookeeper/bin:$PATH
    • 1
    • 1

Make it effective

source ~/.bash_profile
    • 1
    • 1

Configuration file Location

/usr/local
    • 1
    • 1

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
    • 1
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  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

Setting Global variables

vim ~/.bash_profile
    • 1
    • 1

Last line Join

PATH=/usr/local/zookeeper/zookeeper-3.4.9/bin:$PATH
    • 1
    • 1

Make it effective

source ~/.bash_profile
    • 1
    • 1

Configuration file Location

/usr/local/zookeeper/zookeeper-3.4.9
    • 1
    • 1

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
    • 1
    • 1
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
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

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
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
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  #安装
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

Note: Phpize is the phpize for your PHP version directory

5. Configure the extension

Edit PHP configuration file

vim php.ini
    • 1
    • 1

End add

extension=zookeeper.soextension=kafka.so
    • 1
    • 2
    • 1
    • 2

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/
    • 1
    • 1

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/
    • 1
    • 1
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.