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

相关资料

相关推荐
顺风尿一寸1 天前
Java Socket 内核之旅:从 SocketChannel.read() 到 tcp_recvmsg 与 epoll 的完整调用链路
linux
XIAOHEZIcode1 天前
Ubuntu 终端美化全栈指南:Bash 到 Kitty 踩坑实录
linux·ubuntu·命令行
唐青枫1 天前
别再只会用 cron:Linux systemd Timer 定时任务实战详解
linux
AlfredZhao3 天前
生产环境里,为什么不建议把普通端口直接暴露到公网?
linux·https·443·80
武子康4 天前
调查研究-197 FAISS vs Elasticsearch 全面对比:从向量检索、全文搜索到 RAG 选型指南
人工智能·elasticsearch·agent
戴为沐4 天前
Linux内存扩容指南
linux
zylyehuo5 天前
Linux 彻底且安全地删除文件
linux
用户805533698035 天前
主线 U-Boot 上 RK3506:和闭源 rkbin 拔河的三个隐性契约
linux·嵌入式
Elasticsearch5 天前
Elasticsearch ES|QL:现已支持视图、子查询和读取时模式定义
elasticsearch
用户034095297915 天前
linux fcitx 5 雾凇拼音 设置在中文输入法下仍然输入英文标点
linux