In this tutorial, we'll walk through the process of setting up Grafana on an AWS EC2 instance. Grafana is a popular open-source platform for monitoring and observability, and AWS EC2 provides a reliable and scalable infrastructure for hosting it.
Prerequisites
An AWS account with EC2 access
Basic understanding of Linux commands
SSH access to your instance
Step 1: Launch an EC2 Instance
First, we need to set up our EC2 instance:
Log into AWS Console and navigate to EC2
Launch a new instance with these specifications:
Ubuntu Server 24.04 LTS AMI
t2.medium instance type (for better performance)
Configure security group with the following rules:
SSH (Port 22)
HTTP (Port 80)
Custom TCP (Port 3000) for Grafana
Step 2: Configure Security Groups
Security group configuration is crucial for allowing proper access to your Grafana instance:
Create or modify security group rules to allow:
Inbound SSH access (port 22)
Inbound HTTP access (port 80)
Inbound Custom TCP on port 3000 (Grafana's default port)
Any additional ports needed for your data sources
Step 3: Install Grafana
Connect to your EC2 instance via SSH and follow these steps to install Grafana:
# Update the system
sudo apt-get update
# Add Grafana GPG key
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
# Add Grafana repository
sudo add-apt-repository "deb https://packages.grafana.com/oss/deb stable main"
# Update package list
sudo apt-get update
# Install Grafana
sudo apt-get install grafana -y
Step 4: Start and Enable Grafana Service
After installation, we need to start and enable the Grafana service:
# Start Grafana
sudo systemctl start grafana-server
# Enable Grafana to start on boot
sudo systemctl enable grafana-server
# Verify the service status
sudo systemctl status grafana-server
Step 5: Access Grafana Web Interface
Once Grafana is running, you can access it through your web browser:
Open your web browser
Navigate to
http://your-ec2-public-ip:3000
You'll see the Grafana login page
Default credentials are:
Username: admin
Password: admin
Step 6: Initial Setup
After your first login:
Change the default admin password when prompted
You'll be taken to the Grafana home dashboard
From here, you can:
Add data sources
Create dashboards
Configure alerts
Manage users and permissions
Key Features Available After Setup
Data Sources: Add your preferred data sources such as:
Prometheus
InfluxDB
Elasticsearch
CloudWatch
And many more
Dashboards: Create custom dashboards or import pre-built ones
Visualization options
Real-time monitoring
Custom metrics
Alerting: Set up alerts based on your metrics
Multiple notification channels
Custom alert rules
Alert history
Best Practices and Security Considerations
Security:
Change default admin password immediately
Use HTTPS for production environments
Implement proper authentication methods
Regularly update Grafana
Performance:
Monitor system resources
Optimize dashboard queries
Use appropriate EC2 instance size
Backup:
Regular backup of Grafana configurations
Database backup if using internal database
Document all custom configurations
Troubleshooting Tips
If you can't access Grafana:
Check EC2 security group settings
Verify Grafana service status
Check instance public IP address
Review Grafana logs:
sudo journalctl -u grafana-server
Common issues:
Port 3000 not accessible
Database connection issues
Plugin compatibility problems
Conclusion
You now have a fully functional Grafana installation running on AWS EC2. This setup provides a solid foundation for building your monitoring and visualization infrastructure. Remember to regularly update both your EC2 instance and Grafana installation to ensure security and stability.
For more advanced configurations and optimizations, refer to the official Grafana documentation which provides detailed information about various features and capabilities.