TIL

23/12/10 TIL __ AWS EC2 ๋ฐฐํฌ (redis, ์นด์นด์˜ค passport) ์—๋Ÿฌ

GABOJOK 2023. 12. 11. 02:14

 

 

 

๐Ÿฃ   ์ƒํ™ฉ

 

๋‚ด ์˜ˆ์ƒ๊ณผ๋Š” ๋‹ค๋ฅด๊ฒŒ ๋งŽ์€ ์‹œ๊ฐ„์„ passport์™€ ๋ ˆ๋””์Šค์— ์‚ฌ์šฉํ–ˆ๋‹ค. 

๋ฐฐํฌ๋ฅผ ๋น ๋ฅด๊ฒŒ ๋๋‚ด๊ณ  ๊ฐ•์˜๋ฅผ ๋“ค์œผ๋ ค๊ณ  ํ–ˆ๋Š”๋ฐ, ๋ฐฐํฌ์—์„œ ๋˜ ์• ๋ฅผ ๋จน์—ˆ๋‹ค. 

์นด์นด์˜ค ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ์ž‘๋™์ด ๋˜์ง€ ์•Š์•˜๊ณ ,

๋ฐฐํฌํ›„ pm2 startup์„ ํ†ตํ•ด ์„œ๋ฒ„ ์žฌ์‹œ์ž‘ ์„ค์ •์„ ํ•œ ๋’ค์— 

ec2 ์ธ์Šคํ„ด์Šค ์žฌ๋ถ€ํŒ…์„ ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด ์„œ๋ฒ„๊ฐ€ ๋‹ค์šด๋˜๋ฉด์„œ ์‹คํ–‰๋˜์ง€ ์•Š์•˜๋‹ค. 

15๋ถ„์„ ๊ธฐ๋‹ค๋ ธ๋Š”๋ฐ๋„!!

 

 

๐Ÿš™   ๊ณผ์ •

์šฐ๋ถ„ํˆฌ๋กœ ๋ฐฐํฌ ํ›„, pm2 startup์„ ํ–ˆ๊ณ , ์ž˜ ๋˜๋Š”์ง€ ํ…Œ์ŠคํŠธ ํ•ด๋ณด๊ธฐ ์œ„ํ•ด ec2์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์žฌ๋ถ€ํŒ… ํ•ด๋ดค๋‹ค.

์ค‘์ง€์™€ ๋‹ค๋ฅด๊ฒŒ ์žฌ๋ถ€ํŒ…์€ ip์ฃผ์†Œ๊ฐ€ ์œ ์ง€๋˜๊ธฐ ๋•Œ๋ฌธ์— ๋‚˜๋Š” ์„œ๋ฒ„๊ฐ€ ์ฃฝ์—ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ์‚ด์•„๋‚  ๊ฒƒ์œผ๋กœ ๊ธฐ๋Œ€ํ•˜๊ณ  ์žˆ์—ˆ๋‹ค. 

๊ทธ๋Ÿฌ๋‚˜ ๊ทธ๊ฒŒ ์•„๋‹ˆ์˜€๋‹ค. 

์„œ๋ฒ„๋Š” ๊บผ์กŒ๊ณ , 15๋ถ„์„ ๊ธฐ๋‹ค๋ ค๋„ ๋Œ์•„์˜ค์ง€ ์•Š์•˜๋‹ค.

pm2๋ฅผ stop ํ›„ delete ํ•œ ํ›„์—, port๋ฅผ ์กฐํšŒํ•ด ๋ดค๋”๋‹ˆ ํฌํŠธ๊ฐ€ ์‚ด์•„์žˆ์—ˆ๋‹ค. 

ํฌํŠธ๋ฅผ ์ฃฝ์˜€๋Š”๋ฐ๋„ ์‚ด์•„์žˆ์–ด์„œ ppid๋ฅผ ์ฃฝ์˜€๋‹ค. 

์˜ค์ž‰....

๊ทธ๋ž˜๋„ ์‚ด์•„์žˆ๋‹ค. ..

 

์•„๋ฌด๋ฆฌ ๋ฐ˜๋ณตํ•ด๋ด๋„ ์‚ด์•„์žˆ๋‹ค. 

 

 

1.  pm2 ๋ฐฐํฌํ›„ ๋‹ค์‹œ ๋ฐฐํฌ๋ฅผ ์œ„ํ•ด ํฌํŠธ๋ฅผ ์ฃฝ์—ฌ๋„ ๊ณ„์† ์‚ด์•„๋‚˜๋Š” ๋ฌธ์ œ ( kill -9 pid), ( kill -9 ppid) ํ•ด๋„ ์•ˆ๋จน์„ ๊ฒฝ์šฐ.

pm2 kill๊ณผ  pm2 unstartup ๋ช…๋ น์–ด๋ฅผ ์ง„ํ–‰ํ›„ port์˜ ppid๋ฅผ ์ฃฝ์ด๋‹ˆ ์‚ญ์ œ๊ฐ€ ๋˜์—ˆ๋‹ค. 

 

 

๋ญ”๊ฐ€ ์„ค์ •์„ ์ž˜๋ชปํ•œ๊ฒƒ ๊ฐ™์•„ ๋‹ค์‹œ ์ฒ˜์Œ๋ถ€ํ„ฐ ์ง„ํ–‰ํ•ด ๋ณด์•˜๋‹ค.

๋ ˆ๋””์Šค๋ฅผ ๋‹ค์‹œ ์„ค์น˜ํ•˜๋Š”๋ฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค. 

 

 

2.  ์šฐ๋ถ„ํˆฌ ๋ ˆ๋””์Šค ์„ค์น˜ ์—๋Ÿฌ

ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=1/FAILURE)

 

์ด ์—๋Ÿฌ๋Š” ๋ญ”๊ฐ€ ํ•ด์„œ ์ฐพ์•„๋ณด๋‹ˆ,

conf ํŒŒ์ผ์„ค์ •์„ ์•ˆํ•ด์„œ ๊ทธ๋Ÿฐ๊ฒƒ ๊ฐ™์•˜๋‹ค. 

์ฐพ์•„๋ณด๋‹ˆ conf ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์„œ ๋„ฃ์–ด์ฃผ์–ด์•ผ ํ–ˆ๋‹ค. 

 

//ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ
sudo mkdir -p /var/lib/redis
sudo chown -R redis:redis /var/lib/redis
dir /var/lib/redis

//ํ˜„์žฌ ๊ถŒํ•œ ํ™•์ธ
ls -alt /etc/redis/redis.conf
-rw-r----- 1 redis redis 107554 Dec 10 17:13 /etc/redis/redis.conf

//๊ถŒํ•œ ๋ณ€๊ฒฝ
sudo chmod 600 /etc/redis/redis.conf
ls -alt /etc/redis/redis.conf
-rw------- 1 redis redis 107554 Dec 10 17:13 /etc/redis/redis.conf

ubuntu@ip-172-31-10-167:~/node_Personal_assignment_3$ sudo apt-get upgrade
Reading package lists... Done

 

 

sudo mkdir -p /var/lib/redis: /var/lib/redis
๊ฒฝ๋กœ์— Redis๋ฅผ ์œ„ํ•œ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. -p ์˜ต์…˜์€ ๋ถ€๋ชจ ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ์—๋„ ๊ฒฝ๋กœ ์ „์ฒด๋ฅผ ์ƒ์„ฑ

sudo chown -R redis:redis /var/lib/redis: /var/lib/redis
๋””๋ ‰ํ† ๋ฆฌ์™€ ๊ทธ ํ•˜์œ„ ํŒŒ์ผ ๋ฐ ๋””๋ ‰ํ† ๋ฆฌ์— ๋Œ€ํ•œ ์†Œ์œ ์ž์™€ ๊ทธ๋ฃน์„ redis:redis๋กœ ๋ณ€๊ฒฝ

ls -alt /etc/redis/redis.conf: /etc/redis/redis.conf
ํŒŒ์ผ์˜ ๊ถŒํ•œ๊ณผ ์†Œ์œ ์ž ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

sudo chmod 600 /etc/redis/redis.conf: /etc/redis/redis.conf
ํŒŒ์ผ์˜ ๊ถŒํ•œ์„ ๋ณ€๊ฒฝํ•˜์—ฌ ํ•ด๋‹น ํŒŒ์ผ์— ๋Œ€ํ•ด ์†Œ์œ ์ž๋งŒ ์ฝ๊ธฐ ๋ฐ ์“ฐ๊ธฐ ๊ถŒํ•œ์„ ๋ถ€์—ฌ

sudo apt-get upgrade
์‹œ์Šคํ…œ์˜ ํŒจํ‚ค์ง€ ๋ฆฌ์ŠคํŠธ๋ฅผ ์—…๋ฐ์ดํŠธ

 

 

์ด๋ ‡๊ฒŒ ํ•˜๋‹ˆ ๋ ˆ๋””์Šค ์„ค์น˜๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ง„ํ–‰๋˜์—ˆ๋‹ค. 

 

sudo apt-get install redis-server

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
redis-server is already the newest version (6:7.2.3-1rl1~jammy1).
0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.

 

 

 

 

์ฐธ๊ณ ๋กœ ๋ ˆ๋””์Šค ์„ค์น˜ ๊ณผ์ •์€ ์ด๋ ‡๊ฒŒ ํ–ˆ๋‹ค. 

# ๋ ˆ๋””์Šค ์ œ๊ฑฐ ํ›„ ์žฌ์„ค์น˜
sudo apt-get --purge remove redis-server
sudo rm -rf /etc/redis/dump.rdb
sudo apt-get update
sudo apt-get install redis-server

 

 

 

3. ์ฝ”๋“œ ์˜ค๋ฅ˜

 

์ดํ›„ node src/app.js๋กœ ์„œ๋ฒ„ ์‹คํ–‰ํ›„ ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด๋‹ˆ ์ฝ”๋“œ ์˜ค๋ฅ˜๊ฐ€ ์žˆ์—ˆ๋‹ค. 

์ฝ”๋“œ๋ฅผ ์ˆ˜์ •ํ›„ ๋‹ค์‹œ ์ž‘์—…ํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ..

 

cd๋กœ ์ž‘์—…ํŒŒ์ผ์„ ๋‚˜์˜จ ํ›„. ์•„๋ž˜์˜ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ํด๋ก ํ•ด์˜จ ํŒŒ์ผ์„ ์‚ญ์ œํ•œ๋‹ค. 

rm -rf ์‚ญ์ œํ•  ๋””๋ ‰ํ† ๋ฆฌ๋ช…

 

 

๊ทธ๋ฆฌ๊ณ  ๋‹ค์‹œ ํด๋ก ํ›„ ์žฌ์‹œ์ž‘!!!

 

 

 

 

 

4. prisma client ์˜ค๋ฅ˜

 

์ฐธ ํ”„๋ฆฌ์ฆˆ๋งˆ ํด๋ผ์ด์–ธํŠธ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค๋ฉด ์ด๊ฒƒ๋„ ์จ์•ผํ•œ๋‹ค. 

npm add prisma @prisma/client

npx prisma generate

 

 

 

 

5. ์นด์นด์˜ค ๋กœ๊ทธ์ธ ์—๋Ÿฌ

 

์ด๊ฑด ๊ฒฝ๋กœ๋ฅผ localhost๋กœ ์ง€์ •ํ•ด ์ค˜์„œ ๊ทธ๋žฌ๋˜๊ฑฐ๋‹ค. 

์‚ฌ์ดํŠธ์˜ ๊ฒฝ๋กœ์™€, ์ฝ”๋“œ์˜ ๊ฒฝ๋กœ๋ฅผ localhost:ํฌํŠธ๋ฒˆํ˜ธ ๊ฐ€ ์•„๋‹ˆ๋ผ ๋„๋ฉ”์ธ ์ด๋ฆ„์„ ๋„ฃ์–ด์ฃผ๋ฉด ๋œ๋‹ค. 

 

 

 

์ฐธ๊ณ ํ•œ ๋ธ”๋กœ๊ทธ

https://phsun102.tistory.com/120

 

CentOS - Redis.conf ์„ค์ •

https://phsun102.tistory.com/51 CentOS์— Redis์„ค์น˜ ( wget ํ™œ์šฉ ) 0. ๊ธฐ๋ณธ ์„ค์ • ๋‹ค์šด๋กœ๋“œ ํด๋”๋ฅผ ์ƒ์„ฑ ํ›„, ํ•ด๋‹น ํด๋”๋กœ ์ด๋™ mkdir /downloads cd /downloads 1. Redis ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ Redis ๊ณต์‹ ํ™ˆํŽ˜์ด์ง€์—์„œ ํŒŒ์ผ์„ wget ๋ช…

phsun102.tistory.com