Linux⭐ Featuredguide

AWS EC2 Instanzen einrichten – Grundlagen 2025

Von der ersten EC2-Instanz zum produktiven Server

S
SeeColors IT
11. Juni 20264 Min. Lesezeit605 Aufrufe

EC2 Instance-Typen

Familie Optimiert für Beispiel
t3/t4g Allgemein (Burst) t3.micro, t4g.small
m6i/m7i Allgemein (balanced) m6i.large, m7i.xlarge
c6i/c7i CPU-intensiv c6i.2xlarge
r6i/r7i RAM-intensiv r6i.large (RAM-optimiert)
g4dn/g5 GPU g4dn.xlarge (NVIDIA T4)
i3en Storage-intensiv i3en.xlarge (NVMe)

Für KMU: t3.small bis m6i.large abdeckt 90% der Anwendungsfälle.

Erste EC2-Instanz starten (AWS CLI)

# AWS CLI installieren
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip && sudo ./aws/install

# Konfigurieren
aws configure
# AWS Access Key ID: [Ihr Key]
# AWS Secret Access Key: [Ihr Secret]
# Default region name: eu-central-1
# Default output format: json

# AMI ID für Ubuntu 24.04 (eu-central-1)
aws ec2 describe-images     --owners 099720109477     --filters "Name=name,Values=ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*"     --query 'Images | sort_by(@, &CreationDate) | [-1].ImageId'     --output text

# Key Pair erstellen
aws ec2 create-key-pair     --key-name mein-key     --query 'KeyMaterial'     --output text > ~/.ssh/mein-key.pem
chmod 400 ~/.ssh/mein-key.pem

# Security Group
aws ec2 create-security-group     --group-name web-sg     --description "Web Server Security Group"

# SSH und HTTP erlauben
aws ec2 authorize-security-group-ingress     --group-name web-sg     --protocol tcp --port 22 --cidr 0.0.0.0/0

aws ec2 authorize-security-group-ingress     --group-name web-sg     --protocol tcp --port 80 --cidr 0.0.0.0/0

# Instanz starten
aws ec2 run-instances     --image-id ami-0a628e1e89aaedf80     --instance-type t3.small     --key-name mein-key     --security-groups web-sg     --count 1     --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=web-server-01}]'

Instanz verwalten

# Alle Instanzen anzeigen
aws ec2 describe-instances     --filters "Name=tag:Name,Values=web-server-01"     --query 'Reservations[].Instances[].{ID:InstanceId,State:State.Name,IP:PublicIpAddress}'

# Per SSH verbinden
ssh -i ~/.ssh/mein-key.pem ubuntu@<PUBLIC_IP>

# Instanz stoppen/starten/beenden
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
aws ec2 start-instances --instance-ids i-1234567890abcdef0
aws ec2 terminate-instances --instance-ids i-1234567890abcdef0

User Data (Cloud-Init beim Start)

# EC2 beim ersten Start konfigurieren
cat > userdata.sh << 'EOF'
#!/bin/bash
apt update && apt install -y nginx
systemctl enable --now nginx
echo "Hello from EC2!" > /var/www/html/index.html
EOF

aws ec2 run-instances     --image-id ami-0a628e1e89aaedf80     --instance-type t3.small     --key-name mein-key     --user-data file://userdata.sh

EBS Volumes (persistenter Speicher)

# Volume erstellen
aws ec2 create-volume     --availability-zone eu-central-1a     --size 50     --volume-type gp3     --encrypted

# Volume anhängen
aws ec2 attach-volume     --volume-id vol-0123456789abcdef0     --instance-id i-1234567890abcdef0     --device /dev/sdf

# In der Instanz: Volume formatieren und mounten
sudo mkfs.ext4 /dev/sdf
sudo mkdir /data && sudo mount /dev/sdf /data
echo '/dev/sdf /data ext4 defaults 0 2' | sudo tee -a /etc/fstab

EC2 Spot Instances (70-90% günstiger)

# Spot Instance anfragen (für unterbrechbare Workloads)
aws ec2 request-spot-instances     --instance-count 1     --type one-time     --launch-specification     '{"ImageId":"ami-0a628e1e89aaedf80","InstanceType":"m6i.large","KeyName":"mein-key"}'

FAQ

Was ist der Unterschied zwischen Stop und Terminate?
Stop: Instanz bleibt erhalten (EBS-Daten bleiben), IP ändert sich beim Restart. Terminate: Instanz und Instance-Store-Daten werden gelöscht.

Wie viel kostet eine t3.small Instanz?
t3.small (2 vCPU, 2 GB RAM) in eu-central-1: ca. 0,023 USD/Stunde, ~16 USD/Monat.

Fazit

AWS EC2 ist flexibel und skalierbar. Für KMU empfehlen wir den Start mit t3-Instanzen und schrittweise Optimierung nach echten Workload-Messungen.

AWS Cloud-Beratung für KMU in Heidelberg, Mannheim und der Rhein-Neckar-Region. Anfragen.

Artikel teilen

War dieser Artikel hilfreich?

Dein Feedback hilft uns, bessere Inhalte zu erstellen.

Kommentar hinterlassen

Verwandte Artikel