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

相关资料

相关推荐
vortex515 小时前
Shell脚本技巧:去除文件中字符串两端空白
linux·bash·shell·sed·awk
world-wide-wait16 小时前
python高级04——网络编程
linux·服务器·网络
迎風吹頭髮16 小时前
Linux内核架构浅谈26-Linux实时进程调度:优先级反转与解决方案
linux·服务器·架构
yumgpkpm16 小时前
大数据综合管理平台(CMP)(类Cloudera CDP7.3)有哪些核心功能?
hive·hadoop·elasticsearch·zookeeper·big data
Java 码农16 小时前
CentOS 7上安装SonarQube10
linux·centos
特种加菲猫16 小时前
网络协议分层:解密TCP/IP五层模型
linux·网络·笔记
Zhsh-716 小时前
centos配置ES和MYSQL自动备份
mysql·elasticsearch·centos
平平无奇。。。16 小时前
版本控制器之Git理论与实战
linux·git·gitee·github
一键三联啊16 小时前
【GIT】错误集锦及解决方案
大数据·elasticsearch·搜索引擎
宇宙第一小趴菜16 小时前
11 安装回忆相册
linux·运维·centos7·yum·回忆相册·kh_mod