gearman的安装和配置

gearman作为并发任务管理服务,已经越来越多攻城狮在生产环境中使用了。为了日后方便部署到服务器,我写了一个shell。

一般服务器使用稳定的centos,我使用的是centos6.7.

安装shell如下:

#!/bin/bash

# 安装相关依赖
yum install uuid-devel libuuid libuuid-devel uuid
boost-devel libevent libevent-devel boost boost-devel
gcc-c++ mysql-libs mysql libmemcached-devel libmemcached
make curl libcurl-devel mysql-devel gperf

cd /usr/local/src

# 安装gearmand服务
wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz
cd gearmand-1.1.12
./configure
make && make install

#启动Gearman服务端
/usr/local/sbin/gearmand -d -u root --log-file=/var/loggearmand.log
# 或用mysql做数据队列

# 安装gearman php扩展
wget http://pecl.php.net/get/gearman-1.1.1.tgz
tar -zxvf gearman-1.1.1.tgz
cd gearman-1.1.1
phpize
./configure
make && make install

# 添加配置到php.ini
echo 'extension = "/usr/lib64/php/modules/gearman.so"' >> /etc/php.ini

#检查组件是否安装成功


php -m | grep gearman

如果出现gearman该扩展,则说明安装成功。

补充一下:我在ubuntu上安装gearman php扩展时遇到无法加载gearman扩展的情况.报错如下:

PHP Warning: PHP Startup: gearman: Unable to initialize module

Module compiled with module API=20121212

PHP compiled with module API=20131226 These options need to match

bing了一下,国外也有人遇到如此情况。如:http://stackoverflow.com/questions/32062680/php-startup-gearman-unable-to-initialize-module

最后结果是不了了之。国内更多是转载也没有什么解决办法,不过如果是在ubuntu上安装此扩展,不要忘了apt-get方式。

首先我:

sudo apt-cache search php5-gearman

发现有这个扩展。

然后直接:

sudo apt-get install -y php5-gearman.

再次php -m | grep gearman,就可以看到扩展已经载入了。

Gearman,我们的目标是星辰大海!

原文地址:https://www.cnblogs.com/freephp/p/5266371.html