알아두면 좋은 IT 지식/General

AWS 프리티어 EC2 인스턴스 리눅스 서버 무료로 사용하기 (2)

uutopia 2024. 5. 2. 15:09

자 이제 저번 글에서 생성한 RHEL 리눅스 서버에 필요한 초기 환경 세팅을 시작해보자.

(이전 글 : https://uutopia.tistory.com/67)

 

root 계정 활성화

root 계정을 사용하기 위해 패스워드를 설정하고 계정을 전환한다.

(초기 접속 계정인 ec2-user 에 sudo 권한이 부여되어 있다.)

[ec2-user@ip-172-31-14-94 ~]$ sudo passwd
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.
[ec2-user@ip-172-31-14-94 ~]$ sudo -i
[root@ip-172-31-14-94 ~]#

 

시간 동기화

인스턴스의 리전이 다른 경우 Asia/Seoul로 타임존을 변경한다.

[root@ip-172-31-14-94 US]# date
Thu May  2 01:39:20 AM EDT 2024
[root@ip-172-31-14-94 ~]# cp -p /usr/share/zoneinfo/Asia/Seoul /etc/localtime
cp: overwrite '/etc/localtime'? yes
[root@ip-172-31-14-94 ~]# timedatectl set-timezone Asia/Seoul
[root@ip-172-31-14-94 ~]#
[root@ip-172-31-14-94 ~]# date
Thu May  2 02:39:20 PM KST 2024

 

한글 언어팩 설치

패키지 설치를 통해서 서버의 언어 설정을 en_US.UTF-8 → ko_KR.utf8로 변경한다. (재접속 시 적용)

[root@ip-172-31-14-94 ~]# locale
LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
[root@ip-172-31-14-94 ~]# dnf install glibc-langpack-ko
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered with an entitlement server. You can use subscription-manager to register.

Last metadata expiration check: 1:23:38 ago on Thu 02 May 2024 01:18:57 PM KST.
Dependencies resolved.
======================================================================================================
 Package                   Architecture   Version               Repository                       Size
======================================================================================================
Installing:
 glibc-langpack-ko         x86_64         2.34-100.el9          rhel-9-baseos-rhui-rpms         371 k
Upgrading:
 glibc                     x86_64         2.34-100.el9          rhel-9-baseos-rhui-rpms         2.0 M
 glibc-common              x86_64         2.34-100.el9          rhel-9-baseos-rhui-rpms         321 k
 glibc-gconv-extra         x86_64         2.34-100.el9          rhel-9-baseos-rhui-rpms         1.7 M
 glibc-langpack-en         x86_64         2.34-100.el9          rhel-9-baseos-rhui-rpms         674 k

Transaction Summary
======================================================================================================
Install  1 Package
Upgrade  4 Packages

Total download size: 5.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): glibc-common-2.34-100.el9.x86_64.rpm                           4.9 MB/s | 321 kB     00:00
(2/5): glibc-langpack-en-2.34-100.el9.x86_64.rpm                       30 MB/s | 674 kB     00:00
(3/5): glibc-gconv-extra-2.34-100.el9.x86_64.rpm                       42 MB/s | 1.7 MB     00:00
(4/5): glibc-langpack-ko-2.34-100.el9.x86_64.rpm                      1.5 MB/s | 371 kB     00:00
(5/5): glibc-2.34-100.el9.x86_64.rpm                                  7.1 MB/s | 2.0 MB     00:00
------------------------------------------------------------------------------------------------------
Total                                                                  16 MB/s | 5.0 MB     00:00
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                              1/1
  Upgrading        : glibc-common-2.34-100.el9.x86_64                                             1/9
  Upgrading        : glibc-langpack-en-2.34-100.el9.x86_64                                        2/9
  Upgrading        : glibc-gconv-extra-2.34-100.el9.x86_64                                        3/9
  Running scriptlet: glibc-gconv-extra-2.34-100.el9.x86_64                                        3/9
  Running scriptlet: glibc-2.34-100.el9.x86_64                                                    4/9
  Upgrading        : glibc-2.34-100.el9.x86_64                                                    4/9
  Running scriptlet: glibc-2.34-100.el9.x86_64                                                    4/9
  Installing       : glibc-langpack-ko-2.34-100.el9.x86_64                                        5/9
  Cleanup          : glibc-2.34-83.el9_3.7.x86_64                                                 6/9
  Cleanup          : glibc-langpack-en-2.34-83.el9_3.7.x86_64                                     7/9
  Cleanup          : glibc-gconv-extra-2.34-83.el9_3.7.x86_64                                     8/9
  Running scriptlet: glibc-gconv-extra-2.34-83.el9_3.7.x86_64                                     8/9
  Cleanup          : glibc-common-2.34-83.el9_3.7.x86_64                                          9/9
  Running scriptlet: glibc-common-2.34-83.el9_3.7.x86_64                                          9/9
  Verifying        : glibc-langpack-ko-2.34-100.el9.x86_64                                        1/9
  Verifying        : glibc-2.34-100.el9.x86_64                                                    2/9
  Verifying        : glibc-2.34-83.el9_3.7.x86_64                                                 3/9
  Verifying        : glibc-common-2.34-100.el9.x86_64                                             4/9
  Verifying        : glibc-common-2.34-83.el9_3.7.x86_64                                          5/9
  Verifying        : glibc-langpack-en-2.34-100.el9.x86_64                                        6/9
  Verifying        : glibc-langpack-en-2.34-83.el9_3.7.x86_64                                     7/9
  Verifying        : glibc-gconv-extra-2.34-100.el9.x86_64                                        8/9
  Verifying        : glibc-gconv-extra-2.34-83.el9_3.7.x86_64                                     9/9
Installed products updated.

Upgraded:
  glibc-2.34-100.el9.x86_64                         glibc-common-2.34-100.el9.x86_64
  glibc-gconv-extra-2.34-100.el9.x86_64             glibc-langpack-en-2.34-100.el9.x86_64
Installed:
  glibc-langpack-ko-2.34-100.el9.x86_64

Complete!
[root@ip-172-31-14-94 ~]# localectl set-locale LANG=ko_KR.utf8
[root@ip-172-31-14-94 ~]# exit
logout
[ec2-user@ip-172-31-14-94 ~]$ su -
Password:
Last failed login: Thu May  2 14:32:15 KST 2024 on pts/1
There was 1 failed login attempt since the last successful login.
[root@ip-172-31-14-94 ~]# locale
LANG=ko_KR.utf8
LC_CTYPE="ko_KR.utf8"
LC_NUMERIC="ko_KR.utf8"
LC_TIME="ko_KR.utf8"
LC_COLLATE="ko_KR.utf8"
LC_MONETARY="ko_KR.utf8"
LC_MESSAGES="ko_KR.utf8"
LC_PAPER="ko_KR.utf8"
LC_NAME="ko_KR.utf8"
LC_ADDRESS="ko_KR.utf8"
LC_TELEPHONE="ko_KR.utf8"
LC_MEASUREMENT="ko_KR.utf8"
LC_IDENTIFICATION="ko_KR.utf8"
LC_ALL=

 

swap 메모리 추가

프리티어 서버의 경우 메모리가 1GB로 제한되어 있으므로 swap 메모리를 1GB 추가해서 보완한다.

[root@ip-172-31-14-94 Asia]# free -h
               total        used        free      shared  buff/cache   available
Mem:           753Mi       254Mi       115Mi       5.0Mi       501Mi       499Mi
[root@ip-172-31-14-94 Asia]# dd if=/dev/zero of=/swapfile bs=64M count=16
16+0 records in
16+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 13.8998 s, 77.2 MB/s
[root@ip-172-31-14-94 Asia]# chmod 600 /swapfile
[root@ip-172-31-14-94 Asia]# mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=91ac4454-ce7f-4c5f-a3ee-a60e2029e177
[root@ip-172-31-14-94 Asia]# swapon /swapfile
[root@ip-172-31-14-94 Asia]# echo '/swapfile swap swap defaults 0 0' >> /etc/fstab
[root@ip-172-31-14-94 Asia]# free -h
               total        used        free      shared  buff/cache   available
Mem:           753Mi       260Mi       102Mi       5.0Mi       508Mi       493Mi
Swap:          1.0Gi          0B       1.0Gi

 

cache 메모리 비우기

운영 중 메모리가 부족할 경우 cache 메모리를 비워서 어느정도 해결할 수 있다.

(그래도 부족할 경우 swap 메모리를 추가해 준다.)

free -h
               total        used        free      shared  buff/cache   available
Mem:           753Mi       262Mi       101Mi       6.0Mi       509Mi       491Mi
Swap:          1.0Gi          0B       1.0Gi
[root@ip-172-31-14-94 ~]# sync
[root@ip-172-31-14-94 ~]# echo 3 > /proc/sys/vm/drop_caches
[root@ip-172-31-14-94 ~]# free -h
               total        used        free      shared  buff/cache   available
Mem:           753Mi       228Mi       542Mi       6.0Mi        76Mi       525Mi
Swap:          1.0Gi          0B       1.0Gi