首页 web服务器 正文
284

Gearman服务管理及队列持久化

#!/bin/bash

#普通模式,任务队列存放在内存中。
/usr/sbin/gearmand -d --log-file=/var/log/gearmand.log -L 0.0.0.0 -p 4730

#Mysql队列模式,将任务队列存放在Mysql数据库中。
/usr/sbin/gearmand -d --log-file=/var/log/gearmand.log -L 0.0.0.0 --queue-type=mysql \
--mysql-host=127.0.0.1 --mysql-port=3306 --mysql-user=user --mysql-password=ComplexPassword \
--mysql-db=mydbname --mysql-table=gearman_queue
#验证成功与否: gearman -f test -b abcdef, 然后查看gearman_queue表有没有这条job.
#除了支持mysql外,还支持memcache, sqlite等,具体参数运行:gearmand --help查看。
#gearman_queue表结构如下:
#CREATE TABLE `gearman_queue` (
#  `unique_key` varchar(64) COLLATE ascii_bin NOT NULL,
#  `function_name` varchar(255) COLLATE ascii_bin NOT NULL,
#  `priority` int(11) NOT NULL,
#  `data` longblob NOT NULL,
#  `when_to_run` int(11) NOT NULL,
#  PRIMARY KEY (`unique_key`,`function_name`) USING BTREE,
#  KEY `function_name` (`function_name`) USING BTREE
#) ENGINE=InnoDB DEFAULT CHARSET=ascii COLLATE=ascii_bin

#-b –-backlog:监听连接数量
#-d –-daemon:后台运行
#-f –-file-descriptors:文件描述符的数量
#-j –-job-retries:移除不可用 Job 之前运行的次数
#-l –-log-file:日志文件存放位置(默认记录最简单日志)
#-L –-listen:监听的 IP
#-p –-port:指定监听端口
#-q –-queue-type:指定持久化队列
#-t –-threads:使用的 I/O 线程数量
#-u –-user:启动后,切换到指定用户
#--mysql-host:--mysql 系列为 MySQL 持久化连接信息

# If running: ps aux|grep gearmand  OR netstat -anlutp | grep gearmand

# Version: gearadmin --server-version OR gearmand -V

# Shutdown: gearadmin --shutdown

# 开放4730端口供外部访问:
# firewall-cmd --zone=public --add-port=4730/tcp --permanent
# 重启:systemctl restart firewalld.service

#gearman安装后在bin目录下有2个程序gearman,gearadmin

#[gearadmin]
#--help
#Provice help about the program.

#--create-function
#Create a function from the server.

#-h [ --host ] arg (=localhost)i
#Connect to the host

#-p [ --port ] arg (=4730)
#Port number or service to use for connection

#--drop-function
#Drop a function from the server.

#--server-version
#Fetch the version number for the server.

#--server-verbose
#Fetch the verbose setting for the server.

#--status
#Status for the server.

#--workers
#Workers for the server.

#--shutdown
#Shutdown server.

#[gearman]
#bin目录下的gearman用来命令行操作命令。Command line client for Gearmand

#Common options

#-f <function>
#Function name to use for jobs (can give many)

#-h <host>
#Job server host

#-H
#Print this help menu

#-p <port>
#Gearman server port

#-t <timeout>
#Timeout in milliseconds

#-i <pidfile>
#Create a pidfile for the process

#-n
#In client mode run one job per line, in worker mode send data packet for each line

#-N
#Same as -n, but strip off the newline

#Client options

#-b
#Run jobs in the background

#-I
#Run jobs as high priority

#-L
#Run jobs as low priority

#-P
#Prefix all output lines with functions names

#-s
#Send job without reading from standard input

#-u <unique>
#Unique key to use for job

#Worker options*

#-c <count>
#Number of jobs for worker to run before exiting

#-w
#Run in worker mode

#With gearman you can run client and worker functions from the command line.

#The environmental variable GEARMAN_SERVER can be used to specify multiple gearmand servers. Please see the c:func:’gearman_client_add_servers’ for an explanation of the required syntax.


正在加载评论...