您的位置:首页 > 其它

elasticsearch-5.5.3伪分布式集群开发过程中问题总结

2017-11-01 11:10 399 查看
 
一、X-pack修改密码问题

       伪分布式集群,一台机子上3个实例,每个实例都安装了x-pack,肯定不能用默认的密码,必须修改。我以为三个实例要分别修改,当我先启动第一个实例,修改完密码后;把第一个kill掉,再启动第二个实例,再修改时报错了:

{"error":{"root_cause":[{"type":"illegal_state_exception","reason":"passwordcannot be changed as user service cannot write until template and mappings areup to date"}],"type":"illegal_state_exception","reason":"passwordcannot
be changed as user service cannot write until template and mappings areup to date"},"status":500}

      解决:这证明伪分布式集群不是单个修改的,而是:第一种方法:首先启动所有实例,然后在主节点上修改(如果3个都是主节点,任选一个,一般选第一个启动的),这样集群就都修改了;第二种:你先启动了第一个实例,然后修改密码,紧接着启动第二个、第三个实例,让他们形成集群,并不用再修改,后加入的会自动同步第一个的密码。但是真分布式集群是不是这样我还没测试。



二、Logstash端口问题

      因为我要把MySQL数据同步到elasticsearch,使用到了logstash-input-jdbc插件,所以必须先安装logstash,而logstash默认端口为9600至9700,由于某些规则我想使用其它端口,就把logstash端口改成了8099,但是这一改就出问题了,报如下错:

error.{:url=>"http://logstash_system:xxxxxx@localhost:9200/",:error_type=>LogStash::Outputs::ElasticSearch::HttpClient::Pool::HostUnreachableError,:error=>"Elasticsearch Unreachable:[http://logstash_system:xxxxxx@localhost:9200/][Manticore::SocketException]Connection
refused (Connection refused)"}

["192.168.110.31:8011", "192.168.110.31:8012","192.168.110.31:8013"]

       况且我在logstash.yml文件中配置的是修改后的x-pack信息:

xpack.monitoring.elasticsearch.url:["192.168.110.31:8011","192.168.110.31:8012","192.168.110.31:8013"]

xpack.monitoring.elasticsearch.username:"elastic"

xpack.monitoring.elasticsearch.password:"abc234wer"

       那么为什么它会显示logstash_system:xxxx,证明他根本没走默认的配置文件,并且我的三个elasticsearch实例端口并不是9200;我后来把logstash端口那里注掉了,再启动logstash就成功了,它又使用了9600端口。所以最好不要修改logstash端口



三、Logstash后台长期运行问题

       # ./bin/logstash  -f  xxx.conf 

       采用这种方式启动,会一直占用屏幕输出,一旦退出进程就挂了,而你想在后台运行,网上有用nohup运行的,有用screen方式启动的;而用nohup方式启动时,虽然可以在后台运行,但是logstash日志一直报:

A plugin had an unrecoverable error. Will restart thisplugin.

Plugin: <LogStash::Inputs::Stdinid=>"d82cf8f6e66e1ce48c50c9d2d840029f3296238a-1",enable_metric=>true, codec=><LogStash::Codecs::Line id=>"line_6e3830b8-b4c6-4fb8-b15c-27356ae29021",enable_metric=>true, charset=>"UTF-8",delimiter=>"\n">>

Error: Bad file descriptor - Bad file descriptor

 

       Elasticsearch中文社区有一个同样的问题,下面的回答说这个错是由于直接bin/logstash 启动的时候,有个plugin要从stdin里面读数据。而一旦用了nohup,表明stdin就是空了,自然会报 bad file descriptor这个错。他提出了两个解决方法:一个是把logstash安装成服务,另外一个在启动时加个参数:

nohup  bin/logstash  -f  config/xxxxxxx.conf  0</dev/null &

       原因分析的很有道理,但是这个方法我还没测试。不过我发现当用./bin/logstash   -f   xxx.conf 这个命令启动完后,我同时按下ctrl+z,回到终端,用jps查看logstash仍在运行,logstash在后台的进程名称为Main;这也达到了我的目的。有兴趣的人可以试一下那个人说的方法。我还专门搜了一下在linux中ctrl+z和ctrl+c的区别,这里可不能ctrl+c,一按就stop掉了。按ctrl+z挂起。

 

四、elasticsearch客户端api查询问题

       在elasticsearch中prefixQuery(前缀查询),只能应用在text类型上,不能用在long类型上,从mysql同步到elasticsearch时,系统自动将主键id映射为long类型,我在代码里用QueryBuilders.prefixQuery(“id”,”192345”),前缀匹配id查询时就报错了:

org.elasticsearch.index.query.QueryShardException: Can onlyuse prefix queries on keyword and text fields - not on [id] which is of type[long]

org.elasticsearch.action.search.SearchPhaseExecutionException :all shards failed



五、客户端查询结果返回source的问题

       采用SearchResponse类返回的response.getHits()可以返回查询结果,你想在返回结果时转换为JavaBean,但是报异常了,原因是结果里面还返回了@timestamp、@version、和type信息。属性对不上当然报错。那么怎么让它别返回这个三个信息呢,SearchRequestBuilder里面有一个setFetchSource()方法,有几个构造函数,参数里面可以定义返回哪些,不返回哪些,我用的是这个方法

public SearchRequestBuilder setFetchSource(@Nullable String[] includes, @Nullable String[] excludes) {
    this.sourceBuilder().fetchSource(includes, excludes);
    return this;
}

      第一个参数是设置哪些要返回,是一个字段数组,第二个参数是不要返回哪些字段,我感觉这个方法不太人性化,既然第一个参数已经指定我要哪些了,那剩下的肯定是不要了呗,第二个参数还干嘛用?我觉得有问题。

      当时最开始想的是在动态映射模版文件中修改@timestamp、@version、和type这三个属性让他们不被索引,结果却导致kibana中查不到elasticsearch的数据,而SearchRespons还是返回了这三个字段,所以我的想法错了,赶紧改回来,kibana中又可以搜到了,证明kibana是根据时间戳@timestamp来检索的,以后不敢乱修改了。



六、使用Java客户端连接时,启动log4j的问题

      Elasticsearch客户端要用到log4j-core的依赖,没加启动项目就会显示一行红颜色的字

ERRORStatusLogger Log4j2 could not find a logging implementation. Please addlog4j-core to the classpath. Using SimpleLogger to log to the console...

      加了这个依赖后,又冒了一行红颜色的字:

ERRORStatusLogger No log4j2 configuration file found. Using default configuration:logging only errors to the console.

      解决:在项目resource文件夹下新建一个log4j2.xml,文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="[%-5p] %d %c - %m%n" />
        </Console>
        <File name="File" fileName="dist/my.log">
            <PatternLayout pattern="%m%n" />
        </File>
    </Appenders>

    <Loggers>
        <Logger name="mh.sample2.Log4jTest2" level="INFO">
            <AppenderRef ref="File" />
        </Logger>
        <Root level="INFO">
            <AppenderRef ref="Console" />
        </Root>
    </Loggers>
</Configuration>


七、jdbc插件支持多表配置

  input里面配置多个数据源,output里面根据if[type]==”my_type”{ }else{ }来分别输出

八、多表联合查询

 这里多表指的是嵌套关系、父子关系;Java api为

HasParentQueryBuilderhpqb=QueryBuilders.hasParentQuery("branch",QueryBuilders.idsQuery().ids("london"));更多请参考下面的链接

九、如果kibana的monitor模块看不到logstash的监控信息,试着在logstash.yml文件中加入:

xpack.monitoring.exporters:

  id1:

    type: http

    host: ["192.168.110.31:8011","192.168.110.31:8012","192.168.110.31:8013"]

    auth.username: remote_monitor

    auth.password: yourpassword

当然首先你得为remote_monitor设置角色和密码:

curl -XPOST -uelastic '172.31.11.31:8091/_xpack/security/user/remote_monitor' -d '{

  "password" :"yourpassword",

  "roles" : ["remote_monitoring_agent"],

  "full_name" : "Internal AgentFor Remote Monitoring"

}'

更多请参见官网监控集群的配置
https://www.elastic.co/guide/en/x-pack/5.6/monitoring-cluster.html 集群监控

http://www.cnblogs.com/l-xxx-10000/p/6380062.html 父子搜索

https://elasticsearch.cn/question/2690   nohup启动报错解决
http://blog.csdn.net/SunnyYoona/article/details/51842221 http://www.cnblogs.com/dennisit/p/3363851.html  searchType介绍

http://www.jianshu.com/p/eb30eee13923   matchQuery和termQuery比较

http://www.bubuko.com/infodetail-1813779.html     logstash后台长期运行

https://segmentfault.com/q/1010000010230074    jdbc多索引配置

http://www.jianshu.com/p/a49d93212eca  xpack介绍
http://www.cnblogs.com/Orgliny/p/5442519.html  match和term比较
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息