linux php安装zookeeper扩展
linux php安装zookeeper扩展
tags:php zookeeper linux ext
前言:
zookeeper提供很犀利的命名服务,并且集群操作具有原子性,所以在我的多个项目中被采用。
在原项目总,服务器集群的状态统一上报到zookeeper集群中,然后通过客户端来访问zookeeper,实时观察集群的状态(当然了,你要做成配置同步也可以)。但是客户端跨平台不方便,开发一个手机客户端又太egg pain了,所以打算采用PHP来读取zookeeper中。
以下是安装php的zookeeper扩展的步骤。多次使用,如有问题请反馈。转载请注明出处。
环境:
|
1
2
3
4
5
|
centos : 6.4 zookeeper : 3.4.5 php : 5.5.10 nginx : 1.5php 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.inicp /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
|
<?phpecho "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/confcp zoo_sample.cfg zoo.cfgcd ../bin./zkServer.sh start |
这里最好确认一下是否期待成功,./zkServer.sh status
我这里是单台,所以结果为:
|
1
2
3
4
|
[root@localhost bin]# ./zkServer.sh statusJMX enabled by defaultUsing config: /root/zookeeper-3.4.5/bin/../conf/zoo.cfgMode: standalone |
编译zookeeper库,给php用的
|
1
2
3
|
cd ../src/c./configure --prefix=/usr/local/zookeeperlibmake && 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.iniextension_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"}NULLstring(3) "abc"array(2) { [0]=> string(7) "test123" [1]=> string(9) "zookeeper"}NULLNULLarray(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
linux php安装zookeeper扩展的更多相关文章
- linux下安装opcache扩展
linux下安装opcache扩展 参考:http://www.php.net/manual/zh/opcache.installation.php 1 2 3 4 5 6 7 wget http ...
- Linux上安装Zookeeper以及一些注意事项
最近打算出一个系列,介绍Dubbo的使用. 分布式应用现在已经越来越广泛,Spring Could也是一个不错的一站式解决方案,不过据我了解国内目前貌似使用阿里Dubbo的公司比较多,一方面这个框架也 ...
- 总结 Linux 下安装 PHP 扩展步骤
总结一下 Linux 下安装 PHP 扩展步骤,这里以安装 PHP 的 redis 扩展为例. 一.拿到扩展包下载地址,下载扩展包 pecl 上搜索 redis wget http://pecl.ph ...
- Linux下安装Zookeeper
Zookeeper是一个协调服务,可以用它来作为配置维护.名字服务.分布式部署: 下面,我来分享一下在Linux下安装Zookeeper的整个步骤,让大家少走弯路. 一.Zookeeper下载 [ro ...
- linux 下安装php扩展
linux下安装php扩展 步骤: 1.在扩展解压包目录执行 phpize 2.执行 ./configure --with-php-config=/usr/local/php/bin/php-conf ...
- Linux php安装zip扩展
Linux php安装zip扩展 2018.07.22 22:40 1165浏览 #wget http://pecl.php.net/get/zip-1.12.4.tgz #tar zxfv zi ...
- Linux上安装ZooKeeper并设置开机启动(CentOS7+ZooKeeper3.4.10)
1下载Zookeeper 2安装启动测试 2.1上载压缩文件并解压 2.2新建 zookeeper配置文件 2.3安装JDK 2.4启动zookeeper 2.5查看zookeeper的状态 3将Zo ...
- linux centos7 安装zookeeper
linux 系统下 zookeeper 安装教程 1.下载安装包 1)进入安装目录 cd /home/install/ 2)下载 wget http://mirror.bit.edu.cn/apach ...
- php win/linux/mac 安装redis扩展或者扩展报错 zend_smart_str.h file not found
1 windows 安装reids 扩展 根据phpinfo 查看php信息.在pecl.php.net 下载对应的redis扩展版本,放如扩展目录,在php.ini 配置扩展信息,重启服务 2 li ...
随机推荐
- 学习资料 50个常用的sql语句
Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师表 问题 ...
- 关于oracle中传过来的一个多id需要插入到数据库用,分格的存储过程
create or replace procedure test ( jf_Id in nvarchar2, yf_id in nvarchar2 ) as v_length NUMBER := LE ...
- C++中“强制转换”的四大天王
哈哈,这个标题有点搞笑了!笑一笑,十年少,希望大家都嗨心! 在C++中主要有四种强制类型转换:static_cast,reinterpret_cast,const_cast,dynamic_cast. ...
- php xml 互相转换
正好昨天才做过类似的需求……几行代码就可以搞定. 如果你使用 curl 获取的 xml data$xml = simplexml_load_string($data);$data['tk'] = js ...
- CentOS 6.x 播放 mp3 音乐 —— 成功
参考:http://blog.chinaunix.net/uid-14735472-id-3472898.html centos 6.x 添加 rpmforge 源--- CentOS 6.x 安装 ...
- 0329 复利计算器5.0 Juint单元测试 组员 254列志华 253韩麒麟
一.主要功能与需求分析 1.本金为100万,利率或者投资回报率为3%,投资年限为30年,那么,30年后所获得的利息收入:按复利计算公式来计算就是:1,000,000×(1+3%)^30 2.如果按照单 ...
- 搭建高性能计算环境(十)、应用软件的安装之Wien2k
1,首先安装fftw .tar.gz cd fftw- ./configure --prefix=/opt/fftw- --enable-shared --enable-float --enable- ...
- ThinkPHP5中Session的使用
由于用惯了ThinkPHP之前的版本,一想到要用Session就直接用$_SESSION来存取,今天看了ThinkPHP5的手册,才发现原来这么用时不安全滴.ThinKPHP5对Session进行了封 ...
- hadoop-2.7.1基于QMJ高可用安装配置
1.修改主机名及hosts文件 10.205.22.185 nn1 (主)作用namenode,resourcemanager,datanode,JournalNode,zk,zkfc(hive,sq ...
- PHP判断用户所在国家并跳转对应的目录
<?php // 淘宝API查询国家代码 $url = "http://ip.taobao.com/service/getIpInfo.php?ip=".get_client ...