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

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM