本文实例讲述了gearman+mysql方式实现持久化操作。分享给大家供大家参考,具体如下:

1、为什么要持久化?

gearman的job server中的工作队列存储在内存中,一旦服务器有未处理的任务时重启或者宕机,那么这些任务就会丢失。
持久化存储队列可以允许添加后台任务,并将其存储在外部的持久型队列里(比如MySQL数据库)。

2、关于gearman的持久化的文章,建议可以看官方文档

http://gearman.org/manual/job_server/#persistent_queues
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;
> create user 'gearman'@'%' IDENTIFIED BY '123456';> grant all on gearman.* TO 'gearman'@'%';> flush privileges;
> 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
> 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
gearmand: unrecognised option '--libdrizzle-host=192.168.1.100'
https://launchpad.net/libdrizzle/+download

安装libdrizzle

> tar xf libdrizzle-5.1.4.tar.gz> cd libdrizzle-5.1.4
> ./configure> make && make install
> tar xf gearmand-1.1.12.tar.gz > cd gearmand-1.1.12
> ./configure --help
> yum install mysql-server mysql-devel
> ./configure> make && make install
* 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: :

查看是否安装上

> 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

> vi /etc/ld.so.conf
/usr/local/lib
> ldconfig
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.
gearmand: Error while initializing the queue : libdrizzle
ERROR 2017-02-22 07:51:02.536574 [ main ] Failed to initialize libdrizzle: initialize(QUEUE_ERROR) -> libgearman-server/queue.cc:246

创建一个后台job

> gearman -f test -b 123456

更多关于MySQL相关内容感兴趣的读者可查看本站专题:《MySQL索引操作技巧汇总》、《MySQL常用函数大汇总》、《MySQL日志操作技巧大全》、《MySQL事务操作技巧汇总》、《MySQL存储过程技巧大全》及《MySQL数据库锁相关技巧汇总》

希望本文所述对大家MySQL数据库计有所帮助。

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Andorid Dialog 示例【慢慢更新】
  3. Android(安卓)PureMVC
  4. Ubunu下搭建android NDK环境
  5. 自定义SeekBar主题
  6. android SQLite数据库基本操作示例
  7. android draw bitmap 示例代码
  8. Android启动时启动Activity 的定义的位置
  9. Android适配器之------BaseAdapter(例子)

随机推荐

  1. 正确使用异步函数的姿势[每日前端夜话(0x
  2. 下一代原生应用开发框架来了:Google Flutt
  3. 盘一盘机器学习中的那些距离
  4. 世界顶级公司的前端面试都问些什么[每日
  5. 精通webpack的5大关键点
  6. 使用机器学习生成可维护的前端代码(附源
  7. 前端AI实战——告诉世界前端也能做AI
  8. 文末重磅福利|Python实现回归预测及模型优
  9. 使用 RAIL 模型评估前端性能 [每日前端夜
  10. RPA 2020.11 all in one 安装