๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์„œ๋ฒ„/AWS

[EC2] AWS ํ”„๋ฆฌํ‹ฐ์–ด ์‚ฌ์šฉ๋ฒ• Step2 - ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„ ์ดˆ๊ธฐ์„ค์ •

by yunamom 2022. 8. 1.
๋ฐ˜์‘ํ˜•

์•ˆ๋…•ํ•˜์„ธ์š” yunamom ์ž…๋‹ˆ๋‹ค :D

์ด๋ฒˆ ํฌ์ŠคํŒ…์—์„œ๋Š” Step2 ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„ ์ดˆ๊ธฐ์„ค์ • ๋ฐฉ๋ฒ•์„ ์ˆœ์„œ๋Œ€๋กœ ์ž‘์„ฑํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป

 

  1. ์šฐ๋ถ„ํˆฌ apt ๊ธฐ๋ณธ๋ช…๋ น์–ด ์•Œ์•„๋‘๊ธฐ
  2. ์„œ๋ฒ„ ์ ‘์†ํ›„ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ
  3. ํƒ€์ž„์กด ์„ค์ •
  4. ์Šค์™‘ ์˜์—ญ ๋งŒ๋“ค๊ธฐ (๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ : Virtual memory)
  5. ์Šค์™‘ ์˜์—ญ ํฌ๊ธฐ ์กฐ์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

โœจ ์šฐ๋ถ„ํˆฌ apt ๊ธฐ๋ณธ๋ช…๋ น์–ด ์•Œ์•„๋‘๊ธฐ

#Advanced Package Tools apt๋Š” ubuntu์—์„œ SW๋ฅผ ์„ค์น˜, ์—…๋ฐ์ดํŠธ, ์ œ๊ฑฐํ•˜๋Š” ๋ช…๋ น์–ด์ด๋‹ค.

#์„ค์น˜๋œ ํŒจํ‚ค์ง€ ๋ชฉ๋ก ๋ณด๊ธฐ ๋ช…๋ น
$ apt list --installed

#ํŒจํ‚ค์ง€ ์„ค์น˜ ๋ช…๋ น
$ sudo apt install ํŒจํ‚ค์ง€๋ช…

#ํŒจํ‚ค์ง€ ์ œ๊ฑฐ ๋ช…๋ น
$ sudo apt remove ํŒจํ‚ค์ง€๋ช…

#์ตœ์‹  ํŒจํ‚ค์ง€ ๋ชฉ๋ก ๋‹ค์šด๋กœ๋“œ ๋ช…๋ น (ubuntu์— ์„ค์น˜ ๊ฐ€๋Šฅํ•œ ํŒจํ‚ค์ง€๋“ค์— ๋Œ€ํ•œ ์ตœ์‹  ์ •๋ณด๋ฅผ ๋‹ค์šด๋กœ๋“œ)
$ sudo apt update

#์„ค์น˜๋œ ํŒจํ‚ค์ง€ ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ์—…๊ทธ๋ ˆ์ด๋“œ
$ sudo apt upgrade

 

โœจ ์„œ๋ฒ„์ ‘์†ํ›„ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ ํ•˜๊ธฐ 

#์„œ๋ฒ„ ์ ‘์†ํ•˜๊ธฐ
$ ssh -i [ํ‚คํŒŒ์ผ์ด๋ฆ„].pem ubuntu@[์ธ์Šคํ„ด์Šค ํƒ„๋ ฅIP]

#ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ
$ sudo apt update
$ sudo apt upgrade

#์ค‘๊ฐ„์— Y/N์„ ๋ฌป๋Š” ๋ฉ”์‹œ์ง€๊ฐ€ ์ถœ๋ ฅ๋ ์‹œ Y๋ฅผ ์ž…๋ ฅํ›„ ์—”ํ„ฐ

์•„๋ž˜์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋‚˜์˜ฌ๊ฒฝ์šฐ Ok ๋ˆ„๋ฅด๊ณ  ๋„˜์–ด๊ฐ€๊ธฐ

*์œ„์˜ ๋ฌธ๊ตฌ๊ฐ€ ์‹ ๊ฒฝ์“ฐ์ธ๋‹ค๋ฉด .conf ํŒŒ์ผ ์ˆ˜์ • or purge 

$ sudo vi /etc/needrestart/needrestart.conf
# ์•„๋ž˜๋‚ด์šฉ ์ž…๋ ฅํ›„ ESC -> :wq (์ €์žฅํ›„ ๋‚˜๊ฐ€๊ธฐ)

nrconf{kernelhints} = 0;
nrconf{ucodehints} = 0;

 

 

โœจ ํƒ€์ž„์กด ์„ค์ •ํ•˜๊ธฐ 

$ date
Mon Aug  1 05:20:35 UTC 2022
$ sudo ln -sf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
$ date
Mon Aug  1 14:21:27 KST 2022

 

โœจ ์Šค์™‘ ์˜์—ญ ๋งŒ๋“ค๊ธฐ (*์ค‘์š”)

 

1๏ธโƒฃ. ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ (Virtual memory) ๋ž€?

์šด์˜์ฒด์ œ์—์„œ ์‹คํ–‰ ์ค‘์ธ ํ”„๋กœ์„ธ์Šค์— ํ• ๋‹นํ•  ๋ฉ”๋ชจ๋ฆฌ๋ฅผ RAM ์šฉ๋Ÿ‰๋ณด๋‹ค 2~3๋ฐฐ ํฌ๊ฒŒ ํ• ๋‹น๋œ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ๋ผ๊ณ  ํ•œ๋‹ค.

์ฆ‰, ์ด ์šด์˜์ฒด์ œ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ๋Š” RAM์˜ ์ฃผ์†Œ๊ฐ€ ์•„๋‹ˆ๊ณ  RAM ์šฉ๋Ÿ‰๋ณด๋‹ค 2~3๋ฐฐ ํฐ ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ ์ฃผ์†Œ์ด๋‹ค.

 

์ด ๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ๋Š” ์ž‘์€ ํŽ˜์ด์ง€(page)๋“ค๋กœ ๋‚˜๋‰œ๋‹ค.

๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ์˜ ํŽ˜์ด์ง€๋“ค ์ค‘ ํ™œ๋ฐœํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๋Š” ํŽ˜์ด์ง€๋“ค์€ RAM์— ํ• ๋‹น๋˜์–ด ์žˆ๊ณ ,

์•„์ฃผ ๊ฐ€๋” ์‚ฌ์šฉ๋˜๋Š” ํŽ˜์ด์ง€๋“ค์€ ๋””์Šคํฌ์— ํ• ๋‹น๋˜์–ด ์žˆ๋‹ค.

 

ํ™œ๋ฐœํ•˜๊ฒŒ ์‚ฌ์šฉ๋˜๋˜ ํŽ˜์ด์ง€๊ฐ€, ์‹œ๊ฐ„์ด ์ง€๋‚˜ ์•„์ฃผ ๊ฐ€๋” ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด ๊ทธ ํŽ˜์ด์ง€๋Š” RAM์—์„œ ๋””์Šคํฌ๋กœ ์ด๋™ํ•œ๋‹ค.

๋ฐ˜๋Œ€๋กœ ๋””์Šคํฌ์— ์žˆ๋˜ ํŽ˜์ด์ง€๋ฅผ ์ฝ๊ณ  ์“ฐ๊ฒŒ ๋˜๋ฉด, ๊ทธ ํŽ˜์ด์ง€๋Š” ๋””์Šคํฌ์—์„œ RAM์œผ๋กœ ์ด๋™ํ•œ๋‹ค.

์ด๋Ÿฌํ•œ ์ด๋™์„ ํŽ˜์ด์ง•(paging) ํ˜น์ธ ์Šค์™‘(swap)์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

 

2๏ธโƒฃ. ์Šค์™‘ ์˜์—ญ (Swap space)

๊ฐ€์ƒ ๋ฉ”๋ชจ๋ฆฌ์— ํ• ๋‹น๋œ ๋””์Šคํฌ ์˜์—ญ์„ ์Šค์™‘ ์˜์—ญ(Swap space) ์ด๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค.

 

3๏ธโƒฃ. ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰๊ณผ ๋””์Šคํฌ ์šฉ๋Ÿ‰ ํ™•์ธ

AWS EC2์—๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์Šค์™‘ ์˜์—ญ์ด ๋งŒ๋“ค์–ด์ ธ ์žˆ์ง€ ์•Š๋‹ค.

 

- ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰ & ์‚ฌ์šฉ๋Ÿ‰ ํ™•์ธ ๋ช…๋ น

$ free -m
               total        used        free      shared  buff/cache   available
Mem:            1851         216         314           0        1320        1459
Swap:              0           0           0

swap ์˜์—ญ์˜ ํฌ๊ธฐ๊ฐ€ 0์œผ๋กœ ์„ค์ •๋˜์–ด์žˆ๋‹ค.

Linux์—์„œ ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰์ด ๋ถ€์กฑํ•˜๋ฉด ์‹œ์Šคํ…œ์ด ๋งค์šฐ ๋Š๋ ค์ง€๋ฏ€๋กœ swap ์˜์—ญ์„ ๋งŒ๋“ค์–ด์•ผ ํ•œ๋‹ค.

 

- ๋””์Šคํฌ ์‚ฌ์šฉ๋Ÿ‰ ํ™•์ธ ๋ช…๋ น

$ df
Filesystem      1K-blocks    Used Available Use% Mounted on
/dev/root        30313680 2079996  28217300   7% /
tmpfs              948012       0    948012   0% /dev/shm
tmpfs              379208     976    378232   1% /run
tmpfs                5120       0      5120   0% /run/lock
/dev/nvme0n1p15     99800    5180     94620   6% /boot/efi
tmpfs              189600       4    189596   1% /run/user/1000

Linux์—์„œ๋Š” /dev/root๊ฐ€ ๊ธฐ๋ณธ ํŒŒ์ผ ์‹œ์Šคํ…œ ์œผ๋กœ ๋ณธ์ธ์˜ ์„œ๋ฒ„๋Š” 28,217,300๋ธ”๋Ÿญ์ด ์‚ฌ์šฉ๊ฐ€๋Šฅ (28 gb)

 

4๏ธโƒฃ. ์Šค์™‘ ์˜์—ญ ๋งŒ๋“ค๊ธฐ

 

- ์Šค์™‘ ์˜์—ญ์œผ๋กœ ์‚ฌ์šฉํ•  ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024
1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 5.0564 s, 212 MB/s

$ ls -l /swapfile
-rw-r--r-- 1 root root 1073741824 Aug  1 15:08 /swapfile

- ์ƒ์„ฑ๋œ /swapfile ํŒŒ์ผ์„ ์†Œ์œ ์ž(root)๋งŒ ์ฝ๊ณ  ์“ธ์ˆ˜ ์žˆ๊ฒŒ ๊ถŒํ•œ ์„ค์ •ํ•˜๊ธฐ

$ sudo chmod 600 /swapfile
$ ls -l /swapfile
-rw------- 1 root root 1073741824 Aug  1 15:08 /swapfile

- /swapfile ํŒŒ์ผ์„ ์Šค์™‘ ์˜์—ญ์œผ๋กœ ์„ค์ •

$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes)
no label, UUID=5b1a4cd3-c6cc-4582-8a84-a2f53ca58607
$ sudo swapon /swapfile

- /etc/fstab ํŒŒ์ผ์— swapfile ๋“ฑ๋กํ•˜๊ธฐ 

$ sudo vi /etc/fstab

# /etc/fstab ํŒŒ์ผ์„ ์˜คํ”ˆํ›„ i ๋ˆŒ๋Ÿฌ์„œ insert ๋ชจ๋“œ์ง„์ž… -> ์•„๋ž˜ ๋‚ด์šฉ์„ ์ถ”๊ฐ€ -> ESC ๋ˆ„๋ฅด๊ณ  :wq (์ €์žฅํ›„ ๋‚˜๊ฐ€๊ธฐ)
/swapfile swap swap defaults 0  0

- ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰ & ์‚ฌ์šฉ๋Ÿ‰ ํ™•์ธ ( 0 ์—์„œ 1023 ์œผ๋กœ ๋Š˜์–ด๋‚œ๊ฒƒ์„ ํ™•์ธํ• ์ˆ˜ ์žˆ๋‹ค. )

$ free -m
               total        used        free      shared  buff/cache   available
Mem:            1851         183          81           0        1586        1491
Swap:           1023           0        1023

- ๋””์Šคํฌ ์‚ฌ์šฉ๋Ÿ‰ ํ™•์ธ ( ์‚ฌ์šฉ๋Ÿ‰์ด 1gb ๋Š˜์–ด๋‚จ  )

$ df
Filesystem      1K-blocks    Used Available Use% Mounted on
/dev/root        30313680 3128588  27168708  11% /
tmpfs              948012       0    948012   0% /dev/shm
tmpfs              379208     976    378232   1% /run
tmpfs                5120       0      5120   0% /run/lock
/dev/nvme0n1p15     99800    5180     94620   6% /boot/efi
tmpfs              189600       4    189596   1% /run/user/1000

 

โœจ ์Šค์™‘ ์˜์—ญ ํฌ๊ธฐ ์กฐ์ •ํ•˜๊ธฐ 

 

- swapfile ์‚ฌ์šฉ ์ค‘์ง€ (์Šค์™‘ ์˜์—ญ์˜ ํฌ๊ธฐ ์กฐ์ •์„ ํ•˜๋ ค๋ฉด ์‚ฌ์šฉ์„ ์ค‘์ง€ํ•ด์•ผ ํ•จ)

$ sudo swapoff -v /swapfile
swapoff /swapfile

- ์Šค์™‘ ์˜์—ญ์œผ๋กœ ์‚ฌ์šฉํ•  ํŒŒ์ผ ๋‹ค์‹œ ์ƒ์„ฑํ•˜๊ธฐ ( ์Šค์™‘ ์˜์—ญ ํฌ๊ธฐ = 1M * 10240 = 10GB )

$ sudo dd if=/dev/zero of=/swapfile bs=1M count=10240
10240+0 records in
10240+0 records out
10737418240 bytes (11 GB, 10 GiB) copied, 79.0249 s, 136 MB/s
$ ls -l /swapfile
-rw------- 1 root root 10737418240 Aug  1 15:36 /swapfile

- ํŒŒ์ผ์„ ์Šค์™‘ ์˜์—ญ์œผ๋กœ ๋งŒ๋“ค๊ธฐ

$ sudo mkswap /swapfile
Setting up swapspace version 1, size = 10 GiB (10737414144 bytes)
no label, UUID=c9c17dab-12f3-4ffb-acf4-9afd04323bfa
ubuntu@ip-172-31-24-160:~$ sudo swapon /swapfile

- ๋ฉ”๋ชจ๋ฆฌ ์šฉ๋Ÿ‰ & ๋””์Šคํฌ ์‚ฌ์šฉ๋Ÿ‰ ํ™•์ธ

$ free -m
               total        used        free      shared  buff/cache   available
Mem:            1851         179          91           0        1580        1486
Swap:          10239           0       10239
ubuntu@ip-172-31-24-160:~$ df
Filesystem      1K-blocks     Used Available Use% Mounted on
/dev/root        30313680 12565772  17731524  42% /
tmpfs              948012        0    948012   0% /dev/shm
tmpfs              379208      976    378232   1% /run
tmpfs                5120        0      5120   0% /run/lock
/dev/nvme0n1p15     99800     5180     94620   6% /boot/efi
tmpfs              189600        4    189596   1% /run/user/1000

 

์ด๋ฒˆ์‹œ๊ฐ„์—๋Š” ์ด๋ ‡๊ฒŒ ์šฐ๋ถ„ํˆฌ ์„œ๋ฒ„ ์ดˆ๊ธฐ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•˜์—ฌ ์•Œ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค ๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป

mysql, tomcat ์„ค์น˜๋Š” step3 ์—์„œ ์ž‘์„ฑํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค :D 

300x250

์ฝ”๋“œ