安装
[bash]
# CXX=/usr/bin/g++44 CC=/usr/bin/gcc44 ./configure --prefix=/usr/local/gearman --enable-static-boost --with-mysql=/usr/local/mysql/bin/mysql_config
# make
# make install
[/bash]
安装 PHP 扩展
[bash]
[root@localdomain gearman-1.0.2]# /usr/local/php/bin/phpize
[root@localdomain gearman-1.0.2]# ./configure --with-php-config=/usr/local/php/bin/php-config --with-gearman=/usr/local/gearman/
[root@localdomain gearman-1.0.2]# make
[root@localdomain gearman-1.0.2]# make install
[/bash]
完后,修改 PHP 配置文件, 加入 gearman.so 扩展,重启 PHP,执行命令
php -i | grep gearman,若看到如下类似的信息,说明安装成功。[bash]
[root@localdomain php]# bin/php -i | grep gearman
gearman
gearman support => enabled
libgearman version => 0.38
PWD => /usr/local/src/gearman-1.0.2
_SERVER["PWD"] => /usr/local/src/gearman-1.0.2
[/bash]
用 MySQL 做持久化存储,启动服务
- 在 MySQL 服务器中建立数据库和表结构:
[sql]
CREATE TABLE `gearman_queue` (
`unique_key` varchar(64) NOT NULL,
`function_name` varchar(255) DEFAULT NULL,
`priority` int(11) DEFAULT NULL,
`data` longblob,
`when_to_run` int(11) DEFAULT NULL,
PRIMARY KEY (`unique_key`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
[/sql]
Gearman 的 MySQL 持久化储存,默认表名是gearman_queue,这可在服务启动时根据需要进行设置。另外,表结构设置如存储引擎可根据效率等进行修改。
- 启动服务
[bash]
[root@localdomain gearman]# /usr/local/gearman/sbin/gearmand -p 4730 --log-file=/tmp/gearmand-4730.log --pid-file=/tmp/gearmand-4730.pid -q MySQL --mysql-host=localhost --mysql-user=gearmand --mysql-password=123456 --mysql-db=gearman --verbose DEBUG -d
[/bash]
若上一步中建立的数据库表,其表名不是gearman_queue,用参数--mysql-table=TABLE_NAME进行指定即可。
命令行工具
- 启动 Worker
bin/gearman -w -f wc -- wc -l & - 运行 Client
bin/gearman -f wc < /tmp/gearmand-4730.log - 查看 Server 状态
bin/gearadmin -h [ --host ] -p [--port] --status - 查看 Server 运行中的 workers
bin/gearadmin -h [ --host ] -p [--port] --workers - 关闭 Server
bin/gearadmin -h [ --host ] -p [--port] --shutdown - 移除名为 FUNCTION_NAME 的 JOB
bin/gearman -n -w -f FUNCTION_NAME > /dev/null - 移除 20 个名为 FUNCTION_NAME 的 JOB
gearman -c 20 -n -w -f FUNCTION_NAME > /dev/null
安装常见问题
- 编译时,报错:configure: error: cannot find Boost headers version >= 1.39.0
[bash]
[root@localdomain gearmand-0.38]# yum search boost
[root@localdomain gearmand-0.38]# yum install boost.x86_64
[root@localdomain gearmand-0.38]# yum install yum install boost-devel.x86_64
[/bash] - uuid/uuid.h;No such file or directory
错误代码:
[bash]
[root@localdomain gearmand-0.38]# make
make all-am
make[1]: Entering directory `/usr/local/src/gearmand-0.38'
CXX libgearman/libgearman_libgearman_la-add.lo
libgearman/add.cc:53:23: error: uuid/uuid.h: No such file or directory
libgearman/add.cc: In function 'gearman_task_st* add_task(gearman_client_st&, gearman_task_st*, void*, gearman_command_t, const gearman_string_t&, gearman_unique_t&, const gearman_string_t&, time_t, const gearman_actions_t&)':
libgearman/add.cc:154: error: 'uuid_t' was not declared in this scope
libgearman/add.cc:154: error: expected ';' before 'uuid'
libgearman/add.cc:155: error: 'uuid' was not declared in this scope
libgearman/add.cc:155: error: 'uuid_generate' was not declared in this scope
libgearman/add.cc:156: error: 'uuid_unparse' was not declared in this scope
libgearman/add.cc: In function 'gearman_task_st* add_reducer_task(gearman_client_st*, gearman_command_t, gearman_job_priority_t, const gearman_string_t&, const gearman_string_t&, const gearman_unique_t&, const gearman_string_t&, const gearman_actions_t&, time_t, void*)':
libgearman/add.cc:263: error: 'uuid_t' was not declared in this scope
libgearman/add.cc:263: error: expected ';' before 'uuid'
libgearman/add.cc:334: error: 'uuid' was not declared in this scope
libgearman/add.cc:334: error: 'uuid_generate' was not declared in this scope
libgearman/add.cc:335: error: 'uuid_unparse' was not declared in this scope
make[1]: *** [libgearman/libgearman_libgearman_la-add.lo] Error 1
make[1]: Leaving directory `/usr/local/src/gearmand-0.34'
make: *** [all] Error 2
[/bash]
yum 解决如下,或者源代码安装,参考 uuid/uuid.h;No such file or directory 。
[bash]
[root@localdomain gearmand-0.38]# yum install e4fsprogs.x86_64
[root@localdomain gearmand-0.38]# yum install e2fsprogs-devel.x86_64
[/bash] - configure: error: Unable to find libevent
[bash]
[root@localdomain gearmand-0.38]# yum install libevent.x86_64
[root@localdomain gearmand-0.38]# yum install libevent-devel.x86_64
[/bash] - tr1/cinttypes: No such file or directory
错误代码:
[bash gutter="false"]
make[1]: Entering directory `/usr/local/src/gearmand-0.38'
CXX libgearman/libgearman_libgearman_la-actions.lo
In file included from ./libgearman/common.h:44,
from libgearman/actions.cc:39:
./libgearman-1.0/gearman.h:53:27: error: tr1/cinttypes: No such file or directory
make[1]: *** [libgearman/libgearman_libgearman_la-actions.lo] Error 1
make[1]: Leaving directory `/usr/local/src/gearmand-0.38'
[/bash]
解决:
[bash]
[root@localdomain gearmand-0.38]# yum install gcc44 gcc44-c++
[/bash] - 用 MySQL 做 Gearman Server 的持久化存储,
make install时始终无法通过。最后直接将libgearman-server/plugins/queue/mysql/queue.cc文件中 include MySQL 库文件的位置改为绝对路径才算解决这个问题。 - Trouble compiling gearman 0.22 with drizzle persistence on Centos 5.6
- ./configure doesn't fail for lack of c++
- compiling gearmand tr1/cinttypes in cent os
[bash]
#include </usr/local/mysql/include/mysql/mysql.h>
#include </usr/local/mysql/include/mysql/errmsg.h>
[/bash]
说明:
- 版本说明: gearmand 0.38 , libgearman
- 系统为 64 位,所以之上的软件都是安装 64 位的版本,若系统不是 64 位的,修改对应的版本即是。
- 用 yum 安装,可能会收到找不到对应源的错误,或无对应需要的版本。在
/etc/yum.repos.d/drizzle.repo文件中加入如下,重新执行命令即可。
[bash gutter="false"]
[drizzle]
name=drizzle
baseurl=http://rpm.drizzle.org/7-dev/redhat/$releasever/$basearch/
enabled=1
gpgcheck=0
[drizzle-src]
name=drizzle-src
baseurl=http://rpm.drizzle.org/7-dev/redhat/$releasever/source
enabled=1
gpgcheck=0
[drizzle-dev]
name=drizzle-dev
baseurl=http://rpm.drizzle.org/7-dev/redhat/5/$basearch/
enabled=0
gpgcheck=0
[/bash]
没有评论 :
发表评论