首頁  >  文章  >  後端開發  >  怎麼安裝php zookeeper擴充

怎麼安裝php zookeeper擴充

青灯夜游
青灯夜游原創
2021-09-27 20:04:492139瀏覽

安裝方法:1、安裝並啟動zookeeper伺服器;2、下載zookeeper擴展,並解壓縮到PHP安裝目錄的ext目錄下;3、在php安裝目錄下,執行指令產生configure和makefile;4 、使用make指令編譯安裝即可。

怎麼安裝php zookeeper擴充

本教學操作環境: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影片教學

以上是怎麼安裝php zookeeper擴充的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn