Osagie Anolu
Posted on November 28, 2024
Table of Contents
- Cloud Computing Fundamentals
- Amazon EC2 Basics
- AWS CLI Configuration
- Storage Services (EBS, S3)
- High Availability (ELB, Auto Scaling)
- Monitoring and File Systems
- Website Deployment
Cloud Computing Fundamentals
What is Cloud Computing?
Cloud computing provides on-demand computing resources over the internet with pay-as-you-go pricing. Key benefits include:
- Scalability
- Cost-effectiveness
- Global deployment
- Reduced maintenance
- High availability
Service Models
IaaS (Infrastructure as a Service)
├── Raw computing resources
├── Example: EC2, EBS
└── User manages OS and applications
PaaS (Platform as a Service)
├── Development and deployment platform
├── Example: Elastic Beanstalk
└── User focuses on code
SaaS (Software as a Service)
├── Complete application
├── Example: Gmail
└── User consumes service
Amazon EC2 Basics
EC2 Overview
EC2 (Elastic Compute Cloud) provides resizable compute capacity. Key features:
- Virtual servers (instances)
- Multiple instance types
- Various operating systems
- Pay-per-use pricing
EC2 Quick Start
# 1. Launch Instance
aws ec2 run-instances \
--image-id ami-12345678 \
--instance-type t2.micro \
--key-name MyKeyPair \
--security-group-ids sg-12345678
# 2. Configure Security Group
aws ec2 create-security-group \
--group-name MySecurityGroup \
--description "Basic web security group"
aws ec2 authorize-security-group-ingress \
--group-name MySecurityGroup \
--protocol tcp \
--port 80 \
--cidr 0.0.0.0/0
Instance Types
General Purpose (t2, t3)
├── Balanced CPU/Memory
└── Ideal for web servers
Compute Optimized (c5, c6)
├── High CPU performance
└── For processing-heavy tasks
Memory Optimized (r5, r6)
├── Fast memory performance
└── For database applications
AWS CLI Configuration
Installation
# Linux
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Configure AWS CLI
aws configure
AWS Access Key ID: [YOUR_ACCESS_KEY]
AWS Secret Access Key: [YOUR_SECRET_KEY]
Default region name: [YOUR_REGION]
Default output format: json
Basic CLI Commands
# List EC2 instances
aws ec2 describe-instances
# Create key pair
aws ec2 create-key-pair --key-name MyKeyPair
# List S3 buckets
aws s3 ls
Storage Services
EBS (Elastic Block Store)
Creating and Attaching EBS Volume
# Create volume
aws ec2 create-volume \
--size 100 \
--availability-zone us-east-1a \
--volume-type gp3
# Attach volume
aws ec2 attach-volume \
--volume-id vol-12345678 \
--instance-id i-12345678 \
--device /dev/sdf
EBS Snapshots
# Create snapshot
aws ec2 create-snapshot \
--volume-id vol-12345678 \
--description "Daily backup"
# Copy snapshot to another region
aws ec2 copy-snapshot \
--source-region us-east-1 \
--source-snapshot-id snap-12345678 \
--destination-region us-west-2
S3 (Simple Storage Service)
Bucket Operations
# Create bucket
aws s3 mb s3://my-unique-bucket-name
# Upload file
aws s3 cp myfile.txt s3://my-bucket/
# Configure static website hosting
aws s3 website s3://my-bucket/ \
--index-document index.html \
--error-document error.html
High Availability
ELB (Elastic Load Balancer)
Application Load Balancer Setup
# Create load balancer
aws elbv2 create-load-balancer \
--name my-load-balancer \
--subnets subnet-12345678 subnet-87654321 \
--security-groups sg-12345678
# Create target group
aws elbv2 create-target-group \
--name my-targets \
--protocol HTTP \
--port 80 \
--vpc-id vpc-12345678
Auto Scaling
Auto Scaling Group Configuration
# Create launch template
aws ec2 create-launch-template \
--launch-template-name WebServerTemplate \
--version-description WebServerVersion1 \
--launch-template-data '{
"ImageId": "ami-12345678",
"InstanceType": "t2.micro",
"SecurityGroupIds": ["sg-12345678"]
}'
# Create Auto Scaling group
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name my-asg \
--launch-template LaunchTemplateName=WebServerTemplate \
--min-size 2 \
--max-size 4 \
--desired-capacity 2 \
--vpc-zone-identifier "subnet-12345678,subnet-87654321"
Monitoring and File Systems
CloudWatch
Setting Up Monitoring
# Create alarm
aws cloudwatch put-metric-alarm \
--alarm-name cpu-monitor \
--alarm-description "CPU utilization monitor" \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--statistic Average \
--period 300 \
--threshold 70 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 2
# Create dashboard
aws cloudwatch put-dashboard \
--dashboard-name "WebServerMonitoring" \
--dashboard-body file://dashboard.json
EFS (Elastic File System)
EFS Setup
# Create file system
aws efs create-file-system \
--performance-mode generalPurpose \
--throughput-mode bursting
# Create mount target
aws efs create-mount-target \
--file-system-id fs-12345678 \
--subnet-id subnet-12345678 \
--security-group sg-12345678
Website Deployment
WordPress Deployment on EC2
1. Server Setup
#!/bin/bash
# Update system
sudo yum update -y
# Install LAMP stack
sudo yum install httpd mariadb-server php php-mysqlnd -y
# Start services
sudo systemctl start httpd
sudo systemctl start mariadb
sudo systemctl enable httpd
sudo systemctl enable mariadb
2. WordPress Installation
# Download WordPress
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
# Configure database
mysql -u root -p <<EOF
CREATE DATABASE wordpress;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EOF
# Move WordPress files
sudo cp -r wordpress/* /var/www/html/
sudo chown -R apache:apache /var/www/html/
3. WordPress Configuration
// wp-config.php
define('DB_NAME', 'wordpress');
define('DB_USER', 'wpuser');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
// Security keys
define('AUTH_KEY', 'unique-phrase-here');
define('SECURE_AUTH_KEY', 'unique-phrase-here');
define('LOGGED_IN_KEY', 'unique-phrase-here');
define('NONCE_KEY', 'unique-phrase-here');
Template Website on S3
1. Bucket Setup
# Create and configure bucket
aws s3 mb s3://my-template-website
aws s3 website s3://my-template-website \
--index-document index.html \
--error-document error.html
# Set bucket policy
aws s3api put-bucket-policy \
--bucket my-template-website \
--policy '{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-template-website/*"
}
]
}'
2. Website Deployment
# Download template
wget https://templatemo.com/tm-zip/[template-number]/templatemo_[template-number].zip
unzip templatemo_[template-number].zip
# Upload to S3
aws s3 sync ./template/ s3://my-template-website/
Integration and Security
1. Domain Configuration
# Create Route 53 record
aws route53 change-resource-record-sets \
--hosted-zone-id ZXXXXXXXXXXXXX \
--change-batch '{
"Changes": [{
"Action": "CREATE",
"ResourceRecordSet": {
"Name": "www.example.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z2FDTNDATAQYW2",
"DNSName": "s3-website-us-east-1.amazonaws.com",
"EvaluateTargetHealth": false
}
}
}]
}'
2. SSL Certificate
# Request certificate
aws acm request-certificate \
--domain-name www.example.com \
--validation-method DNS
# Add to CloudFront distribution
aws cloudfront create-distribution \
--origin-domain-name my-template-website.s3.amazonaws.com \
--default-root-object index.html
3. Backup Configuration
# Create backup script
#!/bin/bash
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
# Backup WordPress
aws s3 sync /var/www/html/ s3://backup-bucket/wordpress/$TIMESTAMP/
mysqldump wordpress > wp_backup_$TIMESTAMP.sql
aws s3 cp wp_backup_$TIMESTAMP.sql s3://backup-bucket/database/
# Backup template website
aws s3 sync s3://my-template-website/ s3://backup-bucket/template/$TIMESTAMP/
Monitoring Setup
1. CloudWatch Alarms
# CPU utilization alarm
aws cloudwatch put-metric-alarm \
--alarm-name high-cpu \
--alarm-description "CPU high utilization" \
--metric-name CPUUtilization \
--namespace AWS/EC2 \
--statistic Average \
--period 300 \
--threshold 80 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 2 \
--alarm-actions arn:aws:sns:region:account-id:topic-name
# Storage alarm
aws cloudwatch put-metric-alarm \
--alarm-name storage-space \
--alarm-description "Low storage space" \
--metric-name DiskSpaceUtilization \
--namespace System/Linux \
--statistic Average \
--period 300 \
--threshold 85 \
--comparison-operator GreaterThanThreshold \
--evaluation-periods 1
2. Logging Configuration
# Install CloudWatch agent
sudo yum install amazon-cloudwatch-agent -y
# Configure agent
cat > /opt/aws/amazon-cloudwatch-agent/bin/config.json <<EOF
{
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/httpd/access_log",
"log_group_name": "/aws/ec2/wordpress/access",
"log_stream_name": "{instance_id}"
},
{
"file_path": "/var/log/httpd/error_log",
"log_group_name": "/aws/ec2/wordpress/error",
"log_stream_name": "{instance_id}"
}
]
}
}
}
}
EOF
Maintenance Tasks
Daily Checks
#!/bin/bash
# Check system status
systemctl status httpd
systemctl status mariadb
# Check disk space
df -h
# Check logs
tail -n 100 /var/log/httpd/error_log
# Verify backups
aws s3 ls s3://backup-bucket/wordpress/$(date +%Y%m%d)/
Weekly Tasks
#!/bin/bash
# Update system
yum update -y
# Optimize database
mysqlcheck -o wordpress -u root -p
# Rotate logs
logrotate -f /etc/logrotate.d/httpd
# Clean temporary files
find /tmp -type f -atime +7 -delete
This comprehensive guide covers all major aspects of AWS services and website hosting. Each section provides practical, step-by-step instructions that can be followed sequentially or referenced as needed.
💖 💪 🙅 🚩
Osagie Anolu
Posted on November 28, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.