In this tutorial we will be discussing how to install elasticsearch with a jdbc river on a Ubuntu 14.04 LTS server.
Prequisites
For this tutorial you will need:
- A Ubuntu 14.04 LTS installation
- SSH access
- A logged in root user or a user with sudo rights
- MySQL installed
- Unzip installed (apt-get install unzip)
Install Oracle Java
sudo add-apt-repository ppa:webupd8team/java
and press enter when asked
apt-get update
sudo apt-get install oracle-java7-installer
You can test your java installation by checking what is the output of
java –version
Download Elasticsearch
First go to /home by using
cd /home
Now download the Elasticsearch Debian Package
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.4.deb
(Check if this version is still the latest by visiting http://www.elasticsearch.org/overview/elkdownloads/)
Install the Debian package by using
dpkg -i elasticsearch-1.3.4.deb
Start Elasticsearch by running
Service elasticsearch start
Wait some seconds and then visit
Your.servers.ip:9200
or use the command
curl -X GET 'http://localhost:9200'
It should say something like ‘status: 200’
and some other information.
You just installed Elasticsearch!
Install MySQL JDBC driver
Now you need to install the MySQL JDBC driver. This lets MySQL, JDBC river and Elasticsearch communicate.
Install the JDBC driver
./bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.3.4.4/elasticsearch-river-jdbc-1.3.4.4-plugin.zip
Download the MySQL JDBC driver to your current directory by using
curl -o mysql-connector-java-5.1.28.zip -L 'http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.28.zip/from/http://cdn.mysql.com/'
Unzip the zip file by using
unzip mysql-connector-java-5.1.28.zip
Add the jar to the JDBC river plugin directory and give it permissions.
cp mysql-connector-java-5.1.28/mysql-connector-java-5.1.28-bin.jar plugins/jdbc/
chmod 644 plugins/jdbc/
Restart Elasticsearch by using
service elasticsearch restart
Make sure you only have 1 (ONE!) mysql-connector-java-5.1.28-bin.jar in your elasticsearch folder! It should be in plugins/jdbc.
Your first JDBC river
Now you can start using JDBC river with SQL like this
1 2 3 4 5 6 7 8 9 |
curl -XPUT 'localhost:9200/_river/jdbc_river/_meta' -d '{ "type" : "jdbc", "jdbc" : { "url" : "jdbc:mysql://localhost:3306/myshop", "user" : "root", "password" : "root", "sql" : "select * from order" } }' |