Learning Salesforce Einstein
上QQ阅读APP看书,第一时间看更新

Installing  and configuring PredictionIO Event Server

There are a couple of ways to install PredictionIO. The first approach is to install it directly from Source Code and the other approach is using Docker.

To learn more about how to use the Docker container, there is an open source project. You can learn more here (https://github.com/sphereio/docker-predictionio).

For this section, we will directly install from the source code so that we know the components that are installed to get PredictionIO running.

  1. Create a folder where you want to install PredictionIO. Download the source code from the Apache software foundation website, which is located at https://www.apache.org/dyn/closer.cgi/incubator/predictionio/0.10.0-incubating/apache-predictionio-0.10.0-incubating.tar.gz
Note that the latest version at the time of writing is 0.10.0.
  1. Run the following commands in the same directory where you have downloaded the source code, which usually takes some time:
$ tar zxvf apache-predictionio-0.10.0-incubating.tar.gz
$ cd apache-predictionio-0.10.0-incubating
$ ./make-distribution.sh

The last command is a Shell Script to create the PredictionIO binary:

Once the installation is complete, you will see the preceding screen with a message that the binary PredictionIO is created for.

  1. Extract the binary that's just been built using the following command:
$ tar zxvf PredictionIO-0.10.0-incubating.tar.gz
The zxvf stands for the following: The z variable means unzip; x means extract files from the archive; v means print the filenames verbosely; and f means the following argument is a filename.
  1. Install the vendor dependencies into a new subfolder. Type the following command line:
$ mkdir PredictionIO-0.10.0-incubating/vendors
  1. Set up Apache Spark; if you recall, it is our processing engine. Let's type the following command lines to install Spark:
$ wget http://d3kbcqa49mib13.cloudfront.net/spark-1.5.1-bin-hadoop2.6.tgz

$ tar zxvfC spark-1.5.1-bin-hadoop2.6.tgz PredictionIO-0.10.0-incubating/vendors
If you decide to install Apache Spark to another location, you must edit PredictionIO-0.10.0-incubating/conf/pio-env.sh  and change the  SPARK_HOME  variable to point to your own Apache Spark installation.
  1. Set up Storage for the Event Server and other metadata. We can set this to either PostgreSQL (https://www.postgresql.org/) or HBASE. This section will only discuss the PostgreSQL setup since, for this chapter, we will be using PostgreSQL for all our experiments. The best method to install PostgreSQL on Mac is as follows: 
$ brew install postgresql

// LINUX users use

sudo apt-get install postgresql-9.4
  1. Link PIO with PostgreSQL by running the following command:
$ createdb pio

If you run into issues that read username does not exist, it may be a permission issue; in this case, simply try createdb and then log in using the following command. This will simply create a database for your login user:

psql -h localhost

If you get an error such as could not connect to server: No such file or directory, then you must first start the server manually using the following command:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start

Alternatively, you can also start Postgres using the following brew command:

brew services start postgresql
To stop PostgreSQL use  brew services stop postgresql

The final command to link PIO to PostgreSQL is as follows:

$ psql -c "create user pio with password 'pio'"
  1. Start the Event Server using the following command to confirm if it is configured:
pio eventserver &

Once the Event Server starts, you will see the following output:

Please note, if anytime you receive an error that states your ports are not reachable or Event Server cannot be started due to issues with PostgreSQL, manually start it with the following command:

$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
If the user is not able to connect to Postgres DB when running on Linux machine, we will need to create Postgres User using following command:



sudo -u postgres psql