Contents

Install the CloudWatch Agent on Amazon Linux 2018

Install the CloudWatch Agent on Amazon Linux 2018

Befor start ๐Ÿ

  • we should need to create IAM Role with “CloudWatchAgentServerPolicy” Policy.

  • This Role should be attach with EC2 before start working.

Download the CloudWatch Agent Package ๐Ÿ•ต๐Ÿผ

First we need to download the agent on Amazon Linux 2018 Linux machine.

  • SSH into your Amazon Linux instance.

  • Download the CloudWatch Agent package from AWS S3:

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

Install the CloudWatch Agent: ๐Ÿ› ๏ธ

  • Install the downloaded package using the rpm command

    sudo rpm -U ./amazon-cloudwatch-agent.rpm
    

Configure the CloudWatch Agent: โš™๏ธ

  • Run the configuration wizard to set up the CloudWatch Agent

    sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
    
  • Follow the prompts to configure the agent. You’ll be asked about the type of metrics/logs you want to monitor, destination region, etc. https://github.com/yahyagulshan/linuxnotes/assets/59036269/bd9ac642-7a1d-414f-9b87-c47fec7e2c0b https://github.com/yahyagulshan/linuxnotes/assets/59036269/783f31ab-daf7-41ec-aca0-a48f81793f91 https://github.com/yahyagulshan/linuxnotes/assets/59036269/32dc71a9-ab19-4c88-94bd-824ffc88ebc6 https://github.com/yahyagulshan/linuxnotes/assets/59036269/1ab7a6a4-5172-4e37-b7de-c0b52730f9cf

Start the CloudWatch Agent: ๐Ÿš€

  • After configuring the agent, start it

    sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s
    

https://github.com/yahyagulshan/linuxnotes/assets/59036269/217f9c02-b588-4c93-9aca-048d804343c7

Verify Configuration: ใ€Œโœ” แต›แต‰สณแถฆแถ แถฆแต‰แตˆใ€

  • Verify that the CloudWatch Agent is running and sending metrics/logs to CloudWatch

    sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status
    

https://github.com/yahyagulshan/linuxnotes/assets/59036269/1d335783-6f48-4a6f-80a1-22813f37099a

Next step is Optional Automatically Start on Boot (Optional):

  • To ensure the CloudWatch Agent starts automatically on boot, enable it as a service

    sudo systemctl enable amazon-cloudwatch-agent
    

Access CloudWatch Metrics and Logs: ๐Ÿ“Š

  • Once the agent is running, you can access the metrics and logs in the AWS CloudWatch console.

  • That’s it! You’ve successfully installed and configured the CloudWatch Agent on your Amazon Linux 2018 instance. Make sure to customize the configuration as per your monitoring requirements.