首先說明一點,大家最好不要用什么嘗鮮版,用比穩定版就好了,要不麻煩不斷,另外出了問題,最好去官網,或者google搜索,因為這樣靠譜些,要不現在好多都是低版本的,1.4的什么的,結果按照安裝,多少情況下有這樣那樣的問題。
鄭重聲明,本文ElasticSearch2.3.1最新版的安裝,其他的版本請搭建自行google,最好不要百度,百度一般都是老文章,有些版本問題很多,瞎折騰
ElasticSearch 安裝配置
這個有點老套了,具體大家去移步官網:https://www.elastic.co/guide/en/sense/current/installing.html
按照上面博客的步驟,我安裝了elasticsearch-2.3.1版本的,Java 1.8版本,可是不知道為何運行不起來
Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:93)
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:144)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:270)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
網站一搜,環境變量的問題,可是結果里里外外搞了三次就是不行,去官網搜一下,解決額 ./bin/elasticsearch -Des.insecure.allow.root=true
具體出現問題可以對號入座。這個是因為權限,分組的問題,可以給es用戶組 權限等等 具體問題可以百度其他的
marvel的安裝請參考官網
https://www.elastic.co/guide/en/marvel/current/installing-marvel.html
cd /usr/share/elasticsearch sudo bin/plugin install license sudo bin/plugin install marvel-agent
現在是:http://localhost:9200/_plugin/marvel/ 是空白,還是不知道啥原因,算了,先把數據庫數據導入進來再說
推薦:Elasticsearch入門中文版 http://es.xiaoleilu.com/010_Intro/00_README.htm
https://www.gitbook.com/book/looly/elasticsearch-the-definitive-guide-cn/details
將MySQL中的數據導入ElasticSearch
上面那篇文章的問題,下面將會說明
由於es官網叫停river類的導入插件,因此原始的elasticsearch-jdbc-river變更為elasticsearch-jdbc,成為一個獨立的導入工具。官方提到的同類型工具還有logstash,個人覺得logstash在做數據庫同步的時候並不是很好用,有太多坑要填。目前2.0以上版本並不支持windows的環境,所以各位同學不要試了,windows下最高支持到1.7.3。(2015.12.9)
所以大家看到
- ./bin/plugin --install river-jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.5.0.5/elasticsearch-river-jdbc-1.5.0.5-plugin.zip</span>
這樣的命令 那么就是坑,因為官方不讓安裝了,因為這個問題,我折騰了好久
具體做法就是
- $ wget http://xbib.org/repository/org/xbib/elasticsearch/importer/elasticsearch-jdbc/2.3.1.0/elasticsearch-jdbc-2.3.1.0-dist.zip
- $ unzip elasticsearch-jdbc-2.3.1.0-dist.zip
下面 database是我MySQL數據庫名稱
table是我mysql的表名稱
- "index" : "test",
- "type" : "stdutent"
- bin=/root/elasticsearch-2.3.1/elasticsearch-jdbc-2.3.1.0/bin
- lib=/root/elasticsearch-2.3.1/elasticsearch-jdbc-2.3.1.0/lib
- echo '{
- "type" : "jdbc",
- "jdbc": {
- "url":"jdbc:mysql://localhost:3306/database",
- "user":"root",
- "password":"root",
- "sql":"select * from table",
- "index" : "test",
- "type" : "stdutent"
- }
- }'| java \
- -cp "${lib}/*" \
- -Dlog4j.configurationFile=${bin}/log4j2.xml \
- org.xbib.tools.Runner \
- org.xbib.tools.JDBCImporter
chmod +x import.sh 根據數據庫原因,導入可能有些慢
運行之后./import.sh
往下
- [root@localhost elasticsearch-jdbc-2.3.1.0]# curl 'http://localhost:9200/test/student/_search?pretty&q=*'
如果有數據,說明導入成功
任何東西不考慮環境因素,那么坑很多,jdbc具體安裝可以參考 這個可能是個完善的方法,我上面只能導入一個表的文件
詳細的jdbc安裝可以參考下面一篇文章
http://bluereader.org/article/122422454
官方插件 https://github.com/jprante/elasticsearch-jdbc