启动时启动Bootstrap EC2实例以安装awslogs

时间:2018-10-19 18:06:31

标签: amazon-cloudformation

我正在尝试将以下脚本实施到Launchtemplate中,以启动已安装并准备好awslogs的EC2实例:

    UserData:
      "Fn::Base64": !Sub >-
          #!/bin/bash -xe
          yum install -y aws-cfn-bootstrap
          /opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource BastionHostLaunchtemplate --region ${AWS::Region}
          # Install the CloudWatch Logs agent
          yum -y install awslogs
          service awslogs start
          chkconfig awslogs on

但是当我之后通过SSH连接到实例并检查是否得到此信息时:

 [ec2-user@ip-172-16-47-249 ~]$ sudo service awslogsd status
 Redirecting to /bin/systemctl status awslogsd.service
 Unit awslogsd.service could not be found.
 [ec2-user@ip-172-16-47-249 ~]$

如何正确引导EC2实例?

merci A

1 个答案:

答案 0 :(得分:1)

这几天,您应该使用 CloudWatch代理,它已取代了CloudWatch Logs代理(awslogs)。

wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm

yum install amazon-cloudwatch-agent.rpm

/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:configuration-file-path -s

请参阅:Getting Started: Installing the CloudWatch Agent on Your First Instance - Amazon CloudWatch