A Collection of AWS EC2 Ubuntu Tips

Overview

For many website developers, Amazon Web Services (AWS) and Ubuntu Linux are our world. The Ubuntu instances on AWS have exceptionally performance, have almost unbelievable reliability, and are surprisingly affordable. Establishing a website on a AWS EC2 Ubuntu instance can be a little intimidating at first to setup, configure, backup, and operate. As such, there are numerous Ubuntu Linux tips and short-cuts that one learns on this development journey. Here is my growing list:

Updates to Ubuntu

What if after accessing the AWS instance using SSH via terminal (as described in post AWS WordPress 1: Create EC2 Instance, the login result to the Ubuntu instance shows the following message about pending updates?

Welcome to Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-1041-aws x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

18 packages can be updated.
0 updates are security updates.


*** System restart required ***
Last login: Wed Dec 27 19:31:25 2017 from 71.197.165.101
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Updating the Ubuntu Linux AWS instance involves a few simple commands:

Fetches the list of available updates:

sudo apt-get update

Installs the updates:

sudo apt-get dist-upgrade

Cleans up /var/cache/apt/archives:

sudo apt-get clean

Removes old kernels:

sudo apt autoremove

Reboots the EC2 instance:

sudo /sbin/reboot

Getting Information on Disk Storage and CPU Utilization

It is important to understand how much disk storage and memory is being use and how much CPU is being utilized. Here are two commands and their typical responses on an AWS EC2 ‘t2.micro‘ instance.

Provide a list of storage devices with usage information:

df -H
Filesystem      Size  Used Avail Use% Mounted on
udev            512M     0  512M   0% /dev
tmpfs           104M  3.2M  101M   4% /run
/dev/xvda1      8.3G  1.3G  7.0G  16% /
tmpfs           520M     0  520M   0% /dev/shm
tmpfs           5.3M     0  5.3M   0% /run/lock
tmpfs           520M     0  520M   0% /sys/fs/cgroup
tmpfs           104M     0  104M   0% /run/user/1000

Provide memory usage and CPU utilization information:

top
top - 19:52:37 up 3 min,  1 user,  load average: 0.02, 0.07, 0.03
Tasks: 108 total,   1 running, 107 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  1014644 total,   817484 free,    45944 used,   151216 buff/cache
KiB Swap:        0 total,        0 free,        0 used.   813248 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND
    1 root      20   0   37756   5720   3896 S  0.0  0.6   0:02.38 systemd
    2 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kthreadd
    3 root      20   0       0      0      0 S  0.0  0.0   0:00.01 ksoftirqd/0
    4 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0
    5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H
    6 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kworker/u30:0
    7 root      20   0       0      0      0 S  0.0  0.0   0:00.04 rcu_sched
    8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh
    9 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0
   10 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 watchdog/0
   11 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs
   12 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns
   13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 perf
   14 root      20   0       0      0      0 S  0.0  0.0   0:00.00 xenwatch
   15 root      20   0       0      0      0 S  0.0  0.0   0:00.00 xenbus
   16 root      20   0       0      0      0 S  0.0  0.0   0:00.02 kworker/0:1
   17 root      20   0       0      0      0 S  0.0  0.0   0:00.00 khungtaskd
   18 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback
   19 root      25   5       0      0      0 S  0.0  0.0   0:00.00 ksmd
   20 root      39  19       0      0      0 S  0.0  0.0   0:00.00 khugepaged

Other Tips

I will continue to add to this collection of AWS EC2 tips as I discover them!

2018-03-29T17:24:14+00:00By |Amazon Web Services|

Leave A Comment