您的位置:首页 > 数据库 > MySQL

搭建elasticsearch,并同步mysql数据

2016-03-29 16:46 826 查看
系统:ubuntu、mysql、java8
 
一、安装java,要求java7以上。
sudo apt-get install openjdk-7-jre
 
二、下载安装 elasticsearch
1)、
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.deb
2)、
sudo dpkg -i elasticsearch-1.4.4.deb
3)、
/etc/init.d/elasticsearch start

三、安装head插件 https://github.com/mobz/elasticsearch-head/archive/master.zip
将上述文件解压到/usr/share/elasticsearch/plugins 
如果没有这个目录自行创建。
通过http://localhost:9200/_plugin/head/就可以方便使用es了。
四、安装JDBC
插件
 /usr/share/elasticsearch/bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.4.0.10/elasticsearch-river-jdbc-1.4.0.10.zip
 
五、安装Mysql JDBC
驱动
1)、下载jdbc驱动
wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/1.5.2.0/elasticsearch-jdbc-1.5.2.0-dist.zip 2)、解压
unzipelasticsearch-jdbc-1.5.2.0-dist.zip
3)、
cd elasticsearch-jdbc-1.5.2.0/bin/
4)、建立import.sh文件,用来导入mysql数据到es
touch import.sh
5)、编写import.sh文件,如下:
#!/bin/bash
set -e
 
bin=/home/test/Desktop/work/elasticsearch-jdbc-1.5.2.0/bin
lib=/home/test/Desktop/work/elasticsearch-jdbc-1.5.2.0/lib
echo '{
"type" :"jdbc",
"jdbc" : {
"url" :"jdbc:mysql://127.0.0.1:3306/test",
"user" :"root",
"password": "",
"sql" :"select * from test;",
"index":"test",
"type":"ach"
}
}' | java \
-cp"${lib}/*" \
-Dlog4j.configurationFile=${bin}/log4j2.xml\
org.xbib.tools.Runner\
org.xbib.tools.JDBCImporter
6)、运行导入
chmod 777 import.sh
./import.sh
 
六、导入成功,可以进行搜索了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  elasticsearch mysql