Elastic Logging 插件使用示例
编辑Elastic Logging 插件使用示例编辑
以下示例展示了 Elastic Logging 插件的常见配置。
将 Docker 日志发送到 Elasticsearch编辑
Docker 运行命令
docker run --log-driver=elastic/elastic-logging-plugin:8.14.3 \ --log-opt hosts="myhost:9200" \ --log-opt user="myusername" \ --log-opt password="mypassword" \ -it debian:jessie /bin/bash
守护进程配置
{ "log-driver" : "elastic/elastic-logging-plugin:8.14.3", "log-opts" : { "hosts" : "myhost:9200", "user" : "myusername", "password" : "mypassword", } }
将 Docker 日志发送到 Elastic Cloud 上的 Elasticsearch 服务编辑
Docker 运行命令
docker run --log-driver=elastic/elastic-logging-plugin:8.14.3 \ --log-opt cloud_id="MyElasticStack:daMbY2VudHJhbDekZ2NwLmN4b3VkLmVzLmliJDVkYmQwtGJiYjs0NTRiN4Q5ODJmNGUwm1IxZmFkNjM5JDFiNjdkMDE4MTgxMTQzNTM5ZGFiYWJjZmY0OWIyYWE5" \ --log-opt cloud_auth="myusername:mypassword" \ -it debian:jessie /bin/bash
守护进程配置
{ "log-driver" : "elastic/elastic-logging-plugin:8.14.3", "log-opts" : { "cloud_id" : "MyElasticStack:daMbY2VudHJhbDekZ2NwLmN4b3VkLmVzLmliJDVkYmQwtGJiYjs0NTRiN4Q5ODJmNGUwm1IxZmFkNjM5JDFiNjdkMDE4MTgxMTQzNTM5ZGFiYWJjZmY0OWIyYWE5", "cloud_auth" : "myusername:mypassword", "output.elasticsearch.index" : "elastic-log-driver-%{+yyyy.MM.dd}" } }
指定自定义索引和模板编辑
Docker 运行命令
docker run --log-driver=elastic/elastic-logging-plugin:8.14.3 \ --log-opt hosts="myhost:9200" \ --log-opt user="myusername" \ --log-opt password="mypassword" \ --log-opt index="eld-%{[agent.version]}-%{+yyyy.MM.dd}" \ -it debian:jessie /bin/bash
守护进程配置
{ "log-driver" : "elastic/elastic-logging-plugin:8.14.3", "log-opts" : { "hosts" : "myhost:9200", "user" : "myusername", "index" : "eld-%{[agent.version]}-%{+yyyy.MM.dd}", "password" : "mypassword", } }