C语言 c++ php mysql nginx linux lnmp lamp lanmp memcache redis 面试 笔记 ppt 设计模式 问题 远程连接

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目录放到上面的根目录下 即可

 

 

 

 

posted on 2012-09-28 01:20  思齐_  阅读(3283)  评论(0编辑  收藏  举报