wdlinux centos 7 gearman安裝

1、GearMan環境安裝

  • 依賴環境:yum install -y boost-devel gperf libevent-devel libuuid-devel
  • 若是boost版本過低,則要本身編譯安裝
//注意:wdlinux centos 5.11 驗證的版本
//ICU4C :icu4c-56_1-src.zip
//Boost:boost_1_50_0.tar.gz

//安裝ICU4C 
wget http://downloads.sourceforge.net/project/icu/ICU4C/4.0/icu4c-4_0-src.tgz?use_mirror=cdnetworks-kr-2
tar zxvf icu4c-4_0-src.tgz
cd icu/source
./configure –prefix=/usr
make
make install
ldconfig

//安裝Boost 
wget http://sourceforge.net/projects/boost/files/boost/1.43.0/boost_1_43_0.tar.gz/download
tar zxvf boost_1_43_0.tar.gz
cd boost_1_43_0
rm -rf /usr/include/boost/
rm -rf /usr/lib/libboost*
./bootstrap.sh -prefix=/usr/local/boost
./b2
編譯大概半小時,完成後:
./b2 install

2、PHP拓展環境安裝

  • 下載列表:http://pecl.php.net/package/gearman
  • wget http://pecl.php.net/get/gearman-1.1.2.tgz
  • tar zxf gearman-1.1.2.tgz
  • cd gearman-1.1.2
  • /www/wdlinux/php/bin/phpize
  • ./configure --with-php-config=/www/wdlinux/php/bin/php-config
  • make
  • cp ./modules/gearman.so /www/wdlinux/php/lib/php/extensions/no-debug-non-zts-20131226/
  • vim /www/wdlinux/php/etc/php.ini 在文件最後添加 :extension=gearman.so
  • 重啓PHP服務
  • 查看狀態:/www/wdlinux/php/bin/php --info |grep gearman

3、啓動gearman

  • gearman -d

4、測試

//worker.php
<?php
$worker= new GearmanWorker();
$worker->addServer();
$worker->addFunction("reverse", "my_reverse_function");
while ($worker->work());

function my_reverse_function($job)
{
  return strrev($job->workload());
}
?>
  • php worker.php
//client.php
<?php
$client= new GearmanClient();
$client->addServer();
print $client->do("reverse", "Hello World!");
?>

錯誤集:

在編譯過程會遇到如下幾種錯誤,是因爲你的系統默認缺乏這依賴類庫。
報錯一:
checking for boostlib >= 1.39… configure: We could not detect the boost libraries (version 1.39 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to –with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.
configure: error: could not find boost
解決方法
yum install boost-devel


報錯二:
configure: error: could not find gperf
解決方法
yum install gperf


報錯三:
configure: error: Unable to find libevent
解決方法
yum install libevent-devel


報錯四:
configure: error: Unable to find libuuid
解決方法
yum install libuuid-devel

你可使用如下一條命令涵蓋以前的4條命令:
yum install -y boost-devel gperf libevent-devel libuuid-devel
以上命令會一次性安裝完全部的依賴類庫。


報錯五:
gearmand: Could not open log file "/usr/local/var/log/gearmand.log", from ......
解決方法
mkdir -p /usr/local/var/log/
cd /usr/local/var/log/
touch gearmand.log


報錯六:
./libgearman-1.0/gearman.h:53:23: error: cinttypes: No such file or directory
make[1]: *** [libgearman/libgearman_libgearman_la-check.lo] 錯誤 1
make[1]: Leaving directory `/root/gearmand-1.1.12'
make: *** [all] 錯誤 2
解決辦法:
命令:
yum install gcc44 gcc44-c++ libstdc++44-devel -y
而後在環境變量里加入:
export CC=/usr/bin/gcc44 or export CC=/usr/bin/gcc
export CXX=/usr/bin/g++44
保存退出後執行:
source /etc/profile
刪除gearmand-0.34文件夾從新進行編譯.
從新進行編譯後執行make這步......
在後面有詳細的說明,能夠不source直接設置環境變量,由於編譯後也不必定要這個版本的gcc的。


報錯七:
完成後,執行 gearmand -d
gearmand: error while loading shared libraries: libboost_program_options.so.1.50.0: cannot open shared object file: No such file or directory
解決辦法:
vim /etc/ld.so.conf
加上路徑:/usr/local/boost/lib
ldconfig

報錯八:
若是安裝成功,啓動worker時報以下錯誤,頗有多是gearmand 沒有啓動起來。
GearmanWorker fails with 'Failed to set exception option'
gearmand -d或者gearmand -d -u root都啓動不起來。gearmand -vvv調試模式卻提示未定義選項-v。這時應該是觸發gearmand新版本的bug了,查看log應該能看到「000000 [  main ] socket()(Address family not supported by protocol) -> libgearman-server/gearmand.cc:470」這個錯誤,解決辦法是啓動時添加參數-L 0.0.0.0,限定只綁定ipv4地址,忽略ipv6。或者安裝不高於1.0.2的版本。
參見官方反饋帖子:https://bugs.launchpad.net/gearmand/+bug/1134534
參考連接:http://www.usamurai.com/2013/05/01/install-gearman-from-source-in-centos/
相關文章
相關標籤/搜索