You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CloudWatch Agent未配置问题求助:自定义配置重启后被重置

解决CloudWatch Agent配置被重置为默认值的问题

核心原因

CloudWatch Agent的cloud-watch-agent.toml是自动生成文件,直接编辑后重启代理会被覆盖。代理优先读取config.json配置文件,若该文件无法被正确加载(路径错误、格式无效、权限不足),就会触发默认配置重置。

解决步骤

1. 验证config.json的合法性

首先检查配置文件的路径和格式:

  • 默认路径:/opt/aws/amazon-cloudwatch-agent/etc/config.json,确保文件存在
  • 用命令验证JSON格式:
    python -m json.tool /opt/aws/amazon-cloudwatch-agent/etc/config.json
    
    若输出格式化后的JSON则格式正常;若报错,根据提示修正语法错误(比如缺失逗号、引号不匹配、括号未闭合等)。

2. 确保配置文件权限正确

代理需要读取config.json的权限,执行以下命令设置:

sudo chmod 644 /opt/aws/amazon-cloudwatch-agent/etc/config.json
sudo chown root:root /opt/aws/amazon-cloudwatch-agent/etc/config.json

3. 使用官方命令导入配置并重启代理

不要直接编辑toml文件,用amazon-cloudwatch-agent-ctl命令导入config.json并重启代理:

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

参数说明:

  • -a fetch-config:导入配置
  • -m ec2:针对EC2实例环境
  • -c file:/path/to/config.json:指定本地配置文件路径
  • -s:启动/重启代理

4. 验证配置生效状态

  • 查看代理状态:
    sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
    
    输出中若显示status: running且config status: configured,说明配置加载成功。
  • 查看代理日志确认:
    grep "Successfully fetched the config" /opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log
    
    若有匹配日志,证明配置已成功导入并生成正确的toml文件。

内容的提问来源于stack exchange,提问作者Nirmal Negi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 07:08:19