gearmand

gearmand的简单介绍:(任务分发器
PHP 的 Gearman 库能把工作分发给一组机器。Gearman 会对作业进行排队并少量分派作业,而将那些复杂的任务分发给为此任务预留的机器。这个库对 Perl、Ruby、C、Python 及 PHP 开发人员均可用,并且还可以运行于任何类似 UNIX® 的平台上,包括 Mac OS X、 Linux® 和 Sun Solaris。

Gearman是一个用来把工作委派给其他机器、分布式的调用更适合做某项工作的机器、并发的做某项工作在多个调用间做负载均衡、或用来在调用其它语言的函数的系统。

简单示意图:

client:任务发起者

job:任务分配者

worker:任务处理者

支持 mysql,pq,sqlit,brizzle,memcachedb做持久化存储

可开启多个进程,支持failover(自动故障转移)

都可以有多个

 

1.安装依赖包:

yum install -y boost boost-devel gcc gcc44 gcc-c++ libevent libevent-devel uuid-c++ uuid-c++-devel uuid-php uuid-dce-devel uuid-dce

2.安装e2fsprogs (必须用源码安装,yum安装的不好使)

     tar zxvf e2fsprogs-1.41.14.tar.gz 

    cd e2fsprogs-1.41.14

    ./configure –enable-elf-shlibs

    make

    make install

    cp -r lib/uuid/ /usr/include/

    cp -rf lib/libuuid.so* /usr/lib

3. 安装gearmand

    tar zxvf gearmand-0.33.tar.gz

    cd gearmand-0.33

    ./configure –with-debug

    make

    make install

    mkdir -p /usr/local/var/log/
---//配置信息
Configuration summary for gearmand version 0.33

   * Installation prefix:       /usr/local
   * System type:               pc-linux-gnu
   * Host CPU:                  i686
   * C Compiler:                gcc (GCC) 4.4.6 20120305 (Red Hat 4.4.6-4)
   * Assertions enabled:        yes
   * Debug enabled:             yes
   * Warnings as failure:       no
   * Building with libsqlite3   no
   * Building with libdrizzle   no
   * Building with libmemcached no
   * Building with libpq        no
   * Building with tokyocabinet yes
   * Building with libmysql     yes

---

 


安装遇到的错误:

1.cc1plus: warnings being treated as errors
出现这问题的原因是-Werror这个gcc编译选项。
只要在makefile中找到包含这个-Werror选项的句子,将-Werror删除,或是注释掉就行了~会不会有什么问题还不清楚,至少可以编译通过~~~听说在cygwin环境下编译不会出错的!

2.无效的符号连接

ldconfig查看是哪个连接有问题,我删除了,不在报错了,后来就成功了

3.fatal error: uuid/uuid.h: No such file or directory

这是因为没有uuid库和头文件,需要安装e2fsprogs

 

参考文章:

http://blog.csdn.net/aidenliu/article/details/7406390

http://www.ibm.com/developerworks/cn/opensource/os-php-gearman/

http://www.cnblogs.com/cocowool/archive/2011/08/18/2145144.html

http://www.ywjt.org/index/archives/472.html

 

 安装:

1. 安装依赖库

yum install -y boost boost-devel gcc gcc44 gcc-c++ libevent libevent-devel uuid-c++ uuid-c++-devel uuid-php uuid-dce-devel uuid-dce

2. 安装e2fsprogs

 tar zxvf e2fsprogs-1.41.14.tar.gz

cd e2fsprogs-1.41.14

./configure –enable-elf-shlibs

make

make install

cp -r lib/uuid/ /usr/include/

cp -rf lib/libuuid.so* /usr/lib

3. 安装gearmand

tar zxvf gearmand-0.33.tar.gz

cd gearmand-0.33

./configure –with-debug

make

make install

mkdir -p /usr/local/var/log/

#安装gearman扩展

tar zxvf gearman-0.8.0.tgz

cd gearman-0.8.0

/usr/local/php/bin/phpize

./configure –with-php-config=/usr/local/php/bin/php-config

make

make install

4. 修改php.ini文件,增加 extension = “gearman.so”

sed -i ‘/^extension_dir/a extension = \”gearman.so\”‘ /usr/local/php/etc/php.ini

/usr/local/php/sbin/php-fpm reload

5. 启动Job Server 进程

gearmand -L 192.168.30.180 -p 4730 -u root -d

 

测试代码:

 

<?php

# Client code

echo "Starting\n";

# Create our client object.
$gmclient= new GearmanClient();

# Add default server (localhost).
$gmclient->addServer('127.0.0.1',4730);

echo "Sending job\n";

$result = $gmclient->do("reverse", "Hello!");

echo "Success: $result\n";

?> 

 

<?php

echo "Starting\n";

# Create our worker object.
$gmworker= new GearmanWorker();

# Add default server (localhost).
$gmworker->addServer('127.0.0.1',4730);

# Register function "reverse" with the server. Change the worker function to
# "reverse_fn_fast" for a faster worker with no output.
$gmworker->addFunction("reverse", "reverse_fn");

print "Waiting for job...\n";
while($gmworker->work())
{
  if ($gmworker->returnCode() != GEARMAN_SUCCESS)
  {
    echo "return_code: " . $gmworker->returnCode() . "\n";
    break;
  }
}

function reverse_fn($job)
{
  echo strrev($job->workload());
  return strrev($job->workload());
}

?> 

 

监控工具:

Gearman-Monitor on GitHub

把Net_Gearman-0.2.3.tgz的net目录放到上面的根目录下 即可

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值