Filebeat 输出日志到 Opensearch
这个最后基本上可以确认是一个兼容性问题,测试完成发现, 开启兼容模式的Opensearch+filebeat的组合, filebeat 还是会不定期重启。
背景
需求是,使用ES + filebeat 模式在收集日志。
使用Supervisor作为容器的主进程管理工具,启动后分别运行 应用(这里用nginx代替) + filebeat
现在想要用ECS Fargate, 然后依旧还是这个模式, 尽可能新的变动之前的架构, ES 替换成 OpenSearch。
按照这个路数测试。
创建Opensearch
版本:
OpenSearch 2.11 (latest)
OpenSearch_2_11_R20231113-P1 (latest)
Availability Zone(s)
1-AZ without standby
构建Supervisor管理的容器
创建 Dockerfile
创建dockerfile的部分, 比较难的是 , 需要找到合适的filebeat版本
参考页面: Agents and ingestion tools
其他的步骤就下载安装就可以.
1 | # 使用官方Nginx作为基础镜像 |
准备配置文件
需要准备的配置文件一共3个:
- supervisord.conf supervisor的管理配置, 决定了那些进程被管理。
1 | cat ./supervisord.conf |
filebeat.yml filebeat的配置文件。 这配置文件 GPT 会直接写出一个可以用
output.opensearch:, 其实还是不能的, 只能使用原本的配置文件。 (也许是我选择的filebeats版本不正确, 所以不行吧filebeat本身是es序列里面的产品, 不支持opensearch也合理, 如果写成opensearch 会找不到output 的定义, 也说明并不支持这个字段。
2023-12-14T12:03:12.560Z INFO [publisher_pipeline_output] pipeline/output.go:145 Attempting to reconnect to backoff(elasticsearch(https://vpc-ecs-nginx-opensearch-qt7m5rmhddggkiuapyybcmz5oe.cn-north-1.es.amazonaws.com.cn:443)) with 7 reconnect attempt(s)
1 | ```shell |
xpack 报错的日志大概是这样的:
2023-12-14T12:03:12.560Z ERROR [publisher_pipeline_output] pipeline/output.go:154 Failed to connect to backoff(elasticsearch(https://vpc-ecs-nginx-opensearch-qt7m5rmhddggkiuapyybcmz5oe.cn-north-1.es.amazonaws.com.cn:443)): Connection marked as failed because the onConnect callback failed: request checking for ILM availability failed: 401 Unauthorized: {“Message”:”Your request: ‘/_xpack’ is not allowed.”}
2023-12-14T12:03:12.560Z INFO [publisher_pipeline_output] pipeline/output.go:145 Attempting to reconnect to backoff(elasticsearch(https://vpc-ecs-nginx-opensearch-qt7m5rmhddggkiuapyybcmz5oe.cn-north-1.es.amazonaws.com.cn:443)) with 7 reconnect attempt(s)
- nginx.conf 这个是nginx 应用文件, 模拟一个应用程序, 提供webserver服务。配置文件就是标准的配置文件, 修改一下日志输出的路径.
1 | access_log /var/log/access.log main; |
由于baseimage用的是nginx的, 所以nginx 的日志输出会软链接到/dev/stdout, filebeat 不收软链接的文件, 开了DEBUG会看到跳过这个文件的日志.
Buildstage
接下来就可以Build镜像然后进行测试了。
1 | dive build -t reg.liarlee.site/library/superv-nginx:v31 . |
运行启动之后可以看到输出的日志是:
1 | 2023-12-14 14:03:31,093 INFO success: filebeat entered RUNNING state, process has stayed up for > than 1 seconds (startsecs) |
然后查看Opensearch 创建了默认index, 名称是filebeat-7.12.1-2023.12.14
放到 Ecs 里面去
我直接使用我自己的仓库里面拉取了 ,创建ecs service然后curl请求发送到 alb , 转给 task。
观察opensearch中收集的访问日志。


