[Gearman] centos上Gearman的安裝
时间:2021-07-14

一.介绍

Gearman安裝分2步,第1步是gearmand的安裝,第2步是gearman的PHP拓展的安裝。

第1步:

二.gearmand的安裝

1.最先安裝libdrizzle

#yum install libdrizzle libdrizzle-devel

2.安裝gearman(二种方式1.yum2.源代码包)。(c版的server)

1)yum安装

#rpm -ivh http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/epel-release-6-5.noarch.rpm

#yum install -y gearmand

2)源代码包安裝

#cd /opt/build/

#wget https://launchpad.net/gearmand/trunk/0.34/ download/gearmand-0.34.tar.gz

#tar zxf gearmand-0.34.tar.gz

#cd gearmand-0.34

#./configure

#make make install

3.运行gearman服务

1)yum安装方法

#/etc/init.d/gearmand start

2)源代码包安裝方法

#/opt/build/gearmand-0.34/sbin/gearmand -d


#gearmand -vvv -u root

INFO Starting up

INFO Listening on :::4730 (6)

INFO Creating wakeup pipe

INFO Creating IO thread wakeup pipe

INFO Adding event for listening socket (6)

INFO Adding event for wakeup pipe

INFO Entering main event loop

三.gearman的PHP拓展安裝

1.免费下载谷歌扩展程序:http://pecl.php.net/package/gearman

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

tar zxvf gearman-1….

cd gearman-1 …

phpize

./configure

假如提醒:configure: error: Please install libgearman

则安裝:libgearman-devel,指令:yuminstalllibgearman-devel


make make install

迅速就安裝进行,最终会展现so文件的途径,如:/usr/lib64/php/modules/

2.在php.ini结尾再加上extension=”/usr/lib64/php/modules/gearman.so”,重新启动apache,輸出php –info |grep “gearman”或是php -m或是网页页面輸出phpinfo()都能见到早已安裝取得成功。

疑难问题:configure时假如提醒找不着php-config,请特定。如–with-php-cOnfig=/usr/local/php/bin/php-config,留意要特定详细,不必只写文件目录。

四.gearman的运行和检测

1.gearmand -p 4730 -L 121.111.111.111 --log-file=/tmp/gearmand-4730.log --pid-file=/tmp/gearmand-4730.pid -d

2.Client:

$myParams = array();

$myParams['level'] = "warn";

$myParams['content'] = "it's a test";

$client= new GearmanClient();

//假如gearman 300ms内没反应,立即关掉联接

$client-setTimeout(300);

$client-addServer("121.111.111.111", "4730");

$client-doBackground("log", json_encode($myParams));

3.Server

$worker = new GearmanWorker();

$worker - addServer("112.111.111.111", "4730");

$worker - addFunction("log", "doLog");

while ($worker - work());

function doLog($job) {

global $logger, $logLevels, $myParams;

$myParams = NULL;


$myParams = json_decode($job - workload());

$level = $myParams-level;

if (!in_array($level,$logLevels)) $level = 'info';


$logger-$level($myParams-content);

}

参照:

http://www.cppblog.com/guojingjia2006/archive/2013/01/07/197076.html

http://www.xiaomlove.com/php安装gearman拓展完成多线程逐层式每日任务/

标签: centosgearmanpipe