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

相关资料

相关推荐
sunxunyong7 小时前
CGroup配置
linux·运维·服务器
hy____1237 小时前
Linux_网络编程套接字
linux·运维·网络
若风的雨8 小时前
【deepseek】 Linux 调度延时分析
linux
2301_803554528 小时前
linux 以及 c++编程里对于进程,线程的操作
linux·运维·c++
LuDvei8 小时前
windows 中 vs code远程连接linux
linux·运维·服务器·windows
GDAL9 小时前
MANIFEST.in简介
linux·服务器·前端·python
点点滴滴的记录9 小时前
Redis部署在Linux上性能高于Windows
linux·数据库·redis
蜕变的小白9 小时前
基于Linux的天气查询项目
linux·运维·服务器
卤炖阑尾炎9 小时前
Linux firewalld 防火墙从入门到精通:原理与配置全解析
linux·运维·php
小云数据库服务专线9 小时前
linux grep命令
linux·运维·服务器