EC2 Ubuntu instance stops working everyday

0

Hello I am using free tier AWS EC2 Ubuntu instance which stops responding everyday there are no issue with status checks and instance shows running. i am unable to access my ssh terminal & websites inside EC2 i need to restart instance to fix this every time.

My system consist of apache, phpmyadmin &mysql and node js and i am running 2 website which doesn't have much audience because its in testing mode . please let me what is wrong .

3 Answers
2

It's hard to troubleshoot this issue without more details, but here are a few steps you can take to investigate:

  1. Analyze Logs: Check system and application logs for clues. On an Ubuntu EC2 instance:

    • System logs: /var/log/syslog or /var/log/dmesg for any kernel or hardware-related issues.
    • Apache logs: /var/log/apache2/ for web server issues.
    • MySQL logs: /var/log/mysql/ for database errors.
  2. Check Resource Usage: Your instance may be running out of memory or CPU. Use htop or free -m to monitor resources.

  3. Security Groups: Ensure your security group rules haven't changed, preventing access to the instance via SSH or HTTP/S.

  4. Instance Size: The free tier offers limited resources, and even though your websites are in testing, running Apache, PHPMyAdmin, MySQL, and Node.js can be resource-heavy. Consider upgrading your instance type.

  5. AWS Support: If you continue to face issues, consider cutting a ticket with AWS support for deeper analysis.

These steps should help you troubleshoot further!

AWS
emned
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
1

Sounds like the usual out of memory issue. I have seen this before when a EC2 doesnt have enough memory it dies eventually. I suggest increasing the instance size.

If you install the cloudwatch agent it will upload the memory metrics of which you can track in cloudwatch and check it is a memory issue. https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance.html

profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
0

You mention you're using free tier, which means you must be using a t2.micro or t3.micro instance, which are pretty low-spec. And you're running rather a lot - 2 apache websites, phpmyadmin, mysql and node.js - on such a low-powered instance that it's not a surprise to hear that it's running fine at the start, but slowly consumes more and more resources until you can't login any more (it will still show up as running and 2/2 checks passed in AWS Console as it's still actually running, though unusable).

Additionally t2.micro has only 1GB of memory, if you're is trying to use more memory than is available then the memory manager comes into play, and will try to swap processes out of main memory and onto disk (it's more complicated, but that's the general gist of it). This in itself is CPU-intensive, and as free memory gets less and less the memory manager will spend more and more of its time (and more and more CPU) trying to free up pages of main memory, leaving fewer and fewer CPU cycles for anything else (including handling SSH requests for login).

Unfortunately the EC2 section of the AWS Console doesn't display metrics for memory use, you'll need to setup CloudWatch agent to collect these https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html

If it turns out to be lack of memory, it may be beneficial to add a swap file https://repost.aws/knowledge-center/ec2-memory-swap-file

Uplifting the EC2 instance type to one with more resources could also be an option for you https://aws.amazon.com/ec2/instance-types/

Although you are currently on free tier, uplifting to an instance type outside of free tier will mean you start paying for something you previously got for free.

profile picture
EXPERT
Steve_M
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions