gearman + mysql方式实现持久化操作示例
16lz
2021-12-19
本文实例讲述了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数据库计有所帮助。
更多相关文章
- MySQL系列多表连接查询92及99语法示例详解教程
- Andorid Dialog 示例【慢慢更新】
- Android(安卓)PureMVC
- Ubunu下搭建android NDK环境
- 自定义SeekBar主题
- android SQLite数据库基本操作示例
- android draw bitmap 示例代码
- Android启动时启动Activity 的定义的位置
- Android适配器之------BaseAdapter(例子)