- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章gearman + mysql方式实现持久化操作示例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例讲述了gearman+mysql方式实现持久化操作。分享给大家供大家参考,具体如下:
1、为什么要持久化?
gearman的job server中的工作队列存储在内存中,一旦服务器有未处理的任务时重启或者宕机,那么这些任务就会丢失。 持久化存储队列可以允许添加后台任务,并将其存储在外部的持久型队列里(比如MySQL数据库).
2、关于gearman的持久化的文章,建议可以看官方文档 。
1
|
http://gearman.org/manual/job_server/#persistent_queues
|
3、创建用于持久化的数据库和表 。
1
2
3
4
5
6
7
8
9
10
|
CREATE
DATABASE
gearman;
CREATE
TABLE
`gearman_queue` (
`unique_key`
varchar
(64)
NOT
NULL
,
`function_name`
varchar
(255)
NOT
NULL
,
`priority`
int
(11)
NOT
NULL
,
`data` longblob
NOT
NULL
,
`when_to_run`
int
(11),
PRIMARY
KEY
(`unique_key`)
) ENGINE=InnoDB
DEFAULT
CHARSET=utf8;
|
4、创建gearman用户 。
1
2
3
|
>
create
user
'gearman'
@
'%'
IDENTIFIED
BY
'123456'
;
>
grant
all
on
gearman.*
TO
'gearman'
@
'%'
;
> flush
privileges
;
|
5、启动gearmand时指定持久化参数 。
1
2
3
4
5
6
7
8
|
> gearmand -q libdrizzle \
--libdrizzle-host=192.168.1.100 \
--libdrizzle-port=3306 \
--libdrizzle-user=gearman \
--libdrizzle-password=123456 \
--libdrizzle-db=gearman \
--libdrizzle-table=gearman_queue \
--libdrizzle-mysql
|
或者使用如下 。
1
2
3
4
5
6
7
|
> gearmand -q mysql \
--mysql-host=192.168.1.100 \
--mysql-port=3306 \
--mysql-user=gearman \
--mysql-password=123456 \
--mysql-db=gearman \
--mysql-table=gearman_queue
|
如果出现如下问题,说明你在编译安装gearman时没有把libdrizzle装上 。
1
|
gearmand: unrecognised
option
'--libdrizzle-host=192.168.1.100'
|
在如下网址,下载libdrizzle 。
1
|
https://launchpad.net/libdrizzle/+download
|
如:libdrizzle-5.1.4.tar.gz 。
安装libdrizzle 。
1
2
|
>
tar
xf libdrizzle-5.1.4.
tar
.gz
>
cd
libdrizzle-5.1.4
|
这里最好不要指定--prefix,因为你指定了其它目录,下面gearman编译时可能会找不到相关头文件和链接库,需要你手动添加软链接 。
1
2
|
> .
/configure
>
make
&&
make
install
|
然后我们重新编译安装gearman 。
1
2
|
>
tar
xf gearmand-1.1.12.
tar
.gz
>
cd
gearmand-1.1.12
|
如果configure的有哪些参数不清楚,可以用下面命令查看 。
1
|
> .
/configure
--help
|
这里需要安装mysql-devel,以便gearman支持mysql的持久化 。
1
|
> yum
install
mysql-server mysql-devel
|
因为我早先装过gearman,没有指定--prefix,所以这里也没有指定,有需要的可以自行指定 。
1
2
|
> .
/configure
>
make
&&
make
install
|
configure完成最后显示的一段信息 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
* LIBS:
* LDFLAGS Flags:
* Assertions enabled: no
* Debug enabled: no
* Warnings as failure: no
* Building with libsqlite3 no
* Building with libdrizzle
yes
* Building with libmemcached not found
* Building with libpq no
* Building with tokyocabinet no
* Building with libmysql
yes
* SSL enabled: no
* cyassl found: no
* openssl found:
yes
*
make
-j: 2
* VCS checkout: no
* sphinx-build: :
|
最后可以看到libdrizzle和libmysql那地方显示yes 。
查看是否安装上 。
1
|
> gearmand --help
|
如果出现如下错误 。
gearmand: error while loading shared libraries: libdrizzle.so.9: cannot open shared object file: No such file or directory 。
请打开修改/etc/ld.so.conf 。
1
|
>
vi
/etc/ld
.so.conf
|
加入如下一句话 。
1
|
/usr/local/lib
|
运行ldconfig 。
1
|
> ldconfig
|
再次运行上面的gearmand --help,如果出现如下信息,则安装成功 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
builtin
:
libdrizzle:
--libdrizzle-host arg (=localhost) Host of server.
--libdrizzle-port arg (=3306) Port of server. (by default Drizzle)
--libdrizzle-uds arg Unix domain socket
for
server.
--libdrizzle-user arg (=root) User name
for
authentication.
--libdrizzle-password arg Password
for
authentication.
--libdrizzle-db arg (=gearman) Database to use.
--libdrizzle-table arg (=queue) Table to use.
--libdrizzle-mysql Use MySQL protocol.
MySQL:
--mysql-host arg (=localhost) MySQL host.
--mysql-port arg (=3306) Port of server. (by default 3306)
--mysql-user arg MySQL user.
--mysql-password arg MySQL user password.
--mysql-db arg MySQL database.
--mysql-table arg (=gearman_queue) MySQL table name.
|
通过libdrizzle启动gearmand如果出现如下问题 。
1
|
gearmand: Error
while
initializing the queue : libdrizzle
|
并且日志里面的记录是这样的 。
1
2
|
ERROR 2017-02-22 07:51:02.536574 [ main ] Failed to initialize libdrizzle:
initialize(QUEUE_ERROR) -> libgearman-server
/queue
.cc:246
|
不知道是不是mysql版本太高的原因,还是其他的原因,如果大家试了实在不行还是换另一个方式,另一方式我测试是成功的.
创建一个后台job 。
1
|
> gearman -f
test
-b 123456
|
查看数据库如下:
希望本文所述对大家MySQL数据库计有所帮助.
原文链接:https://www.cnblogs.com/jkko123/p/6503600.html 。
最后此篇关于gearman + mysql方式实现持久化操作示例的文章就讲到这里了,如果你想了解更多关于gearman + mysql方式实现持久化操作示例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我是Hibernate的新手。当我保存特定实体时,它将从现有实体中重写数据。 我将ID用作自动生成,如下所示: @Id @GeneratedValue(strategy=GenerationType.
我正在尝试以连续模式使用CouchDB更改通知API,所以我想发送此消息 _changes?feed = continuous?include_docs = true作为GET请求到达我的CouchD
我有 XMPP 服务器(openfire)和一堆客户端(spark),分为几个组(部门)。我正在寻找能够将它们留在 session 室中的能力。我的意思是 Skype 具有的类似功能;当用户关闭带有群
我发布这个问题是为了看看我是否正确理解 Azure Functions 中的并行性,特别是 Durable Functions。 最近使用 az cli 在 Azure Functions 中添加了设
我在 Dev Env 上有一个 AKS 集群,上面运行着一些容器。我还启用了 Azure Log Analytics。但我可以看到正在运行的当前容器的日志,而不是已被终止或停止的旧容器的日志。 我想知
在 Akka 中,当一个 actor 在处理消息时死亡(在 onReceive(...) { ... } 内),该消息就会丢失。有没有办法保证无损?有一种配置 Akka 在将消息发送到 onRecei
我试图让 selectOneMany 取得有限的成功。 我有以下数据库模型 User email Text verkey Text Maybe verified Bool password T
我需要使用持久性(Yesod)从键列表中获取实体列表 假设我有一个 Model 及其相应的 ModelId。我身边有: keys :: [ModelId] 我需要得到 models :: [Model
我有一个使用 GWT、请求工厂和地点/Activity 构建的网络应用程序。我很好奇我使用的历史 token 是否持久。该任务基本上就是让 URL 定义我的网络应用程序的确切位置(读作“文件/文件夹结
我正在寻找一种 jQuery 方法来在刷新页面时使页面元素持久保留在用户屏幕上。当我刷新页面并且丢失 jQuery 页面中的内容时,它会发生变化。 我需要页面持久。如何刷新页面并保持元素不刷新(持久)
当我尝试使用 gcc 编译带有 -fopenmp 标志的 C 代码时,我已经持续收到此错误超过 6 小时了。 错误:控制谓词无效 for ( int i = 0; i #include #ifde
我有带有验证注释的实体,例如@NotNull。我不知道如何防止容器管理的事务在批量持久操作中出现 ConstraintViolationException 的情况下回滚,例如: public void
这是我的代码: http://jsfiddle.net/KCb5z/8/embedded/result/ http://jsfiddle.net/KCb5z/8/ $(function () {
我正在与服务器通信,理想情况下,我希望输入流和输出流始终处于运行状态。我收到未经请求的响应,因此我必须始终准备好接收输入流上的数据。 在我进一步深入之前,我应该说我建立的任何连接都必须能够支持 SSL
我正在寻找一种正确扩展 Azure Functions 的方法,但遇到了问题。 我有一组 IoT 设备,通过 HTTP 向 Azure 发送数据(为此,有一组自动扩展的 Azure Functions
1.临时态(瞬时态) 不存在于session中,也不存在于数据库中的数据,被称为临时态。 比如:刚刚使用new关键字创建出的对象。 2.持久态 存在于session中,事务还未提交,提交之后
我在 Kohana v2 中使用数据库 session 驱动程序。为了使 session 持久化,Kohana 创建了一个 token cookie。这个 cookie 使用了我想的 cookie 配
有谁知道是否有办法使用 PyWinrm 打开一个持久的 PowerShell session ,该 session 保持状态并且可以多次调用?我正在尝试执行以下操作: #!/bin/python im
在运行的Elasticsearch集群中,配置文件中的index.number_of_replicas设置为1。 我可以通过运行以下命令在运行的集群上将其更新为2 # curl -XPUT "http
我在“这么长的帖子必须意味着大量的代码和配置”部分下一对一地使用指南代码。 http://blog.springsource.com/2006/08/07/using-jpa-in-spring-wi
我是一名优秀的程序员,十分优秀!