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

相关资料

相关推荐
光而不耀@lgy1 小时前
C++初登门槛
linux·开发语言·网络·c++·后端
偶尔微微一笑1 小时前
AI网络渗透kali应用(gptshell)
linux·人工智能·python·自然语言处理·编辑器
Run1.1 小时前
深入解析 Linux 中动静态库的加载机制:从原理到实践
linux·运维·服务器
The Mr.Nobody1 小时前
STM32MPU开发之旅:从零开始构建嵌入式Linux镜像
linux·stm32·嵌入式硬件
老兵发新帖2 小时前
Ubuntu 上安装 Conda
linux·ubuntu·conda
秋秋秋秋秋雨2 小时前
linux安装单节点Elasticsearch(es),安装可视化工具kibana
linux·elasticsearch·jenkins
码农hbk2 小时前
linux ptrace 图文详解(七) gdb、strace跟踪系统调用
linux·服务器
hotlinhao3 小时前
ThinkPHP6模型中多组条件逻辑或Or查询的使用
linux·服务器·数据库
Jogging-Snail3 小时前
从零开始掌握Linux数据流:管道与重定向完全指南
linux·运维·管道·重定向·linux 数据流·管道原理
jack xu13 小时前
高频面试题:如何保证数据库和es数据一致性
java·大数据·数据库·mysql·elasticsearch