本文假设您已经安装并配置好Elasticsearch、Kibana、Docker,且安全组都已OK。
参考文档:
阿里云官网文档:https://help.aliyun.com/document_detail/50441.html
阿里云开源log-pilot GitHub地址:https://github.com/AliyunContainerService/log-pilot/blob/master/docs/filebeat/docs.md
PILOT_TYPE=filebeat
docker run -d -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/localtime:/etc/localtime \
-v /:/host:ro \
--cap-add SYS_ADMIN \
-e LOGGING_OUTPUT=elasticsearch \
-e ELASTICSEARCH_HOST=${ELASTICSEARCH_HOST} \
-e ELASTICSEARCH_PORT=${ELASTICSEARCH_PORT} \
registry.cn-hangzhou.aliyuncs.com/acs/log-pilot:0.9.5-filebeat
配置参数详解
ELASTICSEARCH_HOST "(required) elasticsearch host"
ELASTICSEARCH_PORT "(required) elasticsearch port"
ELASTICSEARCH_USER "(optinal) elasticsearch authentication username"
ELASTICSEARCH_PASSWORD "(optinal) elasticsearch authentication password"
ELASTICSEARCH_PATH "(optinal) elasticsearch http path prefix"
ELASTICSEARCH_SCHEME "(optinal) elasticsearch scheme, default is http"
以java应用为例
docker run -d -p 80:8080
-v /root/docker-log-demo.jar:/root/docker-log-demo.jar \
-v /root/docker-log-demo/logs \
--label aliyun.logs.cloud-algorithm=/root/docker-log-demo/logs/*.log \
--label aliyun.logs.cloud-algorithm.target=cloud-algorithm-index-index \
--name docker-log-demo java:8u111 java -jar /root/docker-log-demo.jar
以算法为例
docker run -it
--restart always
--name graph-logs -p 7003:7001
--env APP_CONFIG_FILE=/app/config/app_config_test.py --env LANG=zh_CN.UTF-8
-v /app/logs/app/graph \
--label aliyun.logs.cloud-algorithm=/app/logs/app/graph/*.log \
--label aliyun.logs.cloud-algorithm.target=cloud-algorithm-index \ graph:v20191120 /bin/bash -c "gunicorn --chdir /app -c /app/gunicorn-docker.py main:app "
详解:
在运行容器镜像启动命令中添加主要配置3行,参考:https://help.aliyun.com/document_detail/50441.html#h2-url-4
-v /root/docker-log-demo/logs \
--label aliyun.logs.cloud-algorithm=/root/docker-log-demo/logs/*.log \
--label aliyun.logs.cloud-algorithm.target=cloud-algorithm-index-index \
-v 之后必须为容器内部服务生成日志的内部绝对路径
–label 强制为 aliyun.logs. 开头,后面为自定义 name,后面指定要收集的日志
target参数为ES中的 index