
Overview
For many software 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 server on an 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 EC2 Ubuntu instance using SSH via terminal (mac) or PuTTY (Windows), the login result to the Ubuntu instance shows a message about pending updates similar to the login below?
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.4.0-1029-aws aarch64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Wed Nov 25 15:37:07 UTC 2020 System load: 0.0 Processes: 143 Usage of /: 20.4% of 7.59GB Users logged in: 0 Memory usage: 23% IPv4 address for ens5: 172.31.62.232 Swap usage: 0% * Introducing self-healing high availability clustering for MicroK8s! Super simple, hardened and opinionated Kubernetes for production. https://microk8s.io/high-availability 42 updates can be installed immediately. 15 of these updates are security updates. To see these additional updates run: apt list --upgradable Last login: Tue Nov 24 22:49:38 2020 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 -y 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
Although this is quick, we can do better. If a .bash_aliases file is created, it will be processed by .bashrc file upon reboot. Therefore, this is a good place to combine all of these commands into a single alias. To create the .bash_aliases file, enter the following:
sudo nano ~/.bash_aliases
Add this line, which is which is a concatenation of the previous commands, then save file:
alias update='sudo apt-get update && sudo apt-get -y dist-upgrade && sudo apt-get clean && sudo apt -y autoremove && sudo /sbin/reboot'
Reboot instance:
sudo /sbin/reboot
Now, to update Linux, type:
update
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 (use ctrl-c to exit top):
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!