Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retain apache logs in EC2 when using AWS auto-scaling

We have built a website using AWS EC2 and auto-scaling in a typical LAMP stack (ubuntu).

Scaling etc works well, however, since the instances are "temporary" our apache logs are not retained (as we do not retain the volumes or instances) after load spikes.

Is there a "best practise / most reliable" way to retain our apache logs for these instances?

One idea was to copy log files to S3, during shutdown, by writing a bash script to execute using the /etc/rc0.d functionality (running a script on shutdown).

like image 587
BoomShaka Avatar asked Jul 09 '13 14:07

BoomShaka


People also ask

How do I check Auto Scaling logs?

The information is presented in two ways: on a dashboard that shows recent and upcoming events organized by category, and in a full event log that shows all events from the past 90 days. For more information, see AWS Health Dashboard notifications for Amazon EC2 Auto Scaling. CloudWatch alarms.

How does Auto Scaling work on EC2?

Amazon EC2 Auto Scaling enables you to follow the demand curve for your applications closely, reducing the need to manually provision Amazon EC2 capacity in advance. For example, you can use target tracking scaling policies to select a load metric for your application, such as CPU utilization.

How do I enable EC2 instance logs?

To configure your IAM role or user for CloudWatch LogsOpen the IAM console at https://console.aws.amazon.com/iam/ . In the navigation pane, choose Roles. Choose the role by selecting the role name (do not select the check box next to the name). Choose Attach Policies, Create Policy.


1 Answers

The "best practice" would be to aggregate all your logs on a server that allows you to archive and search them. You could back up older logs in S3 and eventually Glacier.

To make all of this work, you'll need to set up apache to write hourly or minutely logs and write a cronjob to rsync them to some central place or upload them to S3.

Check out http://logstash.net/ for an open-source aggregation & search solution you could run on your own instance and http://loggly.com/ for a non-free fully-hosted solution.

EDIT: My first thought was "don't do it on shutdown." You'll want to sync your log files as regularly as possible and as a result (if you do minutely logs, for example) you get "near realtime" log aggregation/backup and search.

like image 76
rdrey Avatar answered Sep 20 '22 05:09

rdrey