Gearman安裝及使用

2021-09-06 16:20:55 字數 3587 閱讀 3098

基礎安裝包 

yum install vim wget gcc gcc-c++ make dos2unix gperf libevent libevent-devel zlib-devel bzip2-devel openssl-devel ncurses-devel    boost boost-devel mysql-devel  

安裝gearman 非同步佇列

# wget   

# tar -zxvf gearmand-1.1.9.tar.gz  

# cd gearmand-1.1.9  

# ./configure   如果出現錯誤請檢視下面的錯誤解決  

成功後如下 

* libs:                        

* ldflags flags:               

* assertions enabled:        no  

* debug enabled:             no  

* warnings as failure:       no  

* building with libsqlite3   no  

* building with libdrizzle   no  

* building with libmemcached not found  

* building with libpq        no  

* building with tokyocabinet no  

* building with libmysql     yes  

* ssl enabled:               no  

* make -j:                   3  

* vcs checkout:              no  

#  make  

#  make install  

安裝gearman php 擴充套件

# wget   

# mv gearman gearman.tar.gz  

# tar -zxvf gearman.tar.gz  

# cd gearman-1.1.2/  

# phpize  

# ./configure  

# make  

# make install  

# cd /etc/php.d/  

# cp gd.ini gearman.ini  

# vim gearman.ini  

; enable gearman extension module  

extension=gearman.so  

# service php-fpm restart  

錯誤解決

在configure過程中出現了以下錯誤: 

checking for boost headers version >= 1.39.0… no  

configure: error: cannot find boost headers version >= 1.39.0  

解決辦法: 

# yum search boost  

# yum install boost.x86_64  

# yum install boost-devel.x86_64  

繼續執行./configure出現以下錯誤 

checking for gperf... no  

configure: error: could not find gperf  

解決辦法: 

#yum search gperf  

#yum install gperf.x86_64  

繼續執行./configure出現以下錯誤 

checking test for a working libevent... no  

configure: error: unable to find libevent  

解決辦法: 

# yum install libevent libevent-devel  

gearman 引數說明

client mode: gearman [options]   

worker mode: gearman -w [options] [[...]]  

common options to both client and worker modes.  

-f - function name to use for jobs (can give many)  

-h - job server host  

-h            - print this help menu  

-v            - print diagnostic information to stdout(false)  

-p - job server port  

-t - timeout in milliseconds  

-i - create a pidfile for the process  

client options:  

-b            - run jobs in the background(false)  

-i            - run jobs as high priority  

-l            - run jobs as low priority  

-n            - run one job per line(false)  

-n            - same as -n, but strip off the newline(false)  

-p            - prefix all output lines with functions names  

-s            - send job without reading from standard input  

-u - unique key to use for job  

worker options:  

-c - number of jobs for worker to run before exiting  

-n            - send data packet for each line(false)  

-n            - same as -n, but strip off the newline(false)  

-w            - run in worker mode(false)   

gearman非同步佇列使用:

下面先做個命令列測試:

首先開兩個命令列視窗:

tty1:

# gearman -w -f abc  -- wc  -m  

表示統計使用者輸入了多少個字元。

tty2:

# gearman -f abc 'aaaa'   4

輸出結果正確。

# gearman -f abc < /etc/php.ini  

當然也可以直接從檔案中讀入內容。

Gearman 使用小知識

眾所周知,php要實現非同步任務一般都是通過gearmanbeanstalkd等第三方來實現的。目前專案採用的是gearman來實現非同步任務。通俗的來說 gearman是乙個分發任務的程式框架,使用gearman的應用通常有三部分組成 乙個client 乙個worker 乙個 任務伺服器。clie...

gearman 從安裝到python API測試

一 安裝 作業系統 redhat 5.7 1.安裝gearman 首先,我們需要安裝gearmand,在centos和rhel環境下,我們只需執行以下命令 yum install gearmand y 注意 如果不希望通過yum的方式來安裝gearmand,可以通過原始碼編譯安裝,具體安裝方法可以參...

Gearman安裝與使用,分布式訊息佇列

1 介紹 gearman是乙個用來把工作委派給其他機器 分布式的呼叫更適合做某項工作的機器 併發的做某項工作在多個呼叫間做負載均衡 或用來在呼叫其它語言的函式的系統。2 組成 3執行過程 4 gearmand安裝 5 gearmand使用 5.1建立worker worker new gearman...