美文网首页Zookeeper
PHP-Zookeeper扩展安装

PHP-Zookeeper扩展安装

作者: 泡水鱼干 | 来源:发表于2021-05-11 09:30 被阅读0次

    问题

    • 使用pecl安装扩展
      在编译extension时候会 ZOO_MAJOR_VERSION 错误,由于pecl的源码包没有修复bug,建议使用GitHub下载
    • 网上很多文章教程基于zookeeper3.5.9之前,zookeeper软件目录及文件已经变化,新版不存在/src/c 这个目录

    环境准备

    zookeeper 版本:Apache ZooKeeper, version 3.6.2
    php版本:PHP 7.3.27 (cli) (built: Apr 20 2021 13:59:37) ( NTS )
    extension:php- zookeeper 0.7.2
    linux:centos 8

    系统环境

    yum install -y cppunit-devel antl gcc build-essential zlib zlib-devel openssl openssl-devel pcre pcre-devel gcc-c++ autoconf automake
    

    Zookeeper C Binding

    参考:https://github.com/php-zookeeper/php-zookeeper

    低于ZooKeeper 3.5.9

    # 在 apache-zookeeper-3.5.9/src/c 下执行
    $ ./configure --prefix=/usr/local/zookeeper-lib
    $ make
    $ sudo make install
    

    ZooKeeper 3.5.9

    $ autoreconf -if
    $ ant compile_jute
    $ ./configure --prefix=/usr/local/zookeeper-lib
    $ make
    $ sudo make install
    

    ZooKeeper 3.6.x之后

    $ autoreconf -if
    # 从ZooKeeper 3.6.0开始,由于缺少build.xml,ant将失败。该文件和另外两个文件可以在3.5.9的源压缩包中找到
    $ cd apache-zookeeper-3.5.9
    $ cp build.xml ivy* ../apache-zookeeper-3.6.x
    # 在 apache-zookeeper-3.6.x 根目录执行
    $ ant compile_jute
    # 在 zookeeper-client/zookeeper-client-c 下执行
    $ ./configure --prefix=/usr/local/zookeeper-lib
    $ make
    $ sudo make install
    

    安装PHP扩展

    下载

    $ git clone https://github.com/php-zookeeper/php-zookeeper.git
    

    安装

    不要使用 pecl 有bug

    # 在php-zookeeper目录下执行
    [root@localhost php-zookeeper]#  phpize
    [root@localhost php-zookeeper]#  ./configure --with-libzookeeper-dir=/usr/local/zookeeper-lib
    [root@localhost php-zookeeper]#  make
    
    ----------------------------------------------------------------------
    Libraries have been installed in:
       /root/php-zookeeper/modules
    
    If you ever happen to want to link against installed libraries
    in a given directory, LIBDIR, you must either use libtool, and
    specify the full pathname of the library, or use the `-LLIBDIR'
    flag during linking and do at least one of the following:
       - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
         during execution
       - add LIBDIR to the `LD_RUN_PATH' environment variable
         during linking
       - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
       - have your system administrator add LIBDIR to `/etc/ld.so.conf'
    
    See any operating system documentation about shared libraries for
    more information, such as the ld(1) and ld.so(8) manual pages.
    ----------------------------------------------------------------------
    [root@localhost php-zookeeper]# make install
    Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/
    

    配置

    将 /usr/local/php/lib/php/extensions/no-debug-non-zts-20180731/zookeeper.so 加入到php.ini

    验证

    # 重启服务
    $ service php-fpm restart
    $ service nginx restart
    [root@localhost zookeeper-client-c]# php -i | grep zookeeper
    Registered save handlers => files user zookeeper 
    zookeeper
    zookeeper support => enabled
    libzookeeper version => 3.6.0
    zookeeper.recv_timeout => 10000 => 10000
    zookeeper.sess_lock_wait => 150000 => 150000
    zookeeper.session_lock => 1 => 1
    

    相关文章

      网友评论

        本文标题:PHP-Zookeeper扩展安装

        本文链接:https://www.haomeiwen.com/subject/kbkgdltx.html