ElasticSearch的日志配置

ElasticSearch默认情况下使用Log4j2来记录日志,日志配置文件的路径为$ES_HOME/config/log4j2.properties,配置方法见Log4j2官方文档

参考path-settings,通过指定path.logs,可以指定日志文件的保存路径。

在日志配置文件$ES_HOME/config/log4j2.properties中可以使用的变量,如下:

  • es.logs.base_path,指的是日志文件的根路径。
  • es.logs.cluster_name,指的是集群的名称。
  • es.logs.node_name,指的是节点的名称。

按照log4j2的配置规范,上述变量在日志配置文件log4j2.properties中引用时,使用方法如下:

  • ${sys:es.logs.base_path}
  • ${sys:es.logs.cluster_name}
  • ${sys:es.logs.node_name}

配置日志级别的方法,分为:

  • 运行期配置,修改后即时生效,不需要重启服务。
  • 静态配置,修改后需要重启才能生效。

运行期配置

  • 查看当前配置。

    shell 复制代码
    curl -X GET "https://localhost:9200/_cluster/settings?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"

    执行结果如下:

    shell 复制代码
    {
    "persistent" : { },
    "transient" : { }
    }
  • 指定logger.org.elasticsearch.discovery的日志级别为DEBUG

    shell 复制代码
    curl -X PUT "https://localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
    {
        "persistent": {
            "logger.org.elasticsearch.discovery": "DEBUG"
        }
    }
    ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"

    执行输出如下:

    shell 复制代码
    {
    "acknowledged" : true,
    "persistent" : {
        "logger" : {
        "org" : {
            "elasticsearch" : {
            "discovery" : "DEBUG"
            }
        }
        }
    },
    "transient" : { }
    }
  • 查看配置结果。

    shell 复制代码
    curl -X GET "https://localhost:9200/_cluster/settings?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"

    执行结果如下:

    shell 复制代码
    {
    "persistent" : {
        "logger" : {
        "org" : {
            "elasticsearch" : {
            "discovery" : "DEBUG"
            }
        }
        }
    },
    "transient" : { }
    }
  • 恢复logger.org.elasticsearch.discovery的日志级别。

    shell 复制代码
    curl -X PUT "https://localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
    {
    "persistent": {
        "logger.org.elasticsearch.discovery": null
    }
    }
    ' --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"

    执行结果如下:

    shell 复制代码
    {
    "acknowledged" : true,
    "persistent" : { },
    "transient" : { }
    }
  • 查看当前配置。

    shell 复制代码
    curl -X GET "https://localhost:9200/_cluster/settings?pretty" --cacert $ES_HOME/config/certs/http_ca.crt -u "elastic:ohCxPH=QBE+s5=*lo7F9"

    执行结果如下:

    shell 复制代码
    {
    "persistent" : { },
    "transient" : { }
    }

静态配置

修改配置文件elasticsearch.yml,增加如下配置:

yaml 复制代码
logger.org.elasticsearch.discovery: DEBUG

或者修改日志配置文件log4j2.properties,增加如下配置:

properties 复制代码
logger.discovery.name = org.elasticsearch.discovery
logger.discovery.level = debug

相关资料

相关推荐
chlk12315 小时前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑15 小时前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件16 小时前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
深紫色的三北六号1 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash1 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
哈基咪怎么可能是AI2 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github
十日十行2 天前
Linux和window共享文件夹
linux
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
木心月转码ing3 天前
WSL+Cpp开发环境配置
linux