受欢迎的博客标签

Elasticsearch on Ubuntu(3) -Error and Configure Elasticsearch 7.x on Ubuntu

Published

Table of Content

1.

2.Elasticsearch Failed to start service in Ubuntu 18.04- Could not create the Java Virtual Machine

 

Elasticsearch Failed to start service in Ubuntu 18.04-low disk watermark [85%] exceeded

 

3. Elasticsearch 7.4.2 Failed to start service in Ubuntu 18.04 -Invalid NEST response built from a successful (404) low level call on HEAD

 

Elasticsearch 7.14.1

 

Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.14/security-minimal-setup.html to enable security.

 

 

 

Elasticsearch 7.4.2

 

Open the Elasticsearch configuration file for editing:

sudo vi /etc/elasticsearch/elasticsearch.yml

 

error:

the default discovery settings are unsuitable for production use; at least one of [discovery.seed_hosts, discovery.seed_providers, cluster.initial_master_nodes] must be configured

 

network.host : 0.0.0.0
将 #cluster.initial_master_nodes: ["node-1", "node-2"] 
修改为 cluster.initial_master_nodes: ["node-1"],记得保存。
# ---------------------------------- Network -----------------------------------
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
+network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
	@@ -70,6 +71,7 @@ path.logs: /var/log/elasticsearch
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
+cluster.initial_master_nodes: ["node-1"]
#
# For more information, consult the discovery and cluster formation module documentation.
#

访问公网ip出现审计错误:

Valid NEST response built from a successful low level call on POST: /project/doc/_search
# Audit trail of this API call:
 - [1] SniffOnStartup: Took: 00:00:00.0360264
 - [2] SniffSuccess: Node: http://localhost:9200/ Took: 00:00:00.0310228
 - [3] PingSuccess: Node: http://127.0.0.1:9200/ Took: 00:00:00.0115074
 - [4] HealthyResponse: Node: http://127.0.0.1:9200/ Took: 00:00:00.1477640
# Request:
<Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
# Response:
<Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
to help with troubleshootin


https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/audit-trail.html

解决:原为Nest 6.02 版本,按Nest 7.4.2 语法重写创建索引和查询,问题得到解决。

low disk watermark [85%] exceeded on

error:low disk watermark [85%] exceeded

2021-09-20T00:00:07,336][INFO ][o.e.c.r.a.DiskThresholdMonitor] [iZuf6hn15mpmrtypv9ltogZ]
low disk watermark [85%] exceeded on
 [zH0bEPJ9R1C-xKZIcb4BFg][iZuf6hn15mpmrtypv9ltogZ][/var/lib/elasticsearch/nodes/0] 
free: 4.5gb[11.4%], replicas will not be assigned to this node

1.节点iZuf6hn15mpmrtypv9ltogZ上的磁盘空间使用率超过了85%,空闲4.5gb,占总磁盘空间的11.4%。将不会在该节点上分配副本了。

This is a function of Elasticsearch. Per the Elasticsearch error, all indices on this node will marked read-only。

根据日志信息,提示是因为磁盘超过85%,磁盘空间到达85%时,es会将节点上面的索引标为只读,导致不能写入数据。

解决办法:

In short, Permanent fixes are;

1.Delete unused indices.
2.Merge segment using this SO answer.(https://stackoverflow.com/questions/60204556/optimize-api-for-reducing-the-segments-and-eliminating-es-deleted-docs-not-worki)
3.Attach external disk or increase the disk used by the problematic data node.
Solution 1.释放磁盘空间

Solution 2.

# /etc/elasticsearch/elasticsearch.yml

 (1) 调整磁盘空间比例(使用百分比或gb)
        cluster.routing.allocation.disk.watermark.low: 30g
        cluster.routing.allocation.disk.watermark.high: 20gb
  ( 2) 关闭阀值设置
        cluster.routing.allocation.disk.threshold_enabled: false

More information on this can be found here:https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-cluster.html#disk-based-shard-allocation

 

 

 

update Nest 6.0.2 to Nest 7.4.2,出现编译错误

SortField  not exsit

change SortField to FieldSort

Highlights not exist

change Highlights tos Highlight

 foreach (var h in hl.Value.Highlights)
                {
                    WriteLiteral(h);

                }

to
foreach (var h in hl.Value)
                {
                    WriteLiteral(h);

                }

 

change field map Name to RelationName

    /// <summary>
    /// 版本 es7.4.2
    /// </summary>
    [ElasticsearchType(IdProperty = "Id", Name = "F10FileContentModel")]
    public class F10FileContentModel
    {


to


    /// <summary>
    /// 版本 es7.4.2
    /// </summary>
    [ElasticsearchType(IdProperty = "Id", RelationName = "F10FileContentModel")]
    public class F10FileContentModel
    {

 

Elasticsearch Failed to start service in Ubuntu 18.04

step 1:

 wget http://localhost:9200

output

--2021-03-17 01:03:37--  (try:18)  http://localhost:9200/
Connecting to localhost (localhost)|127.0.0.1|:9200... failed: Connection refused.
Connecting to localhost (localhost)|::1|:9200... failed: Cannot assign requested address.
Retrying.

step 2:Restart elasticsearch.service

sudo journalctl -fu elasticsearch.service
sudo systemctl restart elasticsearch.service

output

# sudo journalctl -fu elasticsearch.service
-- Logs begin at Sat 2021-09-18 05:27:58 CST. --
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]: Error: Could not create the Java Virtual Machine.
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]: Error: A fatal exception has occurred. Program will exit.
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]:         at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]:         at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:81)
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]:         at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38)
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:135)
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[1671]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.java:86)
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Sep 19 00:01:12 iZuf6hn15mpmrtypv9ltogZ systemd[1]: Failed to start Elasticsearch.

 

step 3:check Elasticsearch log file

 

[email protected]:/var/log/elasticsearch
# ls -l
total 516
-rw-r--r-- 1 elasticsearch elasticsearch      0 Dec  2  2019 elasticsearch_audit.json
-rw-r--r-- 1 elasticsearch elasticsearch    782 Jan 27  2020 elasticsearch_deprecation.json
-rw-r--r-- 1 elasticsearch elasticsearch    360 Jan 27  2020 elasticsearch_deprecation.log
-rw-r--r-- 1 elasticsearch elasticsearch      0 Dec  2  2019 elasticsearch_index_indexing_slowlog.json
-rw-r--r-- 1 elasticsearch elasticsearch      0 Dec  2  2019 elasticsearch_index_indexing_slowlog.log
-rw-r--r-- 1 elasticsearch elasticsearch      0 Dec  2  2019 elasticsearch_index_search_slowlog.json
-rw-r--r-- 1 elasticsearch elasticsearch      0 Dec  2  2019 elasticsearch_index_search_slowlog.log
-rw-r--r-- 1 elasticsearch elasticsearch  18879 Mar 17 01:38 elasticsearch.log
-rw-r--r-- 1 elasticsearch elasticsearch  33774 Mar 17 01:38 elasticsearch_server.json
-rw-r--r-- 1 elasticsearch elasticsearch 448349 Mar 17 02:08 gc.log
-rw-r--r-- 1 elasticsearch elasticsearch   1464 Feb 10 23:36 gc.log.00
-rw-r--r-- 1 elasticsearch elasticsearch   3311 Mar 15 01:27 hs_err_pid1909.log

You can also check Elasticsearch log file, /var/log/elasticsearch/elasticsearch.log, for more details.

2021-03-17T01:22:59,227][INFO ][o.e.c.r.a.DiskThresholdMonitor] [iZuf6hn15mpmrtypv9ltogZ]
 low disk watermark [85%] exceeded on [d1FehlgHS-uj1BBQ09eIvQ][iZuf6hn15mpmrtypv9ltogZ][/var/lib/elasticsearch/nodes/0]
 free: 4.8gb[12.4%], replicas will not be assigned to this node

 

3. Elasticsearch Failed to start service in Ubuntu 18.04 -Could not create the Java Virtual Machine

 

step 1:The errors says Could not create the Java Virtual Machine

after using the command systemctl status elasticsearch.service I get the following error log:

# systemctl status elasticsearch.service

elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2021-09-19 00:28:51 CST; 5min ago
     Docs: https://www.elastic.co
  Process: 2078 ExecStart=/usr/share/elasticsearch/bin/systemd-entrypoint -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=1/FAILURE)
 Main PID: 2078 (code=exited, status=1/FAILURE)

Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]: Error: Could not create the Java Virtual Machine.
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]: Error: A fatal exception has occurred. Program will exit.
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]:         at org.elasticsearch.tools.launchers.JvmOption.flagsFinal(JvmOption.java:119)
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]:         at org.elasticsearch.tools.launchers.JvmOption.findFinalOptions(JvmOption.java:
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]:         at org.elasticsearch.tools.launchers.JvmErgonomics.choose(JvmErgonomics.java:38
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.jvmOptions(JvmOptionsPars
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd-entrypoint[2078]:         at org.elasticsearch.tools.launchers.JvmOptionsParser.main(JvmOptionsParser.jav
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
Sep 19 00:28:51 iZuf6hn15mpmrtypv9ltogZ systemd[1]: Failed to start Elasticsearch.

 

Failed to start service in Ubuntu 18.04 -Invalid NEST response built from a successful (404) low level call on HEAD

error on runing:

fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.Exception: Invalid NEST response built from a successful (404)
 low level call on POST: /wwwiaspnetcoreindex/_search?typed_keys=true
      # Audit trail of this API call:
       - [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.0061855
      # Request:
      <Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>
      # Response:
      <Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

Answers:

 

I think the message you see tells you everything.

System.Exception: Invalid NEST response built from a successful (404)
 low level call on POST: /wwwiaspnetcoreindex/_search?typed_keys=true

1.response built from a successful - elasticsearch call was successful,

2.but status 404 (not exists) was returned and mapped to existsResponse.Exists which is false in this case. There is no additional request/response information attached, this is why you see:

Request:
Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.
Response:
Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.

3. the HTTP Response from ES tells me that the index does not exist (404).

 

解决办法:

添加判断索引文件是否存在的代码

 

 

Useful links

1.low disk watermark [??%] exceeded on

https://stackoverflow.com/questions/33369955/low-disk-watermark-exceeded-on