ubuntu下gearman安装

本文详细介绍如何在Linux环境下安装Gearman Job Server及其PHP扩展,包括解决安装过程中遇到的各种依赖问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sudo apt-get update

wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz

tar zxvf gearmand-1.1.12.tar.gz

cd gearmand-1.1.12/

./configure

configure: error: could not find boost

sudo apt-get install libboost-dev

现在好像都需要boost,所以执行

./configure

configure: error: Could not find a version of the library!

sudo apt-get install libboost-all-dev

接着

./configure

configure: error: could not find gperf

sudo apt-get install gperf*

接着

./configure

configure: error: Unable to find libevent

sudo apt-get install libevent-dev

接着

./configure

configure: error: Unable to find libuuid

安装libuuid,这里不能通过 sudo apt-get install 来安装了,找不到,通过下面方式安装

wget http://nchc.dl.sourceforge.net/project/libuuid/libuuid-1.0.3.tar.gz

sudo tar zxvf libuuid-1.0.3.tar.gz

cd libuuid-1.0.3/

./configure

没有错误的情况下继续

sudo make

sudo make install

一般没多少错误了,需要等会(可能上面执行配置的时候结果未清理,如需要执行):
:sudo make clean

重新安装

./configure

sudo make

sudo make install

貌似没有错误,继续

gearman

第一次运行会看到以下提示:

gearman: error while loading shared libraries: libgearman.so.8: cannot open shared object file: No such file or directory

(这表示系统不知道libgearman.so.8放在哪个目录下。要在/etc/ld.so.conf中加入libgearman.so.8所在的目录。检查了下,文件所在目录为/usr/local/lib。因此出现这个问题的原因是libgearman.so.8刚生成,没有加入到ld.so.cache中,所以这时需要重新运行一下/sbin/ldconfig( ldconfig命令的作用):)

sudo /sbin/ldconfig

此时再执行 gearman 则已安装成功!

安装完Job Server之后,用gearmand –d命令启动

gearmand -d

第一次运行会看到以下提示:

gearmand: Could not open log file “/usr/local/var/log/gearmand.log”, from “/home/wangyulu/下载/gearmand-1.1.12”, switching to stderr. (No such file or directory)

在提示的目录下创建好/log/gearmand.log文件,再次执行上述命令,就正常启动了job server。

sudo gearmand -d

到这里就已经完全ok了

安装php Gearman扩展

wget http://pecl.php.net/get/gearman-1.1.2.tgz

sudo tar zxvf gearman-1.1.2.tgz

cd gearman-1.1.2/

sudo phpize (这里可能会提示没有此命令,执行 sudo apt-get install php5-dev 安装)

sudo ./configure

sudo make

sudo make install

sudo echo "extension=gearman.so" >> /usr/local/php/etc/php.ini (php.ini的具体位置)

再重启php-fpm

client:

<?php
  $client= new GearmanClient();
  $client->addServer('127.0.0.1', 4730);
  echo $client->do('reverse', 'Hello World!'), "n";
?>

server:

<?php
    $worker= new GearmanWorker();
    $worker->addServer('127.0.0.1', 4730);
    $worker->addFunction('reverse', 'my_reverse_function');

    while ($worker->work());

    function my_reverse_function($job)
    {
        return strrev($job->workload());
    }
?> 

CentOS版请参考这位大哥博客文章http://blog.youkuaiyun.com/21aspnet/article/details/6617985

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值