ubuntu18.04 server settings - RLidea/dev.docs GitHub Wiki

Web server on Ubuntu 18.04

Ubuntu ํ™˜๊ฒฝ์—์„œ์˜ ์›น ์„œ๋ฒ„ ์„ธํŒ… ๋ฐฉ๋ฒ•์„ ๋‹ค๋ฃฌ ํ•œ๊ตญ์–ด ๋ฉ”๋‰ด์–ผ์ž…๋‹ˆ๋‹ค. ์ด ๋ฌธ์„œ๋Š” Ubuntu 18.04 ๋ฅผ ์‚ฌ์šฉํ•  ํ™˜๊ฒฝ์„ ๊ฐ–์ถ˜ ์ดํ›„๋ฅผ ๋‹ค๋ฃฌ ๊ฐ€์ด๋“œ์ž…๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์ ์ธ ๋ฆฌ๋ˆ…์Šค ๋ช…๋ น์–ด์— ๋Œ€ํ•œ ์„ค๋ช…๋Š” ์ œํƒ€์œ„ํ‚ค ๋“ฑ์—์„œ ๊ฒ€์ƒ‰ํ•˜์‹œ๋ฉด ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Ubuntu 16.04LTS ํ™˜๊ฒฝ์—์„œ์˜ ์„ธํŒ…์„ ์›ํ•˜์‹œ๋Š” ๋ถ„์€ (์—ฌ๊ธฐ)๋ฅผ ํ™•์ธํ•ด์ฃผ์„ธ์š”.

  • ์ถ”๊ฐ€: ์•„๋ž˜ ๋™์ž‘๋“ค์„ user data๋กœ ์ž‘์„ฑํ•ด๋ดค๋‹ค.

0. ๋ชฉ์ฐจ

1. ์‹œ์ž‘
    1-1. root๊ถŒํ•œ ์–ป๊ธฐ
    1-2. ์‹œ์Šคํ…œ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ
2. ์‹œ์Šคํ…œ ์„ค์ •
    2-1. ์‹œ์Šคํ…œ ์‹œ๊ฐ„ ์„ค์ • (๊ถŒ์žฅ)
    2-2. Hostname ๋ณ€๊ฒฝ (์˜ต์…˜)
    2-3. SSH๋ฐ FTP Root์ ‘์† ๊ถŒํ•œ ์„ค์ • (์˜ต์…˜/๊ถŒ์žฅํ•˜์ง€ ์•Š์Œ)
3. Nginx ์›น ์„œ๋ฒ„ ์„ค์น˜
    3-1. Nginx ์„ค์น˜
    3-2. ๊ถŒ์žฅ ์„ค์ •
    3-3. Virtual Host
    3-4. Proxy
4. MariaDB ์„ค์น˜
    4-1. ์ €์žฅ์†Œ ์ถ”๊ฐ€
    4-2. ์„ค์น˜
    4-3. ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฒ•
    4-4. ๊ถŒ์žฅ ์„ค์ •
5. Node.js ์„ค์น˜
    5-1. ์„ค์น˜

1. ์‹œ์ž‘

์‹œ์Šคํ…œ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ๊ด€๋ฆฌ์ž(root) ๊ถŒํ•œ์„ ์–ป๊ณ , ์—…๋ฐ์ดํŠธ๋ฅผ ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

1-1. ์‹œ์Šคํ…œ ํŒจํ‚ค์ง€ ์—…๋ฐ์ดํŠธ

๋ชจ๋“  OS๋ฅผ ์‹œ์ž‘ํ•  ๋•Œ๋Š” ์—…๋ฐ์ดํŠธ๋ฅผ ๋จผ์ € ํ•ด์ค์‹œ๋‹ค. apt๋Š” Ubuntu ์—์„œ ํ”„๋กœ๊ทธ๋žจ ํŒจํ‚ค์ง€๋ฅผ ๋‹ค์šด๋กœ๋“œ ํ•˜๊ณ  ์„ค์น˜ํ•˜๋Š” ํŒจํ‚ค์ง€ ๊ด€๋ฆฌ์ž์ž…๋‹ˆ๋‹ค. apt-get --help ๋ผ๋Š” ๋ช…๋ น์„ ๋‚ด๋ฆฌ๋ฉด ์„ค๋ช…๊ณผ ์‚ฌ์šฉ๋ฒ•์ด ๋‚˜ํƒ€๋‚˜๋‹ˆ ์ฐธ๊ณ ํ•˜์‹ญ์‹œ์˜ค. Amazon Linux ๋‚˜ CentOS ๋“ฑ์—์„  yum์„ ์‚ฌ์šฉํ•˜๊ธฐ๋„ ํ•ฉ๋‹ˆ๋‹ค. ๋ฆฌ๋ˆ…์Šค๋“  ์œˆ๋„์šฐ๋“ , ์–ด๋–ค OS์ด๋“  ์ฒ˜์Œ ์‚ฌ์šฉํ•  ๋• ์—…๋ฐ์ดํŠธ๋ฅผ ํ•ฉ๋‹ˆ๋‹ค.

sudo apt-get update -- ํŒจํ‚ค์ง€ ๋ชฉ๋ก ๊ฐฑ์‹ 
sudo apt-get upgrade -- ํ˜„์žฌ ์šด์˜์ฒด์ œ์— ์„ค์น˜๋˜์–ด ์žˆ๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ตœ์‹  ๋ฒ„์ „์œผ๋กœ ํŒจ์น˜

1-2. sudo ์œ ์ € ์ƒ์„ฑ

sudo์œ ์ €๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค. AWS์˜ ๊ฒฝ์šฐ ubuntu๋ผ๋Š” ์ด๋ฆ„์˜ sudo ์œ ์ €๊ฐ€ ์žˆ์–ด์„œ ๊ท€์ฐฎ์œผ๋ฉด ์ƒ๋žตํ•ด๋„ ๋ฉ๋‹ˆ๋‹ค.

adduser username  # username ์ด๋ผ๋Š” ์ด๋ฆ„์œผ๋กœ ์œ ์ € ์ƒ์„ฑ
usermod -aG sudo username  # username ์œ ์ €์—๊ฒŒ sudo ๊ถŒํ•œ ๋ถ€์—ฌ

2. ์‹œ์Šคํ…œ ์„ค์ •

๊ธฐ๋ณธ์ ์ธ ์‹œ์Šคํ…œ ์„ค์ •์„ ํ•ฉ๋‹ˆ๋‹ค.

2-1. ์‹œ์Šคํ…œ ์‹œ๊ฐ„ ์„ค์ • (๊ถŒ์žฅ)

dpkg-reconfigure tzdata

์ดํ›„ ๋‚˜ํƒ€๋‚˜๋Š” GUI ์„ค์ •์—์„œ Asia, Seoul ์„ ์ฐจ๋ก€๋กœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

tzdata

tzdata

2-2. Hostname ๋ณ€๊ฒฝ (์˜ต์…˜)

hostname ํŒŒ์ผ์—๋Š” ์„œ๋ฒ„์˜ ์ด๋ฆ„์ด ๊ธฐ๋ก๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ฅผ ์ด๋ฆ„์„ ์›ํ•˜๋Š” ์ด๋ฆ„์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค. ( ์ˆ˜์ •ํ•˜๊ธฐ ์œ„ํ•ด ํ‚ค๋ณด๋“œ์˜ i๋ฅผ ๋ˆŒ๋Ÿฌ insert ๋ชจ๋“œ๋กœ ๋“ค์–ด๊ฐ‘๋‹ˆ๋‹ค. esc๋ฅผ ๋ˆ„๋ฅด๋ฉด ๋ชจ๋“œ๋ฅผ ๋‚˜๊ฐˆ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. :wq ๋ฅผ ์ž…๋ ฅํ•œ ํ›„ enter(ํ˜น์€ return)์„ ์ž…๋ ฅํ•˜๋ฉด ์ €์žฅ ํ›„ ๋‚˜๊ฐ€๊ธฐ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค. vi์˜ ์ž์„ธํ•œ ์‚ฌ์šฉ๋ฒ•์€ ๋‹ค๋ฅธ ๋ฌธ์„œ๋ฅผ ์ฐพ์•„๋ณด์‹ญ์‹œ์˜ค.)

sudo vi /etc/hostname

์ด์ œ ๋ณ€๊ฒฝํ•œ ๋‚ด์šฉ์„ ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. ์•„๋ž˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•œ ๋’ค, ์„œ๋ฒ„์— ์žฌ ์ ‘์†ํ•˜๋ฉด ์„ค์ •์ด ์ ์šฉ๋˜์–ด ubuntu@myserver๋“ฑ์œผ๋กœ ๋ณ€๊ฒฝ ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

hostname -F /etc/hostname

hostname

2-3. SSH๋ฐ FTP Root์ ‘์† ๊ถŒํ•œ ์„ค์ • (์˜ต์…˜/๊ถŒ์žฅํ•˜์ง€ ์•Š์Œ)

AWS์˜ ๊ฒฝ์šฐ, ์ฒ˜์Œ EC2๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ssh๋ฐ ftp์ ‘์† ๊ถŒํ•œ์ด ubuntu ์œ ์ €๋กœ๋งŒ ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๊ณ  root ๊ณ„์ • ์ ‘์† ํ—ˆ๊ฐ€๋Š” ๋น„ํ™œ์„ฑํ™” ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฌผ๋ก  ssh์ ‘์†์„ ํ•˜๋ฉด ubuntu ์œ ์ €๋Š” sudo ๋ช…๋ น์„ ์ด์šฉํ•ด์„œ root ๊ถŒํ•œ์„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, FTP๋ฅผ ์ด์šฉํ•  ๋• ๊ถŒํ•œ์„ ์–ป๊ธฐ ํž˜๋“ค์–ด ๋ถˆํŽธํ•œ ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. /home/ubuntu ๋””๋ ‰ํ† ๋ฆฌ ์™ธ์—๋Š” FTP๋ฅผ ํ†ตํ•ด ํŒŒ์ผ์„ ์ถ”๊ฐ€/์‚ญ์ œ/์ˆ˜์ •ํ•  ๊ถŒํ•œ์ด ์—†์–ด์„œ ์ž‘์—…์‹œ์— ๋ถˆํŽธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ root๋กœ ์ ‘์†ํ•˜๋Š” ๊ฒƒ์€ ๋ณด์•ˆ ์ƒ ๊ถŒ์žฅํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

root ๊ถŒํ•œ์ด๋‚˜ sudo ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ sshd_configํŒŒ์ผ์„ viํŽธ์ง‘๊ธฐ๋กœ ์ˆ˜์ •ํ•ฉ์‹œ๋‹ค.

vi /etc/ssh/sshd_config

PermitRootLogin ๋ฅผ ์ฐพ์•„์„œ yes๋กœ ๋ณ€๊ฒฝํ•ด์ค๋‹ˆ๋‹ค. ํŽธ์ง‘๊ธฐ์—์„œ i ๋ฅผ ๋ˆ„๋ฅด๋ฉด insert๋ชจ๋“œ๋กœ ๋“ค์–ด๊ฐ€ ์ˆ˜์ •์ด ๊ฐ€๋Šฅํ•ด์ง€๊ณ , esc๋ฅผ ๋ˆ„๋ฅธ ๋’ค :wq ๋ฅผ ์ž…๋ ฅํ•˜๋ฉด ์ €์žฅํ›„ ํ„ฐ๋ฏธ๋„๋กœ ๋Œ์•„์˜ต๋‹ˆ๋‹ค. ( :q ๋Š” ๋‚˜๊ฐ€๊ธฐ, :q! ๋Š” ๊ฐ•์ œ๋กœ ๋‚˜๊ฐ€๊ธฐ ์ž…๋‹ˆ๋‹ค. q!์˜ ๊ฒฝ์šฐ sudo ๊ถŒํ•œ ์—†์ด ์ˆ˜์ •์„ ์‹œ๋„ํ–ˆ๋‹ค๊ฐ€ ๊ถŒํ•œ์ด ์—†์–ด ์ €์žฅํ•  ์ˆ˜ ์—†์„ ๋•Œ ํŽธ์ง‘์„ ๋ฌด์‹œํ•˜๊ณ  ํ„ฐ๋ฏธ๋„๋กœ ๋Œ์•„๊ฐˆ ๋•Œ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.) ๊ธฐ์กด์˜ PermitRootLogin ํ•ญ๋ชฉ์€ ์ฃผ์„์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ฑฐ๋‚˜(#์„ ์•ž์— ์จ์ฃผ๋ฉด ๋จ) ์ง€์›Œ๋ฒ„๋ฆฝ์‹œ๋‹ค.

setting

์ด์ œ ubuntu ์œ ์ €์˜ ssh key๋ฅผ ๋ฃจํŠธ์— ๋ณต์‚ฌํ•ด์ค๋‹ˆ๋‹ค. /root/.ssh ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†๋‹ค๋ฉด mkdir /root/.ssh ๋กœ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/

์ด์ œ ์™ธ๋ถ€์—์„œ ssh๋ฐ ftp๋ฅผ root ๊ณ„์ •์œผ๋กœ ์›๊ฒฉ ์ ‘์† ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. setting

3. Nginx ์›น ์„œ๋ฒ„ ์„ค์น˜ํ•˜๊ธฐ

3-1. Nginx ์„ค์น˜

Ubuntu 18.04 ์—์„œ๋Š” nginx version: nginx/1.14.0 (Ubuntu)๋ฒ„์ „์ด ์ œ๊ณต๋˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. ์„ค์น˜ํ•˜๋ฉด ์ž๋™์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ์žฌ๋ถ€ํŒ…์‹œ ์ž๋™์‹คํ–‰ ๋˜๋Š” ๊ฒƒ์ด ๊ธฐ๋ณธ ์„ค์ •์ด๋ผ ๋”ฐ๋กœ ์„œ๋น„์Šค๋ฅผ ๋“ฑ๋กํ•ด์ค„ ํ•„์š”๋Š” ์—†์Šต๋‹ˆ๋‹ค.

sudo apt install nginx

๋” ์ตœ์‹  ๋ฒ„์ „์˜ Nginx๋ฅผ ์›ํ•œ๋‹ค๋ฉด ์ €์žฅ์†Œ๋ฅผ ๋“ฑ๋กํ•ด์„œ ์‚ฌ์šฉํ•ฉ์‹œ๋‹ค.

์žฌ๋Œ€๋กœ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ๋ฒ„์ „์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

nginx -v

์„œ๋ฒ„ ์žฌ์‹œ์ž‘๋„ ์ž˜ ๋˜๋Š”์ง€ ์ฒดํฌํ•ด๋ด…์‹œ๋‹ค.

service nginx restart

nginx๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ 80 ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์›น๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ผœ๊ณ  ์„œ๋ฒ„์˜ ์•„์ดํ”ผ(http://111.222.333.444 ๋“ฑ)์— ์ ‘์†ํ•ด์„œ ๋™์ž‘ ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. Welcome to nginx! ๋ฌธ๊ตฌ๊ฐ€ ๋œจ๋ฉด ์ •์ƒ์ž…๋‹ˆ๋‹ค. apt-get์œผ๋กœ ์„ค์น˜ํ•˜์˜€์„ ๋•Œ, ์ด ํŒŒ์ผ์˜ ๊ธฐ๋ณธ ์œ„์น˜๋Š” /usr/share/nginx/html/index.html ์ž…๋‹ˆ๋‹ค.

[trouble shooting]

  1. "์‘๋‹ตํ•˜๋Š” ๋ฐ ์‹œ๊ฐ„์ด ๋„ˆ๋ฌด ์˜ค๋ž˜ ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค." ๋ผ๋ฉฐ ํŽ˜์ด์ง€๊ฐ€ ์ ‘์†๋˜์ง€ ์•Š์„ ๋•Œ๋Š” ํฌํŠธ๊ฐ€ ์—ด๋ ค์žˆ๋Š”์ง€ ๋จผ์ € ํ™•์ธํ•ด๋ณด์„ธ์š”. nginx์˜ default port๋Š” 80์ž…๋‹ˆ๋‹ค. AWS์˜ ๊ฒฝ์šฐ, Security group ์˜ ์ดˆ๊นƒ๊ฐ’์ด 22๋ฒˆ ํฌํŠธ๋งŒ ์—ด๋ ค ์žˆ์Šต๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ 80ํฌํŠธ๋ฅผ ์—ด๋ฉด ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3-2. ๊ถŒ์žฅ ์„ค์ •

nginx.conf์˜ ๊ถŒ์žฅ ์„ค์ •์„ ์ ์šฉํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.. ์šฐ์„  ๊ธฐ๋ณธ ์„ค์ • ํŒŒ์ผ์„ ๋ฐฑ์—…ํ•ด๋‘ก๋‹ˆ๋‹ค.

sudo cp nginx.conf nginx.conf.org

์ด์ œ ๋ณธ๊ฒฉ์ ์œผ๋กœ ์„ค์ •ํŒŒ์ผ(nginx.conf)๋ฅผ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/nginx/nginx.conf
events {
    ...
    # ํ•œ ๋ฒˆ์— ๋ณต์ˆ˜์˜ ์ ‘์†์„ ํ—ˆ๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.
    multi_accept on;
    ...
}

http {
    #response header์— nginx ๋ฒ„์ „ ํ‘œ์‹œ ์—ฌ๋ถ€๋ฅผ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
    #๋ณด์•ˆ์„ ์œ„ํ•ด off๋ฅผ ํ•ด์ค์‹œ๋‹ค.
    server_tokens off;

    #response header ์— charset ์„ ๋ถ€์—ฌํ•ฉ๋‹ˆ๋‹ค.
    charset utf8mb4;

    #์›น์„œ๋ฒ„์—์„œ ์ˆ˜์‹ ํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ๋Œ€ ํŒจํ‚ท ํฌ๊ธฐ๋ฅผ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
    #๊ธฐ๋ณธ๊ฐ’์€ 1MB ์ด๋ฉฐ, ๋” ํฐ ํŒŒ์ผ์˜ ์—…๋กœ๋“œ๋ฅผ ํ—ˆ์šฉํ•˜๋ ค๋ฉด ์ด ๊ฐ’์„ ๋Š˜๋ ค์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    #์›ํ•˜๋Š” ๊ฐ’์œผ๋กœ ๋ฐ”๊ฟ‰๋‹ˆ๋‹ค.
    client_max_body_size 20M;
}

์ˆ˜์ •, ์ €์žฅ ํ›„์— ์„œ๋ฒ„๋ฅผ ์žฌ์‹œ์ž‘ํ•ด์ค๋‹ˆ๋‹ค.

service nginx restart

3-3. Virtual Host

์ฐธ๊ณ : ์—”์ง„์—‘์Šค ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ ์„ค์ •(nginx Virtual Host Setup)

3-4. Proxy

3000๋ฒˆ ํฌํŠธ๋กœ ์„œ๋น„์Šค๋˜๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ 80๋ฒˆ ํฌํŠธ๋กœ ํ”„๋ก์‹œํ•ด์•ผ ํ•  ๋•Œ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

$ sudo vi /etc/nginx/sites-available/default 

location ํ•ญ๋ชฉ์„ ์•„๋ž˜ ๋‚ด์šฉ๊ณผ ๊ฐ™์ด ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://127.0.0.1:3000/;
      proxy_redirect off;
}

์ˆ˜์ • ํ›„ nginx๋ฅผ ์žฌ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.

sudo service nginx restart

์ด์ œ 80 ํฌํŠธ์—์„œ ์ ‘์†ํ•ด๋„ 3000๋ฒˆ ํฌํŠธ์—์„œ ์„œ๋น„์Šค๋˜๋Š” ํ”„๋กœ์ ํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

4. MariaDB์„ค์น˜

MariaDB๋ฅผ ์„ค์น˜ํ•ด๋ด…๋‹ˆ๋‹ค.
mysql Ver 15.1 Distrib 10.1.38-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2์ด ์„ค์น˜๋ฉ๋‹ˆ๋‹ค. EC2์˜ MariaDB๋ฅผ ์™ธ๋ถ€์—์„œ ์ ‘์†ํ•˜๊ณ  ์‹ถ์„ ๋• ์—ฌ๊ธฐ๋ฅผ ์ฐธ๊ณ ํ•ฉ๋‹ˆ๋‹ค.

4-1. ์ €์žฅ์†Œ ์ถ”๊ฐ€

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64] http://mirror.zol.co.zw/mariadb/repo/10.3/ubuntu bionic main'
sudo apt update

4-2. ์„ค์น˜

sudo apt -y install mariadb-server mariadb-client

์„ค์น˜ ์ง„ํ–‰์ค‘์— root์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋ฌผ์–ด๋ด…๋‹ˆ๋‹ค. ์•ˆ์ „ํ•˜๊ฒŒ ์„ค์ •ํ•˜๊ณ  ์žŠ์ง€ ์•Š๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด ์ž˜ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ด๋ด…๋‹ˆ๋‹ค.

mysql --version  # ๋ฒ„์ „ ํ™•์ธ
sudo systemctl start mariadb  # ์‹œ์ž‘

์ฐธ๊ณ  ๋งํฌ: (install-mariadb-10-on-ubuntu-18-04-and-centos-7)

4-3. ๊ธฐ๋ณธ์ ์ธ ์‚ฌ์šฉ๋ฒ•

4-3-1. ์‹คํ–‰

sudo systemctl start mariadb

4-3-2. ๋กœ๊ทธ์ธ

mysql -u root
mysql -u root -p #ํŒจ์Šค์›Œ๋“œ ์„ค์ • ์ดํ›„

4-3-3. DB ๋ฐ ์œ ์ € ์ƒ์„ฑ, ๊ถŒํ•œ ๋ถ€์—ฌ

4-3-3-1. Database์ƒ์„ฑ/์‚ญ์ œ

create database [dbname];
show databases; # ์ƒ์„ฑ๋œ DBํ™•์ธ
drop database demo; # DB์‚ญ์ œ

4-3-3-2. user ์ƒ์„ฑ, ๊ถŒํ•œ๋ถ€์—ฌ, ์ ‘์†

์ƒ์„ฑ

create user '[user name]'@'localhost' identified by '[password]'; # ์‚ฌ์šฉ์ž ์ƒ์„ฑ

๊ถŒํ•œ๋ถ€์—ฌ

grant all privileges on [dbname].* to [user name]@'localhost'; # <user name>์—๊ฒŒ <dbname>์˜ ๋ชจ๋“  ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•œ๋‹ค.
FLUSH PRIVILEGES;  # ๋ณ€๊ฒฝ๋œ ๊ถŒํ•œ ์„ค์ •์„ ๋ฐ˜์˜ํ•œ๋‹ค.

์œ ์ € ๋ฆฌ์ŠคํŠธ ํ™•์ธ (์ฐธ๊ณ : [MySQL โ€œshow usersโ€: How to show/list the users in a MySQL database | alvinalexander.com] (https://alvinalexander.com/blog/post/mysql/show-users-i-ve-created-in-mysql-database))

select host, user from mysql.user;

์œ ์ €๋กœ ์ ‘์†

mysql -u [username] -p #์ ‘์†

4-3-4. ์™ธ๋ถ€ DBํˆด๋กœ ์ ‘์†

MySQL ์™ธ๋ถ€ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ด์„œ ์ง์ ‘ ์ ‘์†ํ•  ์ˆ˜๋„ ์žˆ์ง€๋งŒ, SSH ์ ‘์†์„ ์ด์šฉํ•˜๋Š”๊ฒŒ ์ข€ ๋” ์•ˆ์ „ํ•ฉ๋‹ˆ๋‹ค. (์ฐธ๊ณ ๋งํฌ)

4-4. ๊ถŒ์žฅ ์„ค์ •

4-4-1. root ๋น„๋ฐ€๋ฒˆํ˜ธ ์„ค์ •

root์˜ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์„ค์ •ํ•˜๊ฑฐ๋‚˜ ์ˆ˜์ •ํ•˜๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

mysqladmin -u์•„์ด๋”” -p๊ธฐ์กดํŒจ์Šค์›Œ๋“œ password ์‹ ๊ทœํŒจ์Šค์›Œ๋“œ
mysqladmin -uroot -p password [new password]
SET PASSWORD FOR 'root'@'%' = PASSWORD('[password]');
update user set password=PASSWORD('[password]') where user='root';
FLUSH PRIVILEGES;
GRANT ALL ON *.* TO 'root'@'localhost' IDENTIFIED BY '[password]' WITH GRANT OPTION;
FLUSH PRIVILEGES;

4-4-2. Timezone ์„ค์ •

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql
mysql> set time_zone = 'Asia/Seoul';
mysql> select @@time_zone;
mysql> select now();

์ดํ›„ ์žฌ์‹œ์ž‘์„ ํ•˜๋ฉด ์ ์šฉ๋ฉ๋‹ˆ๋‹ค.

service mysqld restart

5. Node.js ์„ค์น˜

5-1. ์„ค์น˜

Node.js ๋ฒ„์ „ v8.10.0 ๋ฐ npm ๋ฒ„์ „ 6.8.0๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

sudo apt install curl
curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt install nodejs

10 ๋ฒ„์ „์„ ์„ค์น˜ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

sudo apt install curl  # ์ด๋ฏธ curl์ด ์„ค์น˜๋˜์–ด ์žˆ๋‹ค๋ฉด ์ง„ํ–‰ํ•˜์ง€ ์•Š์•„๋„ ๋ฉ๋‹ˆ๋‹ค.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install nodejs

12 ๋ฒ„์ „์„ ์„ค์น˜ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ง„ํ–‰ํ•ฉ๋‹ˆ๋‹ค.

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install nodejs

์ž˜ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ์‹œ๋‹ค.

node -v  
npm -v
โš ๏ธ **GitHub.com Fallback** โš ๏ธ