Post

Optimize 1C1G Cloud Server (A Practical, Proven Guide)

Running a cloud server with 1 CPU and 1GB RAM is common for personal projects, landing pages, and small websites. However, default Ubuntu installations are not

How to Optimize an Ubuntu 1C1G Cloud Server (A Practical, Proven Guide)

Introduction

Running a cloud server with 1 CPU and 1GB RAM is common for personal projects, landing pages, and small websites. However, default Ubuntu installations are not optimized for such low-resource environments, often leading to:

  • High memory usage
  • Random freezes
  • OOM (Out of Memory) kills
  • Poor performance under small traffic spikes

This article walks through real, production-tested optimizations to make Ubuntu stable, predictable, and usable on a 1C1G server.


1. The Core Principle: Reduce, Don’t Tune Blindly

On a 1C1G server, optimization is mostly about removing unnecessary components, not endless tuning.

Key rules:

  • Fewer background services
  • Fewer resident daemons
  • Predictable memory usage
  • Swap is mandatory

2. Enable Swap (Non-Negotiable)

Many cloud images ship without swap, which is dangerous on low memory machines.

1
2
3
4
5
sudo fallocate -l 512M /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Verify:

1
free -h

Why this matters:

  • Prevents sudden OOM kills
  • Absorbs short memory spikes
  • Improves system stability dramatically

3. Adjust Kernel Memory Behavior

Reduce aggressive swapping and cache pressure:

1
2
3
4
5
6
7
8
sudo tee /etc/sysctl.d/99-1c1g.conf <<EOF
vm.swappiness=10
vm.vfs_cache_pressure=200
vm.dirty_ratio=10
vm.dirty_background_ratio=5
EOF

sudo sysctl -p /etc/sysctl.d/99-1c1g.conf

4. Install earlyoom (Fail Fast, Not Freeze)

Instead of letting the system hang:

1
2
3
sudo apt update
sudo apt install -y earlyoom
sudo systemctl enable --now earlyoom

This kills memory-hogging processes before the kernel panics.


5. Remove Ubuntu’s Server-Unfriendly Services

Ubuntu enables many services that are useless on cloud servers.

Disable them:

1
2
3
4
5
6
7
sudo systemctl disable --now \
  snapd \
  fwupd \
  multipathd \
  iscsid \
  packagekit \
  unattended-upgrades

Remove snap completely if unused:

1
2
sudo apt purge -y snapd
sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd

Memory saved: 100–200MB


6. Limit systemd Journal Size

Unbounded logs silently eat disk and memory:

1
2
3
4
5
6
7
8
9
sudo mkdir -p /etc/systemd/journald.conf.d

sudo tee /etc/systemd/journald.conf.d/limit.conf <<EOF
[Journal]
SystemMaxUse=50M
RuntimeMaxUse=20M
EOF

sudo systemctl restart systemd-journald

7. Optimize MySQL for Low Memory

MySQL is often the largest memory consumer.

Edit:

1
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Add under [mysqld]:

1
2
3
4
5
innodb_buffer_pool_size = 128M
innodb_log_buffer_size = 8M
max_connections = 20
performance_schema = OFF
table_open_cache = 400

Restart:

1
sudo systemctl restart mysql

8. Tune PHP-FPM Conservatively

For PHP 8.x:

1
sudo nano /etc/php/8.3/fpm/pool.d/www.conf

Recommended settings:

1
2
3
4
5
pm = dynamic
pm.max_children = 2
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1

9. What “Healthy” Looks Like

1
free -h

Expected:

  • Available memory ≥ 450–550MB
  • Swap usage < 100MB
  • No frequent CPU spikes
  • No OOM events

Conclusion

A 1C1G Ubuntu server can be perfectly stable if treated correctly.

The key is not powerful hardware—but intentional minimalism.

This post is licensed under CC BY 4.0 by the author.