欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

ElasticSearch2.3.1环境搭建哪些不为人知的坑

发布时间:2025/3/15 编程问答 30 豆豆
生活随笔 收集整理的这篇文章主要介绍了 ElasticSearch2.3.1环境搭建哪些不为人知的坑 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

   首先说明一点,大家最好不要用什么尝鲜版,用比稳定版就好了,要不麻烦不断,另外出了问题,最好去官网,或者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)

所以大家看到

 

[php] view plaincopy
  • ./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>  

  • 这样的命令 那么就是坑,因为官方不让安装了,因为这个问题,我折腾了好久

     

    具体做法就是

     

    [php] view plaincopy
  • $ 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  
  • 编辑vim import.sh

     

    下面 database是我MySQL数据库名称

    table是我mysql的表名称

    [php] view plaincopy
  • "index" : "test",  
  • index是es中的数据结构,你可以把他看成mysql中的库 [php] view plaincopy
  • "type" : "stdutent"  
  • type类似于mysql中的表
    [php] view plaincopy
  • 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
    往下

    [php] view plaincopy
  • [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

    了解下概念吧,下面的jdbc安装已经不适用了

    https://github.com/leotse90/blogs/blob/master/ElasticSearch%E4%B8%8EMySQL%E6%95%B0%E6%8D%AE%E5%90%8C%E6%AD%A5%E4%BB%A5%E5%8F%8A%E4%BF%AE%E6%94%B9%E8%A1%A8%E7%BB%93%E6%9E%84.md

     

    转载于:https://www.cnblogs.com/Don/p/5529003.html

    总结

    以上是生活随笔为你收集整理的ElasticSearch2.3.1环境搭建哪些不为人知的坑的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。