#gearman服务的安装与使用
#date:2017-11-29

set -x
set -e

#安装开发依赖库
yum install gcc gcc-c++  make automake  glibc libgomp libstdc++-devel boost-devel* libevent-devel* libuuid-devel gperf*  mysql-devel -y

#下载安装gearman
#官方下载,请到https://launchpad.net/gearmand。
wget https://launchpad.net/gearmand/1.2/1.1.12/+download/gearmand-1.1.12.tar.gz
tar zxvf gearmand-1.1.12.tar.gz
cd gearmand-*
./configure       #建议直接默认./configure,不要指定路径等
make && make install



#启动gearman
/usr/local/sbin/gearmand --job-retries 10 --keepalive --protocol http --port 4730 --http-port 8080 --mysql-host xx.xx.xx.xx --mysql-port 3306 --mysql-user gearmand --mysql-password 123456 --mysql-db DB_Gearmand --mysql-table Tbl_GearmanQueue --log-file=/mnt/logs/gearman/gearmand.log --listen xx.xx.xx.xecho "end at `date`" 连接到mysql的数据信息 (数据库名和表名可以更改) CREATE DATABASE `DB_Gearman` /*!40100 DEFAULT CHARACTER SET utf8mb4 */
use
DB_Gearman

CREATE TABLE `Tbl_Queue` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`unique_key` char(64) NOT NULL DEFAULT '',
`function_name` char(255) NOT NULL DEFAULT '',
`priority` int(11) NOT NULL DEFAULT '0',
`data` longblob NOT NULL,
`when_to_run` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `unique_key__function_name` (`unique_key`,`function_name`(128))
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4