Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of implementing persistence operation in gearman + mysql mode

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

In this paper, an example is given to illustrate the implementation of persistence operation by gearman+mysql. Share with you for your reference, the details are as follows:

1. Why should it be persistent?

The work queues in gearman's job server are stored in memory, and once the server has outstanding tasks that restart or go down, those tasks are lost.

Persistent storage queues allow background tasks to be added and stored in external persistent queues (such as MySQL databases).

2. For articles about the persistence of gearman, you can refer to the official documentation.

Http://gearman.org/manual/job_server/#persistent_queues

3. Create databases and tables for persistence

CREATE DATABASE gearman;CREATE TABLE `varchar (64) NOT NULL, `function_ name` varchar (CREATE DATABASE gearman;CREATE TABLE) 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. Create gearman users

> create user 'gearman'@'%' IDENTIFIED BY' 123456; > grant all on gearman.* TO 'gearman'@'%'; > flush privileges

5. Specify persistence parameters when starting gearmand

> 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

Or use the following

> 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

If the following problems occur, you did not install libdrizzle when compiling and installing gearman

Gearmand: unrecognised option'--libdrizzle-host=192.168.1.100'

Download libdrizzle at the following URL

Https://launchpad.net/libdrizzle/+download

Such as: libdrizzle-5.1.4.tar.gz

Install libdrizzle

> tar xf libdrizzle-5.1.4.tar.gz > cd libdrizzle-5.1.4

It is best not to specify-- prefix here, because you have specified another directory. The following gearman compilation may not find the relevant header files and link libraries. You need to add soft links manually.

>. / configure > make & & make install

Then we recompile and install gearman

> tar xf gearmand-1.1.12.tar.gz > cd gearmand-1.1.12

If any of the parameters of configure are unclear, you can check it with the following command

>. / configure-- help

Here you need to install mysql-devel so that gearman supports the persistence of mysql

> yum install mysql-server mysql-devel

Because I installed gearman earlier, I did not specify-- prefix, so it is not specified here. If necessary, you can specify it on your own.

>. / configure > make & & make install

Configure completes the last piece of information displayed

* 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::

Finally, you can see that libdrizzle and libmysql show yes.

Check to see if it is installed on

> gearmand-- help

If the following error occurs

Gearmand: error while loading shared libraries: libdrizzle.so.9: cannot open shared object file: No such file or directory

Please open modify / etc/ld.so.conf

> vi / etc/ld.so.conf

Add the following sentence

/ usr/local/lib

Run ldconfig

> ldconfig

Run the above gearmand-- help again, and if the following message appears, the installation is successful

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.

Start gearmand through libdrizzle if the following problems occur

Gearmand: Error while initializing the queue: libdrizzle

And the record in the log is like this.

ERROR 2017-02-22 07 Failed to initialize libdrizzle 51V 02.536574 [main] Failed to initialize libdrizzle: initialize (QUEUE_ERROR)-> libgearman-server/queue.cc:246

Do not know if the mysql version is too high, or other reasons, if you try really not, or another way, another way my test is successful.

Create a background job

Gearman-f test-b 123456

View the database as follows:

Readers who are interested in MySQL-related content can check out this site's special topics: "Summary of MySQL Index Operation skills", "Summary of MySQL Common functions", "Collection of MySQL Log Operation skills", "MySQL transaction Operation skills Summary", "MySQL stored procedure skills Collection" and "MySQL Database Lock related skills Summary"

It is hoped that what is described in this article will be helpful to everyone's MySQL database design.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report