Docker容器中的AWS Cloudwatch代理

nc1teljy  于 2023-06-21  发布在  Docker
关注(0)|答案(2)|浏览(132)

我正在尝试将Amazon Cloudwatch代理作为容器设置到我的Docker。这是一个OnPremise安装,因此它在本地运行,而不是在AWS Kubernetes或任何类似的东西中运行。
我已经设置了一个基本的dockerfile,agent.json和.aws/文件夹用于凭据,并使用docker-compose build实际设置它,然后启动它,但我遇到了不断的问题,因为Docker不包含或运行systemctl,所以我无法使用AWS自己的文档命令运行服务:

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json -s

当我尝试运行容器时,这将在错误时失败:

cloudwatch_1  | /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl: line 262: systemctl: command not found
cloudwatch_1  | unknown init system

我也试过在/bin中运行/start-amazon-cloudwatch-agent,但没有成功。没有关于此的文档。
基本上,问题是**我如何在前台将其作为服务或进程运行?”””任何人都有线索吗?否则容器就撑不住了。下面是我的代码:

dockerfile

FROM amazonlinux:2.0.20190508
RUN yum -y install https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
COPY agent.json /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json
CMD /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m onPremise -c file:/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json

agent.json

{
    "agent": {
        "metrics_collection_interval": 60,
        "region": "eu-west-1",
        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log",
        "debug": true
    }
}

.aws/文件夹包含配置和凭据,但我从来没有让代理真正尝试建立连接。

v09wglhw

v09wglhw1#

只需要使用官方图片docker pull amazon/cloudwatch-agent,它将为您处理所有的事情;参考号:here
如果您坚持使用自己的,请尝试以下操作:

FROM amazonlinux:2.0.20190508
RUN yum -y install https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
COPY agent.json  /opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json
ENV RUN_IN_CONTAINER=True
ENTRYPOINT ["/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent"]
zpqajqem

zpqajqem2#

使用AWS官方Docker镜像,这里是docker compose的示例

version: "3.8"
services:
  agent:
    image: amazon/cloudwatch-agent:1.247350.0b251814
    volumes:
      - ./config/log-collect.json:/opt/aws/amazon-cloudwatch-agent/bin/default_linux_config.json # agent config
      - ./aws:/root/.aws # required for authentication
      - ./log:/log # sample log
      - ./etc:/opt/aws/amazon-cloudwatch-agent/etc # for debugging the config of AWS of container

从上面的配置,只有前2卷同步所需的。编号3和4用于调试目的。
如果您有兴趣了解每个卷的功能,可以在https://medium.com/@gusdecool/setup-aws-cloudwatch-agent-on-premise-server-part-1-31700e81ab8上阅读更多内容

相关问题