[LINUX] AWS Lightsail Primer 4 Basic Settings (CentOS 7)

Contents of this article

--Set the basic OS settings for the Lightsail instance (CentOS 7).

Prerequisites

--Created a Lightsail instance (CentOS 7).

AWS Lightsail Getting Started 1 Instance Creation (https://qiita.com/s8ta/items/fd274b05b083bcf36dba)

How to proceed with work

Enter commands in the browser version terminal or SSH client.

In the following example, the command cat/etc/redhat-release is entered to check the OS version.

$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

Switch to administrator (root)

Many of the commands entered in this article require administrator privileges. Switch to root first. (Don't forget the hyphen at the end)

$ sudo su -

Commands that require administrator privileges are prompted with #.

Add swap space

Lightsail's cheapest plan ($ 3.50) has as little memory as 512MB. Add swap space so that the program can be executed even if the memory is insufficient.

Check swap area (before addition)

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           485M         98M        260M        8.4M        126M        365M
Swap:            0B          0B          0B

Swap [total] is 0B and no swap space is allocated.

Creating and activating swap files

Create a 1GB swap file on disk and activate it.

# dd if=/dev/zero of=/swapfile bs=1M count=1024 && chmod 600 /swapfile && mkswap /swapfile && swapon /swapfile

If you want to create something other than 1GB, change count = n. For example, with count = 2048, it will be 2GB.

Check swap area (after addition)

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           485M         96M        6.0M        8.4M        382M        367M
Swap:          1.0G          0B        1.0G

Automatic mount setting at OS startup

Make sure that the swap area is automatically enabled when the OS starts.

# echo "/swapfile swap swap defaults 0 0" >> /etc/fstab

Package update

Update installed packages. If you want to proceed while checking the contents, remove the option -y.

# yum -y update

If "Complete!" Is output at the end, the update is complete. Just in case, check if there are any packages that can be updated.

$ yum check-update
Loaded plugins: fastestmirror
Determining fastest mirrors
 * base: d36uatko69830t.cloudfront.net
 * extras: d36uatko69830t.cloudfront.net
 * updates: d36uatko69830t.cloudfront.net

OS restart

To ensure that the package update is reflected, restart the instance from the Lightsail management screen.

aws-lightsail-04-001.png

There was no problem rebooting with the command sudo reboot, but EC2 recommends methods other than OS commands.

We recommend that you use the Amazon EC2 console, command-line tools, or the Amazon EC2 API to restart your instance instead of running the operating system restart command from your instance. If you restart your instance using the Amazon EC2 console, command-line tools, or the Amazon EC2 API, a hard reboot will occur if your instance doesn't shut down completely within minutes.

Reboot Instance --Amazon Elastic Compute Cloud (https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/ec2-instance-reboot.html)

Lightsail was only a procedure on the management screen, and did not mention restarting by command. Start, Stop, or Restart an Amazon Lightsail Instance | Lightsail Documentation (https://lightsail.aws.amazon.com/ls/docs/ja_jp/articles/lightsail-how-to-start-stop-or-restart-your-instance-virtual-private-server)

Change time zone

By default, the time is displayed in UTC, so change it to Japan time.

Confirmation of time (before change)

$ date
Sun Jan 17 10:42:45 UTC 2021

Change to Japan time

# timedatectl set-timezone Asia/Tokyo

Confirmation of time (after change)

$ date
Sun Jan 17 19:42:52 JST 2021

Summary

In the cheapest plan of Lightsail, I introduced the basic settings when using CentOS. In particular, the memory is as small as 512MB, so don't forget to add a swap area.

Recommended Posts

AWS Lightsail Primer 4 Basic Settings (CentOS 7)
CentOS 7 basic settings after network settings
CentOS 7 NW settings
[Linux] Basic settings after OS installation of CentOS 7.3
Teaming (LACP) settings in CentOS 8
[RHEL / CentOS 8] Network settings memo