Home > php教程 > php手册 > linux php安装zookeeper扩展

linux php安装zookeeper扩展

WBOY
Release: 2016-06-06 19:52:57
Original
1168 people have browsed it

linux php安装zookeeper扩展 tags:phpzookeeperlinux ext 前言: zookeeper提供很犀利的命名服务,并且集群操作具有原子性,所以在我的多个项目中被采用。 在原项目总,服务器集群的状态统一上报到zookeeper集群中,然后通过客户端来访问zookeeper,实时观察

linux php安装zookeeper扩展

 

tags:php zookeeper linux ext

 

前言:

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

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

 

环境:

1

2

3

4

5

centos : 6.4  

zookeeper : 3.4.5 

php : 5.5.10 

nginx : 1.5

php zookeeper扩展 :0.2.2

 

 

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

1

./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

 

make && make install

 

 

配置php

1

2

cp php.ini-production /usr/local/php5.5.10/etc/php.ini

cp /usr/local/php5.5.10/etc/php-fpm.conf.default /usr/local/php5.5.10/etc/php-fpm.conf

启动

1

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

 

查看端口是否监听

netstat -lnt | grep 9000

 

编辑nginx配置文件

 

1

2

3

4

5

6

7

8

9

10

11

location ~ .*\.(php)?$

{

expires -1s;

try_files $uri =404;

fastcgi_split_path_info ^(.+\.php)(/.+)$;

include fastcgi_params;

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass 127.0.0.1:9000;

}

 

 

nginx重新加载配置

nginx -s reload

 

测试php访问

 

cd /usr/local/nginx/html/

vim aa.php

写入内容

1

2

3

<?php

echo "test 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服务器

1

2

3

4

cd zookeeper-3.4.5/conf

cp zoo_sample.cfg zoo.cfg

cd ../bin

./zkServer.sh start

 

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

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

1

2

3

4

[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用的

1

2

3

cd ../src/c

./configure --prefix=/usr/local/zookeeperlib

make && make install

 

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

1

2

3

--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

1

2

3

4

./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路径和文件名

1

2

3

4

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

 

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文件,可以用来测试

1

2

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

看是否能打印出如下结果

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

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

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template