如何安装php中zookeeper扩展

发布时间:2021-09-28 09:36:47 作者:小新
来源:亿速云 阅读:134

这篇文章给大家分享的是有关如何安装php中zookeeper扩展的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

安装方法:1、安装并启动zookeeper服务器;2、下载zookeeper扩展,并解压到PHP安装目录的ext目录下;3、在php安装目录下,执行命令生成configure和makefile;4、使用make命令编译安装即可。

本教程操作环境:centos6.4系统、PHP5.5.10版,DELL G3电脑

ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是Google的Chubby一个开源的实现,是Hadoop和Hbase的重要组件。它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护、域名服务、分布式同步、组服务等。

ZooKeeper的目标就是封装好复杂易出错的关键服务,将简单易用的接口和性能高效、功能稳定的系统提供给用户。

要在php中使用zookeeper,先要安装php zookeeper扩展,要安装php zookeeper扩展,得先安装zookeeper

安装php zookeeper扩展的方法

环境:

centos : 6.4

zookeeper : 3.4.5

php : 5.5.10

nginx : 1.5

php zookeeper扩展 :0.2.2

如果没有安装nginx,先安装nginx;确保先把nginx配置好,再往下

如果没有安装php,先安装php(先把nginx的php支持配置好了之后,再去安装zookeeper的扩展)

安装zookeeper

下载

wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.5/zookeeper-3.4.5.tar.gz

解压(随便你放在哪个目录,记得就行)

tar zxfv zookeeper-3.4.5.tar.gz

启动zookeeper服务器

cd zookeeper-3.4.5/conf
cp zoo_sample.cfg zoo.cfg
cd ../bin
./zkServer.sh start

这里最好确认一下是否期待成功,./zkServer.sh status

我这里是单台,所以结果为:

[root@localhost bin]# ./zkServer.sh status
JMX enabled by default
Using config: /root/zookeeper-3.4.5/bin/../conf/zoo.cfg
Mode: standalone

编译zookeeper库,给php用的

cd ../src/c
./configure --prefix=/usr/local/zookeeperlib
make && make install

安装php的zookeeper扩展

下载

wget http://pecl.php.net/get/zookeeper-0.2.2.tgz

解压(解压出来的package.xml不用去管他)

tar zxvf zookeeper-0.2.2.tgz

把他放到/root/php-5.5.10/ext中

mv zookeeper-0.2.2 /root/php-5.5.10/ext/
cd /root/php-5.5.10/ext/

改目录名字

mv zookeeper-0.2.2 zookeeper

回到php-5.5.10目录

cd ..
./buildconf --force
./configure -h|grep zookeeper

查看configure是否已经支持了zookeeper

--enable-zookeeper               Enable zookeeper support
--disable-zookeeper-session      Disable zookeeper session handler support
--with-libzookeeper-dir=DIR   Set the path to libzookeeper install prefix.

如果显示如上,说明已经支持了,继续往下

cd ext/zookeeper

生成configure

/usr/local/php5.5.10/bin/phpize

生成makefile

./configure --with-php-config=/usr/local/php5.5.10/bin/php-config  --with-libzookeeper-dir=/usr/local/zookeeperlib
注意上面的路径:
--with-php-config是php安装的路径
--with-libzookeeper-dir是第一步中install zookeeper库的路径

编译安装

make && make install

结果为,这个结果接下来的配置要用到

Installing shared extensions:     /usr/local/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/

添加ext路径和文件名

vim /usr/local/php5.5.10/etc/php.ini
 
extension_dir="/usr/local/php5.5.10/lib/php/extensions/no-debug-non-zts-20121212/"
extension=zookeeper.so

重新编译php

进入Php的源码文件夹,不要进错了。我的源码文件夹是/root/php-5.5.10,安装目录是/usr/local/php5.5.10

cd /root/php-5.5.10
rm -rf autom4te.cache/ configure
./buildconf --force
./configure -h|grep zookeeper

查看configure是否已经支持了zookeeper

如果已经支持了,继续往下

./configure --prefix=/usr/local/php5.5.10 --with-config-file-path=/usr/local/php5.5.10/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-zookeeper --with-libzookeeper-dir=/usr/local/zookeeperlib --enable-sockets
 make && make install

到这里,已经安装好支持了,来测试下是否正常

在zookeeper-0.2.2.tgz中(也就是Php的zookeeper扩展),有examples/Zookeeper_Example.php文件,可以用来测试

cp /root/php-5.5.10/ext/zookeeper/examples/Zookeeper_Example.php /usr/local/nginx/html/
/usr/local/php5.5.10/bin/php /usr/local/nginx/html/Zookeeper_Example.php

看是否能打印出如下结果

string(0) ""
array(1) {
  [0]=>
  string(9) "zookeeper"
}
NULL
string(3) "abc"
array(2) {
  [0]=>
  string(7) "test123"
  [1]=>
  string(9) "zookeeper"
}
NULL
NULL
array(2) {
  [0]=>
  string(3) "001"
  [1]=>
  string(3) "002"
}

重启php-fpm

killall php-fpm
/usr/local/php5.5.10/sbin/php-fpm

现在就可以通过浏览器访问支持zookeeper扩展的php了

如果还有别的问题,请检查:

1、iptables

2、selinux

感谢各位的阅读!关于“如何安装php中zookeeper扩展”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

推荐阅读:
  1. Ubuntu16.04安装php zookeeper扩展
  2. php中安装mongodb扩展

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:SpringBootSecurity中URL动态权限是怎样的

下一篇:如何解决网站建设更新完前台看不到的问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》