predictionio部署

 
 
本次predictionio部署的系统为:虚拟机centos6.5,内存4G,已在本机(win7)安装Mysql。
predictionio由两部分组成:eventserver和predictionserver,eventserver负责数据源的收集,predictionserver为推荐引擎。三类数据需要保存:数据源eventdata、模型(modeldata)、metadata。三类数据默认保存在PostgreSQL,可在pio-env.sh中配置,pio-env.sh文件位置为apache-predictionio-0.10.0-incubating/conf,默认提供的模版文件pio-env.sh.template,需执行若下命令
 
 
mv pio-env.sh.template pio-env.sh
本次部署选用mysql数据库,需要修改配置文件pio-env.sh,将三类数据的类型改为mysql
 
 

# Default is to usePostgreSQL
PIO_STORAGE_REPOSITORIES_METADATA_NAME=pio_meta
PIO_STORAGE_REPOSITORIES_METADATA_SOURCE=MYSQL
PIO_STORAGE_REPOSITORIES_EVENTDATA_NAME=pio_event
PIO_STORAGE_REPOSITORIES_EVENTDATA_SOURCE=MYSQL
PIO_STORAGE_REPOSITORIES_MODELDATA_NAME=pio_model
PIO_STORAGE_REPOSITORIES_MODELDATA_SOURCE=MYSQL

并将Mysql的连接配置为自己已安装并启动的数据库,本次部署以搭建的Mysql数据,在pio-env.sh中的配置如下
 
 

# MySQL Example
PIO_STORAGE_SOURCES_MYSQL_TYPE=jdbc
PIO_STORAGE_SOURCES_MYSQL_URL=jdbc:mysql://192.168.107.1:3306/pio
PIO_STORAGE_SOURCES_MYSQL_USERNAME=root
PIO_STORAGE_SOURCES_MYSQL_PASSWORD=123456

eventserver

eventserver部署步骤参照:http://predictionio.incubator.apache.org/install/install-sourcecode/
首先下载apache-predictionio-0.10.0-incubating.tar.gz,下载路径
https://www.apache.org/dyn/closer.cgi/incubator/predictionio/0.10.0-incubating/apache-predictionio-0.10.0-incubating.tar.gz
解压,并新建vendors文件夹。
 
 
tar zxvf apache-predictionio-0.10.0-incubating.tar.gz
cd apache-predictionio-0.10.0-incubating
./make-distribution.sh
mkdir vendors
进入刚才新建的vendors文件夹,下载并解压spark安装包。
 
 
cd vendors
wget http://d3kbcqa49mib13.cloudfront.net/spark-1.5.1-bin-hadoop2.6.tgz
tar -zxvf spark-1.5.1-bin-hadoop2.6.tgz
启动,本次使用的数据库为mysql,在文件夹apache-predictionio-0.10.0-incubating/bin下执行,不要执行pio-start-all
 
 
./pio eventserver &
执行成功后,出现如下界面
 
 
[root@cent65m bin]# ./pio eventserver &
[1] 8076
[root@cent65m bin]# [INFO] [Console$] Creating Event Server at 0.0.0.0:7070
[INFO] [HttpListener] Bound to /0.0.0.0:7070
[INFO] [EventServerActor] Bound received. EventServer is ready.
可使用如下命令查看启动状态
./pio status

predictionserver部署
predictionserver配置步骤参照:http://predictionio.incubator.apache.org/templates/recommendation/quickstart/。predictionserver部署的前提条件是eventserver部署完成并已启动。

1. 利用引擎模板创建推荐引擎

首先进入想把推荐引擎部署到的路径,本次推荐引擎部署在apache-predictionio-0.10.0-incubating目录下
 
 
cd /home/apache-predictionio-0.10.0-incubating
pio template get apache/incubator-predictionio-template-recommender MyRecommendation
cd MyRecommendation

2. 产生 AppID Access Key

本次部署的推荐引擎命名为MyApp1,则执行以下命令
 
 
pio app new MyApp1
本次部署产生的Access Key: UzTEPPAr37VmAGArebKZ9B1KeIopTo75w3GdOBXhU-PjEQbYGWaCMzm_hNiAqKC8,产生购买或评分数据时会用到这个Access Key。
可执行以下命令,查看已产生的应用
 
 
pio app list

3. 收集数据

执行以下命令,产生购买或评分数据,eventserver会把自动这些数据保存到数据库中。
 
 
curl -i -X POST http://localhost:7070/events.json?accessKey=UzTEPPAr37VmAGArebKZ9B1KeIopTo75w3GdOBXhU-PjEQbYGWaCMzm_hNiAqKC8 \
-H "Content-Type: application/json" \
-d '{
  "event" : "buy",
  "entityType" : "user",
  "entityId" : "u1",
  "targetEntityType" : "item",
  "targetEntityId" : "i2",
  "eventTime" : "2014-11-10T12:34:56.123-08:00"
}'
其中accessKey=UzTEPPAr37VmAGArebKZ9B1KeIopTo75w3GdOBXhU-PjEQbYGWaCMzm_hNiAqKC8,accessKey=后面的Key是上一步中产生的Access Key。修改"entityId" : "u1"中的u1或"targetEntityId" : "i2"中的i2,会产生不同用户购买不同的商品ID,例如,"entityId" : "u1"修改为"entityId" : "u2",便于后续训练数据和推荐。
在浏览器访问如下链接,可查询已经产生的数据。
http://localhost:7070/events.json?accessKey=UzTEPPAr37VmAGArebKZ9B1KeIopTo75w3GdOBXhU-PjEQbYGWaCMzm_hNiAqKC8

4. 将推荐引擎部署为服务

进入到MyRecommendation路径,修改Engine.json,将appname修改为本次命名的MyApp1,修改成如下
"appName": "MyApp1"
a)  编译
pio build --verbose
b) 训练数据
pio train
c)  部署为服务
pio deploy

d) 获取推荐结果

curl -H "Content-Type: application/json" -d '{ "user": "u1", "num": 4 }' http://localhost:8000/queries.json

其中"user": "u1"中的u1为收集数据步骤中产生数据时执行的命令。

部署中遇到的问题与解决

1. 执行编译(build)时,报错:Not a valid command: assemblyPackageDependency
原因:编译前未进入到MyRecommendation
解决:cd MyRecommendation进入MyRecommendation路径下,再执行pio build
注意:pio的bin路径要加到/etc/profile中或者输入pio的全路径,比如本次部署可执行
/home/ apache-predictionio-0.10.0-incubating/bin/pio train
解决方法也可参考:

https://github.com/sphereio/docker-predictionio/issues/4

2.执行train时报错: ERROR org.apache.spark.executor.Executor [Executor task launch worker-3] - Exce
解决:减小engine.json中的循环次数。
解决方法可参照:http://stackoverflow.com/questions/34133172/predictionio-engine

predictionio部署文档和安装包下载


其他链接

DASE Components Explained (Recommendation)推荐引擎解释链接
http://predictionio.incubator.apache.org/templates/recommendation/dase/
System Architecture and Dependencies链接
http://predictionio.incubator.apache.org/system/

猜你喜欢

转载自blog.csdn.net/zilong230905/article/details/68952890
今日推荐