gearman

任务队列

安装配置
http://gearman.org 
 
 
https://launchpad.net/gearmand 下载最新的版本 gearmand-X.Y.tar.gz
 
 
把gearmand-1.1.12.tar.gz放到 /root/tools 下面去
yum install -y boost  boost-devel gperf libevent-devel libuuid-devel
(yum install boost*  boost-devel* gperf* libevent-devel* libuuid-devel*)
 
 
cd /root/tools
tar xzf gearmand-X.Y.tar.gz
cd gearmand-X.Y
 
find / -name 'mysql_config '  #(如果没有mysql就要安装mysql (yum install mysql mysql-server  mysql-devel),找到mysql_config具体的路径对应下面的内容要修改)
 
./configure  --with-mysql=/usr/bin/mysql_config 
 
make
make install
 
 
 
 
 
 
遇到问题:
错误提示:
error: could not find boost
解决方法:
yum install -y boost boost-devel
 
 
错误提示:
could not find gperf
解决方法:
yum install -y gperf
 
 
因为默认的命令yum install boost  boost-devel 安装到的只是 旧版本,可能是与操作系统默认的资源库有关,
所以需要手动安装最新版的boost  
 
yum install gcc-c++
 
 
 
###boost文件太大,不建议下载更新.
wget http://sourceforge.net/projects/boost/files/boost/1.60.0/boost_1_60_0.zip/download
unzip boost_1_60_0.zip
cd boost_1_60_0
./bootstrap.sh --prefix=/usr/local/boost/ 
./b2 install
 
 
 
 
greaman的PHP扩充  : 到 http://pecl.php.net/package/gearman下载最新版
 
cd /root/tools
 
 
 
wget http://pecl.php.net/get/gearman-1.1.2.tgz
 
tar -zxvf gearman-X.Y.tgz
cd gearman-X.Y
phpize
./configure
make
make install
 
 
 
如果有错误: configure: error: Please install libgearman
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/libgearman-devel-1.1.8-2.el6.x86_64.rpm
 
yum install libgearman-devel.i686 libgearman.i686 后,此问题解决
 
 
如果出现错误:libgearman version 0.21 or later required,说明libgearman版本过低,libgearman所有版本地址:
http://fr2.rpmfind.net/linux/rpm2html/search.php?query=libgearman-devel&system=&arch=
rpm包地址:http://dl.fedoraproject.org/pub/epel/6/x86_64/
如果仍然出错,可考虑换一个低版本的gearman: wget http://pecl.php.net/get/gearman-0.8.0.tgz
 
 
 
 
 
在 /usr/lib64/php/modules/ 会生成文件gearman.so
 
vi /etc/php.ini
 
在最后增加一句
extension="gearman.so"
 
 
重启nginx
service nginx restart
service php-fpm restart
 
 
启动gearman
gearmand -d
 
 
////////////gearman增加mysql的支持////////
创建数据库和表
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, PRIMARY KEY  (`unique_key`)
);
 
 
 
gearmand -q MySQL --mysql-host=localhost --mysql-user=root --mysql-password=123456 --mysql-db=gearman --mysql-table=gearman_queue  -d
 
php /root/gearman/GearmanWorker.php -d
 
gearmand -p 4730 -L 0.0.0.0 --log-file=/tmp/gearmand-4730.log --pid-file=/tmp/gearmand-4730.pid -q MySQL --mysql-host=localhost --mysql-user=root --mysql-password --mysql-db=gearman 
 
 
 
创建一个后台job
gearman -f testqueue -b xx00
 
查看队列
select * from gearman.gearman_queue
 
执行队列中的job
gearman -f testqueue -w
 
查看队列
select * from gearman.gearman_queue  //这条job删除掉了
 
 
 
http://www.cppblog.com/guojingjia2006/archive/2013/01/07/197076.html
 
http://dl.iuscommunity.org/pub/ius/stable/CentOS/7/x86_64/
 
http://www.tuicool.com/articles/mInQvm
 
http://blog.csdn.net/e421083458/article/details/21283113   
                                                                                                                                                                                                                                                                                                                        

 

posted on 2017-05-09 11:29  轻浮不韪  阅读(169)  评论(0编辑  收藏  举报