AWS Linux 1
install
wget <https://amazoncloudwatch-agent.s3.amazonaws.com/centos/amd64/latest/amazon-cloudwatch-agent.rpm>
sudo rpm -U ./amazon-cloudwatch-agent.rpm
add service
$ sudo vi /etc/init.d/amazon-cloudwatch-agent
#! /bin/bash
### BEGIN INIT INFO
# Provides: amazon-cloudwatch-agent
# Required-Start: $local_fs $network
# Required-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: amazon-cloudwatch-agent service
# Description: Run amazon-cloudwatch-agent service
### END INIT INFO
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting amazon-cloudwatch-agent..."
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start
;;
stop)
echo "Stopping amazon-cloudwatch-agent..."
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop
sleep 2
;;
*)
echo "Usage: /etc/init.d/amazon-cloudwatch-agent {start|stop}"
exit 1
;;
esac
exit 0
# 파일 권한 변경
$ sudo chmod 766 /etc/init.d/amazon-cloudwatch-agent
# 서비스 등록
$ sudo chkconfig --add amazon-cloudwatch-agent
# 서비스 자동 시작
$ sudo chkconfig amazon-cloudwatch-agent on
# 시작
$ sudo service amazon-cloudwatch-agent start
AWS Linux 2 or 2023
install
$ sudo yum install amazon-cloudwatch-agent
Start
# 자동으로 서비스 생성됨
$ sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s
# 자동시작
$ sudo systemctl enable amazon-cloudwatch-agent
Status