您的位置:首页 > 运维架构 > Linux

linux php安装zookeeper扩展

2014-04-01 17:22 507 查看
linux php安装zookeeper扩展

tags:php zookeeper linux ext

前言:

zookeeper提供很犀利的命名服务,并且集群操作具有原子性,所以在我的多个项目中被采用。

在原项目总,服务器集群的状态统一上报到zookeeper集群中,然后通过客户端来访问zookeeper,实时观察集群的状态(当然了,你要做成配置同步也可以)。但是客户端跨平台不方便,开发一个手机客户端又太egg pain了,所以打算采用PHP来读取zookeeper中。

以下是安装php的zookeeper扩展的步骤。多次使用,如有问题请反馈。转载请注明出处。

环境:

1、如果没有安装nginx,先安装nginx,可参照:http://hi.baidu.com/solohac/item/081e97e54868403f86d9deff

确保先把nginx配置好,再往下

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

下载

wget http://hk2.php.net/distributions/php-5.5.10.tar.gz
解压

tar zxvf php-5.5.10.tar.gz

生成、安装

cd php-5.5.10

make && make install

配置php

启动

查看端口是否监听

netstat -lnt | grep 9000

编辑nginx配置文件

nginx重新加载配置

nginx -s reload

测试php访问

cd /usr/local/nginx/html/

vim aa.php

写入内容

如果php能正常访问了,继续下面的安装,如果不行,先回头把php的支持弄好。

2、安装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服务器

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

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

编译zookeeper库,给php用的

3、安装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

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

cd ext/zookeeper

生成configure

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

生成makefile

编译安装

make && make install

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

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

添加ext路径和文件名

4、重新编译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文件,可以用来测试

看是否能打印出如下结果

重启php-fpm

killall php-fpm

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

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

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

1、iptables

2、selinux
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: