一、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
- 下载地址:https://launchpad.net/gearmand/
- wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz
- tar zxf gearmand-1.1.12.tar.gz
- cd gearmand-1.1.12
- ./configure --with-boost=/usr/local/boost --with-boost-libdir=/usr/local/boost/lib
- make && make install
二、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
三、启动gearman
- gearman -d
四、测试
//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/
来源:oschina
链接:https://my.oschina.net/u/147056/blog/755299