[DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ƒ์šฉ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ

2022. 9. 16. 15:27ใ†System ์ž‘์—…์‹ค/DevOps

728x90
๋ฐ˜์‘ํ˜•

 

 

 

์ด ๋‚ด์šฉ์€ ์ธํ”„๋Ÿฐ - Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ ์ž…๋‹ˆ๋‹ค.


ํ•ด๋‹น ๋‚ด์šฉ์˜ Code ๋‚ด์šฉ์€ ์ด ๊ณณ์—์„œ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.



๐Ÿ—‚ ๋ชฉ์ฐจ

โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ž๋™ํ™” ๋„๊ตฌ์˜ ์‚ฌ์šฉ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Infrastructure as Code ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Jenkins + Ansible + Kubernetes ์™€์˜ ์—ฐ๋™
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘  - Pipeline
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ก - SonarQube
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - Advenced Jenkins ์‚ฌ์šฉ โ‘ข - Multi Nodes
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ์ƒ์šฉ ํด๋ผ์šฐ๋“œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ
โ— [DevOps] Jenkins๋ฅผ ์ด์šฉํ•œ CI/CD Pipeline ๊ตฌ์ถ• - ๋ถ€๋ก

 

 

 

 

 

๐Ÿš€ AWS ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๊ธฐ

    ๐Ÿ”ฝ  AWS Cloud

        ๐Ÿ“ฆ ์†Œ๊ฐœ

AWS ์‹ค์Šต ํ™˜๊ฒฝ ๊ตฌ์„ฑ๋„

 

AWS์—์„œ VM์„ ์ด์šฉํ•ด์„œ ์œ„์™€ ๊ฐ™์ด ํ™˜๊ฒฝ์„ ๊ตฌ์„ฑํ•ด ๋ณด๋ ค๊ณ  ํ•ด์š”.

 

 

 

 

        ๐Ÿ“ฆ Image๋ฅผ ์ด์šฉํ•˜์—ฌ EC2 ๋งŒ๋“ค๊ธฐ

EC2์—์„œ EC๋Š” Elastic Computing์˜ ์•ฝ์ž์—์š”.

๊ฐ„๋‹จํ•˜๊ฒŒ Cloud ํ™˜๊ฒฝ์—์„œ ๊ตฌ๋™ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฐ€์ƒ Server๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋˜์š”.


์ตœ์ดˆ ์ฃผ๋‹ˆํ•˜๋ž‘์€ ์œ„์™€ ๊ฐ™์ด ๊ธฐ๋ณธ ์ง€์› - ๋ฌด๋ฃŒ๋กœ ํšŒ์› ๊ฐ€์ž…์„ ํ•˜์˜€์–ด์š”.

 


์ง„์ž…์„ ํ•˜๊ฒŒ ๋˜๋ฉด ์œ„์™€ ๊ฐ™์€ ํ™”๋ฉด์ด ๋ณด์ผํ…๋ฐ, ์—ฌ๊ธฐ์„œ EC2๋กœ ๋“ค์–ด๊ฐˆ๊ฒŒ์š”.



๊ทธ๋ฆฌ๊ณ , ์™ผ์ชฝ์— ์ธ์Šคํ„ด์Šค๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



AWS Resion์— ๋Œ€ํ•ด ์ฃผ๋‹ˆํ•˜๋ž‘์€ ์„œ์šธ์„ ์„ ํƒํ•ด ์ฃผ์—ˆ์–ด์š”.

๊ฐ๊ฐ์˜ Resion์— ๋งŒ๋“ค์–ด์ง„ ๋‚ด์šฉ๋“ค์€ ๊ณต์œ ๊ฐ€ ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ์ ์„ ์žŠ์œผ๋ฉด ์•ˆ๋˜๋Š” ๊ฒƒ์ด์—์š”.



'์ธ์Šคํ„ด์Šค ์‹œ์ž‘'์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



๋จผ์ € ์ด๋ฆ„์—๋‹ค๊ฐ€ ํ•ด๋‹น EC2์˜ ์šฉ๋„๋‚˜, ์ด๋ฆ„์„ ์ ์–ด์ฃผ์„ธ์š”.
๋‚˜์ค‘์— ๋ณ€๊ฒฝ๋„ ๊ฐ€๋Šฅํ•ด์š”!



์ด ๊ณณ์€ ์‚ฌ์šฉํ•  Server์— ์„ค์น˜๋  OS๋ฅผ ๊ณ ๋ฅด๋Š” ๊ณณ์ด์—์š”.

๋†€๋ผ์šด ๊ฑด Mac OS๋„ ์ง€์›์ด ๋œ๋‹ค๋Š” ์‚ฌ์‹ค!!

์ฃผ๋‹ˆํ•˜๋ž‘์€ Amazon Linux๋ฅผ ์ด์šฉํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ

AWS ์ตœ์ดˆ ๊ฐ€์ž… ์‹œ ํ”„๋ฆฌ ํ‹ฐ์–ด Service๋ฅผ 80 ~ 90๊ฐœ ์ •๋„ ์ด์šฉ ๊ฐ€๋Šฅ.
EC2๋Š” ํ•œ๋‹ฌ ๊ธฐ์ค€ 750์‹œ๊ฐ„์”ฉ ๋ฌด๋ฃŒ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ.
๋‹จ, EC2 ์ธ์Šคํ„ด์Šค ๊ฐœ ๋‹น 750์‹œ๊ฐ„์ด ์•„๋‹Œ ๋งŒ๋“ค์–ด ๋…ผ ์ธ์Šคํ„ด์Šค ์ด ์ด์šฉ์‹œ๊ฐ„ ๊ธฐ์ค€.
๋งŒ์•ฝ 10๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ์ด์šฉํ•œ๋‹ค๊ณ  ๊ฐ€์ •ํ–ˆ์„ ๋•Œ, ๊ฐœ ๋‹น 75์‹œ๊ฐ„์”ฉ ์ด์šฉ ๊ฐ€๋Šฅ.

 


์ธ์Šคํ„ด์Šค ์œ ํ˜•์€ Hardware ์œ ํ˜• ํ˜น์€ ์ข…๋ฅ˜๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋˜๊ณ , ์ข€ ๋” ์‰ฝ๊ฒŒ ์„ค๋ช…ํ•˜์ž๋ฉด
๋‚ด๊ฐ€ ๊ฐ–๊ณ ์ž ํ•˜๋Š” ์ปดํ“จํ„ฐ์˜ CPU, Memory๋ฅผ ๊ณ ๋ฅด๋Š” ๊ณณ์ด์—์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ ๋ฌด๋ฃŒ๋กœ ์ด์šฉ(t2.micro)ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์„ ์„ ํƒํ•  ๊ฒƒ์ด์—์š”.





Key Pair๋Š” ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•œ Token ํ˜น์€ ์–ด๋–ค ์•”ํ˜ธํ™” ๋œ Key File์ด๋ผ๊ณ  ๋ณด๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์š”.

์ฃผ๋‹ˆํ•˜๋ž‘์€ ํ˜„์žฌ Key Pair๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ƒˆ๋กœ ๋งŒ๋“ค์–ด ๋ณด๋„๋ก ํ• ๊ฒŒ์š”.



์ฃผ๋‹ˆํ•˜๋ž‘์€ ์œ„์™€ ๊ฐ™์ด Key Pair๋ฅผ ๋งŒ๋“ค์–ด ์ค„๊ฑฐ์—์š”.

ํ˜„์žฌ ์ฃผ๋‹ˆํ•˜๋ž‘์€ Mac OS์—์„œ ์ž‘์—…์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Putty ๊ฐ™์€ Program์„ ์ด์šฉํ•˜์ง€ ์•Š์•„์š”.

๋งŒ์•ฝ Window ์‚ฌ์šฉ์ž ์ค‘ Putty๋‚˜, Xshell ๋“ฑ์„ ์ด์šฉํ•  ์˜ˆ์ •์ด๋ผ๋ฉด .ppk๋ฅผ ์„ ํƒํ•˜๋Š”๊ฒŒ ์ข‹์€ ์„ ํƒ์ผ ์ˆ˜ ์žˆ์–ด์š”.



์ด๋ ‡๊ฒŒ Key Pair๊ฐ€ ๋‚ด๋ ค๋ฐ›๊ธฐ ๋˜์—ˆ์–ด์š”.




๋„คํŠธ์›Œํฌ ์„ค์ • ๋ถ€๋ถ„์—์„œ๋Š” ํฌ๊ฒŒ ๋งŒ์งˆ๊ฒƒ์€ ์—†์ง€๋งŒ, ๋ฐฉํ™”๋ฒฝ์— ๋ณด์•ˆ ๊ทธ๋ฃน ์ƒ์„ฑ์ด๋ผ๋Š” ๊ฒƒ์„ ๊ณต๋ถ€ํ•ด ๋ณด์ž๋ฉด
ํ•ด๋‹น ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋Š” Port์™€ IP ๋“ฑ์„ ๋“ฑ๋กํ•ด์„œ ์™ธ๋ถ€์™€ ํ†ต์‹ ํ•˜๊ฒŒ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๋ถ€๋ถ„์ด์—์š”.
์ด๋Š” ๋ฐฉํ™”๋ฒฝ์ด๋ผ๋Š” ํŠน์„ฑ์„ ๊ณต๋ถ€ํ•˜๋ฉด ๋” ์ข‹์•„์š”!



Storage ์ฆ‰, HDD๋‚˜ SDD ์šฉ๋Ÿ‰์„ ๊ณ ๋ฅด๋Š” ๊ณณ์ด์—์š”.

๊ธฐ๋ณธ 8GB๋ฅผ ์ค€๋‹ค๊ณ  ํ•˜๋Š”๋ฐ, ์ตœ๋Œ€ 30GB๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค๊ณ  ํ•˜๋„ค์š”!

์ฃผ๋‹ˆํ•˜๋ž‘์€ 30GB ์„ ํƒํ• ๊ฒŒ์š”.



์ด ๊ณณ์€ Default Value๋กœ ๋„˜์–ด๊ฐˆ๊ฒŒ์š”.



์ด๋ ‡๊ฒŒ ๋งŒ๋“ค์–ด ๋ณผ๊ฒŒ์š”.

'์ธ์Šคํ„ด์Šค ์‹œ์ž‘' ํด๋ฆญ!




๋‹ค ๋งŒ๋“ค์–ด์กŒ์–ด์š”.

ํ˜น์‹œ ๋ชจ๋ฅด๋‹ˆ ์˜ˆ์ƒ ์š”๊ธˆ ์•Œ๋ฆผ ๋ฐ›๊ธฐ ์žŠ์ง€๋งˆ์„ธ์š”!



์ด๋ ‡๊ฒŒ ์ฃผ๋‹ˆํ•˜๋ž‘์€ ์•Œ๋ฆผ ์„ค์ •์„ ํ–ˆ์–ด์š”.



'๋ชจ๋“  ์ธ์Šคํ„ด์Šค ๋ณด๊ธฐ'๋ฅผ ๋ˆ„๋ฅธ ๋’ค ์ƒˆ๋กœ ๊ณ ์นจ์„ ํ•˜๋ฉด ๋งŒ๋“ค์—ˆ๋˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋ณด์ด๊ฒŒ ๋˜์š”.

 

๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ

์ธ์Šคํ„ด์Šค ์ค‘์ง€ : ๊ธฐ๋™ ์ค‘์ธ ์ธ์Šคํ„ด์Šค System ์ข…๋ฃŒ (Shutdown)
์ธ์Šคํ„ด์Šค ์ข…๋ฃŒ : ์ธ์Šคํ„ด์Šค ์‚ญ์ œ 

๋งŒ์•ฝ ์ธ์Šคํ„ด์Šค ์ค‘์ง€๋ฅผ ํ–ˆ๋‹ค๊ฐ€ ์žฌ ๊ธฐ๋™์„ ํ•˜๊ฒŒ ๋˜๋ฉด Public IP๊ฐ€ ๋ณ€๊ฒฝ๋จ.


๊ณ ์ • IP๋ฅผ ๋ฐ•์•„๋ฒ„๋ฆฌ๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ ์™ผ์ชฝ ๋„คํŠธ์›Œํฌ ๋ฐ ๋ณด์•ˆ์— ํƒ„๋ ฅ์  IP ์„ ํƒ


ํƒ„๋ ฅ์  IP ์ฃผ์†Œ ํ• ๋‹น์„ ๋ˆ„๋ฅด๋ฉด ๊ณ ์ • IP๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ์Œ.

๋‹จ, ๋ˆ ๋‚ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 










 

        ๐Ÿ“ฆ EC2 ์ธ์Šคํ„ด์Šค ์ ‘์†

์ตœ์ดˆ ์ฃผ๋‹ˆํ•˜๋ž‘์€ ๋ณด๋‹ค ํŽธ๋ฆฌํ•˜๊ฒŒ EC2 ์ธ์Šคํ„ด์Šค์— ์ ‘์†ํ•˜๊ธฐ ์œ„ํ•ด SSH Client Tool์„ ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.
๋‹ค์–‘ํ•œ Tool์ด ์žˆ์–ด ์ž…๋ง›์— ๋งž๋Š” ๊ฒƒ์„ ์ด์šฉํ•ด๋„ ์ข‹์„ ๊ฑฐ ๊ฐ™์ง€๋งŒ, ์ฃผ๋‹ˆํ•˜๋ž‘์ด ์„ค์น˜ํ•œ Tool์ด ๊ถ๊ธˆํ•˜์‹œ๋‹ค๋ฉด ์ด ๊ณณ์—์„œ ๋งŒ๋‚˜๋ณด์‹ค ์ˆ˜ ์žˆ์–ด์š”.

 


์ตœ์ดˆ ์œ„์™€ ๊ฐ™์ด SSH Client Tool์—์„œ New Host๋ฅผ ๋“ฑ๋กํ•ด ์ค„ ๊ฑฐ์—์š”.



์œ„์™€ ๊ฐ™์ด Server ์ด๋ฆ„์„ ์ž์œ ๋กญ๊ฒŒ Label์— ์ž…๋ ฅํ•ด์ฃผ๊ณ , EC2 ์ธ์Šคํ„ด์Šค Public IP4 ์ฃผ์†Œ๋ฅผ Address์— ์ž…๋ ฅํ•ด ์ค๋‹ˆ๋‹ค.

EC2 ์ธ์Šคํ„ด์Šค๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ ์ƒ์„ฑ์ด ๋˜๋ฉด ec2-user๋ผ๋Š” ๊ณ„์ •์ด ๋งŒ๋“ค์–ด์ง€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
EC2 ์ธ์Šคํ„ด์Šค๋Š” ID, Password ๋ฐฉ์‹์œผ๋กœ Logingํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ,
์œ„์—์„œ EC2 Key Pair๋ฅผ ๋“ฑ๋กํ•  ๋•Œ, ๋‚ด๋ ค ๋ฐ›์•„์กŒ๋˜ ๊ฐ’์„ ๋“ฑ๋กํ•ด์„œ Login์„ ํ•ด์ฃผ์–ด์•ผ ํ•ด์š”.


Password ์ž…๋ ฅํ•˜๋Š” ๊ณณ ์˜†์— Keys Button์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.



Create a new key๋ฅผ ํด๋ฆญํ• ๊ฒŒ์š”.



์œ„์™€ ๊ฐ™์ด ์ด๋ฆ„์„ ๋“ฑ๋กํ•˜๊ณ ,

Import from key file์„ ๋ˆŒ๋Ÿฌ Key File์„ ๊ฐ€์ ธ์™€ ๋ณผ๊ฒŒ์š”.






 

๊ทธ๋Ÿฌ๋ฉด Private key์— ์œ„์™€ ๊ฐ™์ด ์•”ํ˜ธํ™” ๋œ ๋ฌธ์ž์—ด์ด ๋“ฑ๋ก๋˜๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.
์ €์žฅ์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.



๋“ฑ๋ก๋œ Server Icon์„ ํด๋ฆญํ•ด์„œ Server์— ์ ‘์†ํ•ด ๋ณผ๊ฒŒ์š”.



์ฒ˜์Œ ์ ‘์†ํ–ˆ์„ ๋•Œ, Add and continue๋ฅผ ๋ˆŒ๋Ÿฌ Key๋ฅผ ๋“ฑ๋กํ•ด ์ฃผ๋ฉด ๋˜์š”.



์œ„์™€ ๊ฐ™์ด EC2 ์ธ์Šคํ„ด์Šค์— ์ ‘์†์„ ํ•˜์˜€์–ด์š”.



์ด๋ ‡๊ฒŒ ์ ‘์†์ด ๊ฐ€๋Šฅํ•œ ๊ฑด ์œ„์™€ ๊ฐ™์ด ๋ฐฉํ™”๋ฒฝ์—์„œ 22๋ฒˆ (SSH)์— ๋Œ€ํ•ด ์ฐจ๋‹จ ์ •์ฑ…์ด ์—†๊ณ , ๋ชจ๋‘ ์—ด๋ ค์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.









        ๐Ÿ“ฆ EC2 ์ธ์Šคํ„ด์Šค JAVA ์„ค์น˜

yum update -y

728x90


์ตœ์ดˆ yum Repository๋ฅผ ์ตœ์‹ ํ™” ํ•ด์ค„๊ฒŒ์š”.


yum list java*jdk-devel


์„ค์น˜ ๊ฐ€๋Šฅํ•œ JAVA ๋ชฉ๋ก์„ ํ™•์ธํ•ด ๋ณด๋‹ˆ 1.8 ์ด์ƒ์€ ์—†๋„ค์š”.


ํ•˜์ง€๋งŒ, 1.8 Version์€ ๋„ˆ๋ฌด ๋‚ฎ๊ธฐ ๋•Œ๋ฌธ์— AWS์—์„œ ์ œ๊ณตํ•˜๋Š” jdk 11 Version์„ ๋‚ด๋ ค๋ฐ›๊ธฐ ํ•ด ๋ณผ ๊ฒƒ์ด์—์š”.


sudo curl -L https://corretto.aws/downloads/latest/amazon-corretto-11-x64-linux-jdk.rpm -o aws_corretto_jdk11.rpm

 

sudo yum localinstall aws_corretto_jdk11.rpm

 

java -version



๋‚ด๋ ค ๋ฐ›๊ณ , ์„ค์น˜ํ•ด ์ฃผ์—ˆ์–ด์š”.



sudo /usr/sbin/alternatives --config java


์œ„์˜ ๋ช…๋ น์–ด๋กœ Server์— ์„ค์น˜๋˜์–ด ์žˆ๋Š” JAVA ์ค‘ ๋‚ด๊ฐ€ ์›ํ•˜๋Š” JAVA๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ๋Š” ๋ช…๋ น์–ด์—์š”.

ํ•˜๋‚˜๋ฐ–์— ์—†์–ด์„œ ๊ทธ๋ƒฅ Enter๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋  ๊ฑฐ ๊ฐ™์•„์š”.





๋‚ด๋ ค ๋ฐ›์•˜๋˜ jdk rmp File์€ ์ง€์›Œ์ฃผ์—ˆ์–ด์š”.

 

 

 

 

    ๐Ÿ”ฝ  EC2 ์ธ์Šคํ„ด์Šค

        ๐Ÿ“ฆ Image ๋งŒ๋“ค๊ธฐ

์ด๋ฒˆ์— ํ•ด ๋ณผ ์ž‘์—…์€ ์œ„์—์„œ ๋งŒ๋“  EC2 ์ธ์Šคํ„ด์Šค์— ๋Œ€ํ•œ Image๋ฅผ ๋งŒ๋“ค์–ด JAVA๊ฐ€ ์„ค์น˜๋œ ํ™˜๊ฒฝ์— ์ธ์Šคํ„ด์Šค๋ฅผ ํŽธ๋ฆฌํ•˜๊ฒŒ ์„ค์น˜ํ•˜๊ธฐ ์œ„ํ•œ ์‚ฌ์ „ ์ž‘์—…์„ ํ•ด๋ณด๋ ค๊ณ  ํ•ด์š”.

์šฐ๋ฆฌ๋Š” ์ปดํ“จํ„ฐ์— OS๋ฅผ ์„ค์น˜ํ•  ๋•Œ, ISO File์„ ๋ฐ›์•„์„œ OS๋ฅผ ์„ค์น˜ํ•˜๋Š”๋ฐ, ์ด ISO File์„ ๋งŒ๋“ค์–ด ์ฃผ๋Š” ์ž‘์—…์ด๋ผ๊ณ  ์ƒ๊ฐํ•˜๋ฉด ์ข€ ๋” ์‰ฌ์šธ ๊ฑฐ ๊ฐ™์•„์š”.

 

 


์ตœ์ดˆ EC2 ๋Œ€์‹œ๋ณด๋“œ์—์„œ ์ธ์Šคํ„ด์Šค(์‹คํ–‰ ์ค‘)์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.



ํ•ด๋‹น ์ธ์Šคํ„ด์Šค๋ฅผ ํด๋ฆญํ•˜๊ณ , ์ธ์Šคํ„ด์Šค ์ค‘์ง€๋ฅผ ๋ˆŒ๋Ÿฌ System Off๋ฅผ ํ•ด์ค„๊ฒŒ์š”.

์ฐธ๊ณ ๋กœ ์ธ์Šคํ„ด์Šค ์ข…๋ฃŒ ๋ˆ„๋ฅด๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.




์ธ์Šคํ„ด์Šค๊ฐ€ ๊บผ์ง„ ๋’ค '์ž‘์—…' -> '์ด๋ฏธ์ง€ ๋ฐ ํ…œํ”Œ๋ฆฟ' -> '์ด๋ฏธ์ง€ ์ƒ์„ฑ'์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



์œ„์™€ ๊ฐ™์ด ์ด๋ฏธ์ง€ ์ด๋ฆ„๋งŒ ์ ์–ด์ฃผ๊ณ , ์ด๋ฏธ์ง€ ์ƒ์„ฑ์„ ๋ˆŒ๋Ÿฌ์„œ ์ด๋ฏธ์ง€๋ฅผ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.



Navigation Bar์—์„œ AMI๋ฅผ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.




Image ๋งŒ๋“œ๋Š” ๋ฐ๋Š” ๊ฝค ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฝ๋‹ˆ๋‹ค.



ํ•ด๋‹น Image์— ๋Œ€ํ•œ ์ด๋ฆ„์„ ์ง€์–ด์ฃผ์—ˆ์–ด์š”.








        ๐Ÿ“ฆ Image๋ฅผ ์ด์šฉํ•˜์—ฌ ์ธ์Šคํ„ด์Šค ๋งŒ๋“ค๊ธฐ


์ตœ์ดˆ ์ค‘์ง€ ํ–ˆ๋˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋‹ค์‹œ ์‹œ์ž‘ํ•ด ์ค„๊ฒŒ์š”.



์ฒซ๋ฒˆ์งธ๋กœ ๋งŒ๋“ค์—ˆ๋˜ ์ธ์Šคํ„ด์Šค ์ด๋ฆ„์„ ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.



๋‹ค๋ฅธ ์ธ์Šคํ„ด์Šค์—์„œ ๋ณด๋‹ค ํŽธ๋ฆฌํ•˜๊ฒŒ ์ƒํ˜ธ ์ ‘์†์„ ์œ„ํ•ด ๋ณด์•ˆ ๊ทธ๋ฃน์— Tag๋ฅผ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.

๋ณด์•ˆ ๊ทธ๋ฃน์ด๋ผ๊ณ  ์จ์ ธ ์žˆ๋Š” ๊ณณ ๋ฐ‘์— sg-0ee...์„ ํด๋ฆญํ•ด ๋ณผ๊ฒŒ์š”.




'ํƒœ๊ทธ' Tag์—์„œ 'ํƒœ๊ทธ ๊ด€๋ฆฌ'๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.




'์ƒˆ๋กœ์šด ํƒœ๊ทธ ์ถ”๊ฐ€'๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



์ด๋ ‡๊ฒŒ Key - Value Type์œผ๋กœ Tag๋ฅผ ๋งŒ๋“ค๊ณ , '๋ณ€๊ฒฝ ์‚ฌํ•ญ ์ €์žฅ'์„ ๋ˆŒ๋Ÿฌ ๋น ์ ธ๋‚˜๊ฐ€ ์ค„๊ฒŒ์š”.



์œ„์™€ ๊ฐ™์ด Tag๊ฐ€ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์ง„๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.
์ด Tag๋ฅผ ์ด์šฉํ•ด์„œ ๊ฒ€์ƒ‰ํ•˜์—ฌ ๋ณด์•ˆ ๊ทธ๋ฃน์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์–ด์š”.





๋‹ค์‹œ ์ธ์Šคํ„ด์Šค ์ฐฝ์œผ๋กœ ๋Œ์•„์™€์„œ '์ธ์Šคํ„ด์Šค ์‹œ์ž‘'์„ ๋ˆŒ๋Ÿฌ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.



์œ„์™€ ๊ฐ™์ด ์ธ์Šคํ„ด์Šค ์ด๋ฆ„์„ ์„ค์ •ํ•˜๊ณ ,
์ด๋ฒˆ์—๋Š” Quick Start๊ฐ€ ์•„๋‹Œ '๋‚ด AMI'์—์„œ '๋‚ด ์†Œ์œ '์˜ Image๋ฅผ ์„ ํƒํ•ด์„œ ์œ„์—์„œ ๋งŒ๋“  Image๋ฅผ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.




Key Pair ๋ถ€๋ถ„์—์„œ ์ด ์ „์— ๋งŒ๋“ค์—ˆ๋˜ Key Pair๋ฅผ ์„ ํƒํ•ด ์ฃผ์„ธ์š”.




'๋„คํŠธ์›Œํฌ ์„ค์ •'์—์„œ ๋ณด์•ˆ ๊ทธ๋ฃน์€ '๊ธฐ์กด ๋ณด์•ˆ ๊ทธ๋ฃน ์„ ํƒ'์„ ๋ˆŒ๋Ÿฌ
์ด ์ „์— ๋งŒ๋“ค์—ˆ๋˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ๋“ค์–ด ์žˆ๋Š” ๋ณด์•ˆ ๊ทธ๋ฃน๊ณผ ๋™์ผํ•œ ๋ณด์•ˆ ๊ทธ๋ฃน์„ ์„ ํƒํ•ด ์ค„๊ฒŒ์š”.




์ด๋ฒˆ์—๋Š” 4๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ค„๊ฑฐ์—์š”.

์ด๋ ‡๊ฒŒ ํ•œ ๋’ค '์ธ์Šคํ„ด์Šค ์‹œ์ž‘'์„ ๋ˆŒ๋Ÿฌ์ค„๊ฑฐ์—์š”.




์ด 5๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๊ฐ€ ์กด์žฌํ•˜๊ณ , ๋ฐฉ๊ธˆ ๋งŒ๋“  ์ธ์Šคํ„ด์Šค๊ฐ€ ์ค€๋น„๋˜๊ณ  ์žˆ์–ด์š”!



์ƒˆ๋กญ๊ฒŒ ๋งŒ๋“ค์–ด์ง„ ์ธ์Šคํ„ด์Šค์— ๊ฐ๊ฐ์˜ ์ด๋ฆ„์„ ๋‹ฌ๋ฆฌ ์ฃผ์—ˆ์–ด์š”.




์œ„์™€ ๊ฐ™์ด SSH Client์— ๊ฐ๊ฐ์˜ ์ธ์Šคํ„ด์Šค๋“ค์„ ๋“ฑ๋กํ•ด ์ฃผ์—ˆ์–ด์š”.

Key Pair๋Š” ๋™์ผํ•œ File์„ ์ด์šฉํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ ๋งŒ์งˆ ํ•„์š”์—†์ด ์ด๋ฆ„๊ณผ IP ์ฃผ์†Œ๋งŒ ๋ณ€๊ฒฝํ•ด์„œ ๊ฐ๊ฐ ๋งŒ๋“ค์—ˆ์–ด์š”.




๋ชจ๋“  ์ธ์Šคํ„ด์Šค์— ์ •์ƒ์ ์œผ๋กœ ์ ‘์† ๋˜๋Š” ๊ฑธ ํ™•์ธํ•ด ์ฃผ์—ˆ์–ด์š”.





Jenkins๋กœ ์‚ฌ์šฉํ•  ์ธ์Šคํ„ด์Šค์—์„œ Docker๋กœ ์‚ฌ์šฉํ•  ์ธ์Šคํ„ด์Šค์— Ping Test๋ฅผ ํ–ˆ๋”๋‹ˆ Ping์ด ๊ฐ€์ง€ ์•Š์•„์š”.




์ธ์Šคํ„ด์Šค ์•„๋ฌด๊ฑฐ๋‚˜ ์„ ํƒํ•˜๊ณ , '๋ณด์•ˆ' Tab์—์„œ ๋ณด์•ˆ ๊ทธ๋ฃน ๋ฐ‘์— sg-...์„ ํด๋ฆญํ•ด ์ค„๊ฒŒ์š”.



'์ธ๋ฐ”์šด๋“œ ๊ทœ์น™' ์—์„œ '์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ ํŽธ์ง‘'์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



๊ทœ์น™ ์ถ”๊ฐ€๋ฅผ ๋ˆ„๋ฅธ ๋’ค ์œ ํ˜•์— '๋ชจ๋“  ICMP-IPv4'๋ฅผ ์„ ํƒํ•ด ์ฃผ์—ˆ์–ด์š”.
ICMP๋Š” Ping Testํ•  ๋•Œ, ์‚ฌ์šฉํ•˜๋Š” Protocal ์ด๋ฆ„์ด์—์š”.

๊ทธ๋Ÿฐ ๋’ค ๋‹๋ณด๊ธฐ ๋ชจ์–‘์„ ๋ˆ„๋ฅธ ๋’ค ์šฐ๋ฆฌ๊ฐ€ ์‚ฌ์šฉํ•  ์ธ์Šคํ„ด์Šค๋“ค์ด ๋ฌถ์ธ ๋ณด์•ˆ ๊ทธ๋ฃน์„ ์„ ํƒํ•ด ์ฃผ๋ฉด ๋˜์š”.

๋˜๋„๋ก 0.0.0.0์€ ์„ ํƒํ•˜๋ฉด ์ข‹์ง€ ์•Š์•„์š”.

์ด๋Š” ์–ด๋””์„œ๋“  ์ ‘๊ทผํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.




์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•˜๊ณ , '์„ค์ • ์ €์žฅ'์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.




๋ฐ”๋กœ Ping์ด ๋šซ๋ฆฐ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.








        ๐Ÿ“ฆ Jenkins Server ๊ตฌ์ถ•

sudo amazon-linux-extras install epel -y


์ตœ์ดˆ ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด AWS์—์„œ ์ œ๊ณตํ•˜๋Š” ํ™•์žฅ Package๋ฅผ ์„ค์น˜ํ•˜๋„๋ก ํ• ๊ฒŒ์š”.
์ด๋ ‡๊ฒŒ ํ•˜๋Š” ์ด์œ ๋Š” ํ˜„์žฌ ์‚ฌ์šฉํ•˜๋Š” Linux์— ์ถ”๊ฐ€์ ์ธ Dependency Package๋“ค์„ ํ•œ๋ฒˆ์— ์„ค์น˜ํ•˜๊ธฐ ์œ„ํ•จ์ด์—์š”.


๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
epel์ด๋ž€? Extra Package for Enterprise Linux์˜ ์•ฝ์–ด.

 

sudo wget https://mirror.navercorp.com/apache/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

 



opt Directory์—์„œ Maven ์„ค์น˜ ์••์ถ• File์„ ๋ฐ›์•„์ฃผ์—ˆ์–ด์š”.




sudo tar -xvzf {์••์ถ• File ์ด๋ฆ„}

์œ„์˜ ๋ช…๋ น์–ด๋กœ ์••์ถ•์„ ํ•ด์ œํ•ด ์ฃผ์—ˆ์–ด์š”.


๐Ÿ’ก ์ฐธ๊ณ  ์‚ฌํ•ญ
tar ๋ช…๋ น์–ด Option

-x : File ์••์ถ• ํ•ด์ œ.
-v : ์••์ถ• ๊ณผ์ •์„ ๋ณด์ด๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉ.
-z : gz ์••์ถ• File ์••์ถ• ํ’€๊ธฐ.
-f : File๋ช… ์ง€์ •์„ ์œ„ํ•ด ์‚ฌ์šฉ.

 


์••์ถ• File์„ ์‚ญ์ œํ•˜๊ณ , File ๋ชฉ๋ก์„ ํ™•์ธํ•ด ๋ณด์•˜์–ด์š”.



maven Directory์— ๋“ค์–ด์™”์–ด์š”.


vim ~/.bash_profile


ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์„ค์ •์„ ์œ„ํ•ด M2_HOME๊ณผ ๊ทธ ๋ฐ‘์— PATH ๋‚ด์šฉ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.


source ~/.bash_profile


์œ„์˜ ์„ค์ • ๋‚ด์šฉ์ด ๋“ฑ๋ก๋˜๊ฒŒ ํ•ด ์ฃผ์—ˆ์–ด์š”.



mvn --version


Maven ์„ค์ •์ด ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ ๋˜์—ˆ์–ด์š”.


์ด๋ฒˆ์—๋Š” Git์„ ์„ค์น˜ํ•ด ๋ณผ๊ฒŒ์š”.

sudo yum install -y git

 

git --version


Git๋„ ์ •์ƒ ์„ค์น˜ ์™„๋ฃŒ ํ•˜์˜€์–ด์š”.



์ด๋ฒˆ์—๋Š” ๋ณธ๊ฒฉ์ ์œผ๋กœ Jenkins๋ฅผ ์„ค์น˜ํ•ด ๋ณผ๊ฒŒ์š”.


sudo wget https://mirror.navercorp.com/apache/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz

 

sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key



์œ„์˜ ๋ช…๋ น์–ด๋Š” Server ๋‚ด yum Repository์—

Jenkins ๊ด€๋ จ Package๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ์ง€ ์•Š์„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— yum Repository์— ๋“ฑ๋ก ํ•˜๋Š” ๊ฑฐ์—์š”.
๊ทธ๋ฆฌ๊ณ , Key๋ฅผ ๋“ฑ๋กํ•ด ์ฃผ๋Š” ๊ฒƒ์ด์—์š”.

sudo yum install jenkins


yum ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์„ค์น˜๋ฅผ ์ง„ํ–‰ ํ•ด ์ฃผ์—ˆ์–ด์š”.




Jenkins์—์„œ ์œ„์˜ JAVA Version์œผ๋กœ ์„ค์น˜๋ฅผ ์ง„ํ–‰ํ•  ๋•Œ, ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๊ณ  ํ•˜์—ฌ JAVA Version์„ ๋‹ค๋ฅธ ๊ฑธ๋กœ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.


sudo amazon-linux-extras install java-openjdk11

๋ฐ˜์‘ํ˜•



sudo /usr/sbin/alternatives --config java

 

java -version



์œ„์™€ ๊ฐ™์ด 2๊ฐœ์˜ JDK๊ฐ€ ์„ค์น˜ ๋˜์–ด ์žˆ๋Š”๋ฐ, 2๋ฒˆ์„ ์„ ํƒํ•ด ์ค„ ๊ฒƒ์ด์—์š”.




sudo systemctl status jenkins


Jenkins Deamon์ด ์ฃฝ์–ด์žˆ์–ด์š”.
์‚ด๋ ค์ค˜์•ผ ๊ฒ ์–ด์š”.



Jenkins๋ฅผ ์‚ด๋ ค์ฃผ์—ˆ์–ด์š”.


netstat -anp


Jenkins๋Š” ๊ธฐ๋ณธ์ ์œผ๋กœ 8080 Port๋ฅผ ํ†ตํ•ด ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ ์ ‘์†ํ•  ์ˆ˜ ์žˆ์–ด์š”.

๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— AWS ๋ณด์•ˆ ๊ทธ๋ฃน์—์„œ ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™์— 8080 Port๋ฅผ ์—ด์–ด์ฃผ์–ด์•ผ ํ•ด์š”.



'์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ ํŽธ์ง‘'์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.


 
์ฃผ๋‹ˆํ•˜๋ž‘์€ ์ง‘์—์„œ๋งŒ ์ ‘์†์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ์†Œ์Šค์—์„œ '๋‚ด IP'๋ฅผ ์„ ํƒํ•ด ์ง‘์˜ ๊ณต์ธ IP๊ฐ€ ์„ ํƒ๋˜๋„๋ก ํ•˜๊ณ ,
์œ„์™€ ๊ฐ™์ด 8080 Port๋ฅผ ์—ด์–ด์ฃผ์—ˆ์–ด์š”.

'๊ทœ์น™ ์ €์žฅ'์„ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.



Jenkins ์ดˆ๊ธฐ ํ™”๋ฉด์— ์ ‘์†ํ•œ ๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


cat /var/lib/jenkins/secrets/initialAdminPassword


Jenkins ์ดˆ๊ธฐ ๋น„๋ฐ€๋ฒˆํ˜ธ๋Š” ์œ„์™€ ๊ฐ™์ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


๊ฐ’์„ ์ž…๋ ฅํ•˜๊ณ , Continue๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.


์ด ํ›„์— ์„ค์น˜ ์ž‘์—…์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ณณ์— ์ •์„ฑ์Šค๋Ÿฝ๊ฒŒ ์ค€๋น„ํ•ด ๋‘์—ˆ์–ด์š”.









        ๐Ÿ“ฆ Docker Host Server ๊ตฌ์ถ•

sudo amazon-linux-extras install epel -y


์ตœ์ดˆ AWS Linux ํ™•์žฅ Package๋ฅผ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.


yum update -y


๊ทธ๋Ÿฐ ๋’ค yum Repository ์ตœ์‹ ํ™”๋ฅผ ์ง„ํ–‰ํ•ด ์ค„๊ฒŒ์š”.

sudo yum install -y docker


yum์„ ์ด์šฉํ•ด์„œ Docker๋ฅผ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.




Docker Deamon์„ ๊ธฐ๋™ ์‹œ์ผœ ์ฃผ์—ˆ์–ด์š”.


docker --version && docker version

 

sudo docker version




Docker๊ฐ€ ์ •์ƒ ์„ค์น˜ ๋˜์—ˆ์–ด์š”.


๋งŒ์•ฝ sudo ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜๋Š”๊ฒŒ ๊ท€์ฐฎ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ฒ˜๋ฆฌํ•ด ์ฃผ๋ฉด ๋˜์š”.



์ด๋ ‡๊ฒŒ docker Group์— ec2-user๋ฅผ ๋„ฃ์–ด์ฃผ๋ฉด docker ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, sudo๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์ด์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

๋‹จ, ํ•ด๋‹น shell์„ ์ข…๋ฃŒํ–ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ์—ฐ๊ฒฐํ•ด์ค˜์•ผํ•ด์š”.
์ฆ‰, ๊ณ„์ •์„ Logout ํ–ˆ๋‹ค๊ฐ€ ๋‹ค์‹œ Loging ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.



์œ„์™€ ๊ฐ™์ด sudo ๋ช…๋ น์–ด ์—†์ด ์ด์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”.

docker network ls


์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Docker๊ฐ€ ์ด์šฉ ๊ฐ€๋Šฅํ•œ Network ์ •๋ณด๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.





docker run hello-world


์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๊ฐ„๋‹จํ•˜๊ฒŒ Docker Container๋ฅผ ์ž„์‹œ๋กœ ๊ธฐ๋™ ์‹œ์ผœ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.







        ๐Ÿ“ฆ Tomcat Server ๊ตฌ์ถ•

sudo amazon-linux-extras install epel -y


์ตœ์ดˆ AWS Linux ํ™•์žฅ Package๋ฅผ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.



yum update -y


๊ทธ๋Ÿฐ ๋’ค yum Repository ์ตœ์‹ ํ™”๋ฅผ ์ง„ํ–‰ํ•ด ์ค„๊ฒŒ์š”.



wget https://mirror.navercorp.com/apache/tomcat/tomcat-9/v9.0.65/bin/apache-tomcat-9.0.65.tar.gz


opt Directory ๋ฐ‘์— Tomcat ์„ค์น˜ File์˜ ์••์ถ• File์„ ๋ฐ›์•„์ฃผ์—ˆ์–ด์š”.


sudo tar -xvzf apache-tomcat-...


์œ„์˜ ๋ช…๋ น์–ด๋กœ ์••์ถ•์„ ํ•ด์ œํ•ด ์ค„๊ฒŒ์š”.



์••์ถ• File์„ ์‚ญ์ œํ•ด ์ฃผ์—ˆ์–ด์š”.


sudo chmod +x ./bin/startup.sh && sudo chmod +x ./bin/shutdown.sh


์œ„์˜ ๋ช…๋ น์–ด๋กœ ๊ฐ๊ฐ์˜ Shell Script์— ์‹คํ–‰ ๊ถŒํ•œ์„ ์ถ”๊ฐ€ํ•ด ์ฃผ์—ˆ์–ด์š”.


sudo ./bin/startup.sh


์œ„์™€ ๊ฐ™์ด Tomcat Service๋ฅผ ๊ธฐ๋™ํ•ด ์ฃผ์—ˆ์–ด์š”.




์œ„์™€ ๊ฐ™์ด ์ •์ƒ ์ ‘์†์ด ๋˜์—ˆ์–ด์š”!


๋ช‡ ๊ฐ€์ง€ ์„ค์ • ์ž‘์—…์„ ์ถ”๊ฐ€๋กœ ํ•ด ๋ณผ๊ฒŒ์š”.


sudo vim ./webapps/manager/META-INF/context.xml (๋ณ€๊ฒฝ ์ „)

 

sudo vim ./webapps/manager/META-INF/context.xml (๋ณ€๊ฒฝ ํ›„)


์œ„์™€ ๊ฐ™์ด Value Tag๋ฅผ ์ฃผ์„ ์ฒ˜๋ฆฌ ํ–ˆ์–ด์š”.




sudo vim ./webapps/host-manager/META-INF/context.xml (๋ณ€๊ฒฝ ์ „)



sudo vim ./webapps/host-manager/META-INF/context.xml (๋ณ€๊ฒฝ ํ›„)


์œ„์™€ ๋™์ผํ•œ ๋ถ€๋ถ„์„ ์ฃผ์„์ฒ˜๋ฆฌ ํ•ด ์ฃผ์—ˆ์–ด์š”.


์ด๋ ‡๊ฒŒ ์„ค์ •ํ•ด ์ฃผ๋Š” ์ด์œ ๋Š” 

์œ„ ๊ทธ๋ฆผ์—์„œ 'Manager App' ๋ถ€๋ถ„์— ๋ชจ๋“  IP๊ฐ€ ๋‹ค ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก ์—ด์–ด์ค€ ๊ฒƒ์ด์—์š”.



์ด๋ฒˆ์—” Tomcat ๊ด€๋ฆฌ์ž ๊ณ„์ •๋“ค์„ ์ถ”๊ฐ€ํ•ด ๋ณผ๊ฒŒ์š”.



sudo vim ./conf/tomcat-users.xml (๋ณ€๊ฒฝ ์ „)

 

sudo vim ./conf/tomcat-users.xml (๋ณ€๊ฒฝ ํ›„)

 

<role rolename="manager-gui" />
<role rolename="manager-script" />
<role rolename="manager-jmx" />
<role rolename="manager-status" />
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status" />
<user username="deployer" password="deployer" roles="manager-script" />
<user username="tomcat" password="tomcat" roles="manager-gui" />




์œ„์™€ ๊ฐ™์ด Script ๋งจ ๋ฐ‘์— ๋ถ€๋ถ„์„ ์ˆ˜์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.




๊ทธ๋Ÿฐ ๋’ค ์œ„์™€ ๊ฐ™์ด Tomcat Service๋ฅผ ์žฌ ๊ธฐ๋™ ํ•ด ์ฃผ์—ˆ์–ด์š”.




Tomcat์— ์›น ๋ธŒ๋ผ์šฐ์ €๋กœ ๋ถ™์–ด์„œ 'Manager App'์— ๋“ค์–ด๊ฐ€ ์ค„๊ฒŒ์š”.



Script์—์„œ ๋“ฑ๋กํ•œ tomcat ๊ณ„์ •์„ ์ž…๋ ฅํ•ด ์ค๋‹ˆ๋‹ค.



์ •์ƒ ์ ‘์† ๋˜์—ˆ์–ด์š”!







        ๐Ÿ“ฆ Ansible Server ๊ตฌ์ถ•

sudo amazon-linux-extras install epel -y


์ตœ์ดˆ AWS Linux ํ™•์žฅ Package๋ฅผ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.



yum update -y


๊ทธ๋Ÿฐ ๋’ค yum Repository ์ตœ์‹ ํ™”๋ฅผ ์ง„ํ–‰ํ•ด ์ค„๊ฒŒ์š”.



sudo yum install -y ansible


yum์„ ์ด์šฉํ•ด์„œ ansible์„ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.


cd /etc/ansible


Ansible์€ ์ด ๊ณณ์— ์œ„์น˜ํ•˜๊ณ  ์žˆ์–ด์š”.


sudo vim /etc/ansible/hosts


์œ„์™€ ๊ฐ™์ด Host ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์—ˆ์–ด์š”.

์ฐธ๊ณ ๋กœ Public IP๊ฐ€ ์•„๋‹Œ Private IP๋กœ ๋“ฑ๋ก์„ ํ•ด ์ค€ ๊ฒƒ์ด์—์š”.




ssh-keygen -t rsa


Ansible Server์—์„œ Docker Host Server ๊ทธ๋ฆฌ๊ณ , Tomcat Server์— SSH ์ ‘์†์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด
Ansible Server์—์„œ SSH Key๋ฅผ ์ƒ์„ฑํ•ด์ฃผ์—ˆ๋Š”๋ฐ, rsa ์•”ํ˜ธํ™” ๋ฐฉ์‹์˜ Key๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด Key๊ฐ€ ์ƒ์„ฑ์ด ๋˜์—ˆ๋Š”๋ฐ, ๊ณต๊ฐœํ‚ค(.pub)๋ฅผ ๊ฐ๊ฐ์˜ Server์— ์ „๋‹ฌํ•ด ์ค„๊ฑฐ์—์š”.


cat id_rsa.pub


์œ„์˜ ๊ณต๊ฐœํ‚ค ๊ฐ’์„ ๋ณต์‚ฌํ•ด ์ค๋‹ˆ๋‹ค.



๋จผ์ € Docker Server์— ๋“ฑ๋กํ•ด ๋ณผ๊ฒŒ์š”.

vim ~/.ssh/authorized_keys (๋ณ€๊ฒฝ ์ „)


์ด๋ฏธ ํ•˜๋‚˜ Key๊ฐ€ ์žˆ๋„ค์š”.


vim ~/.ssh/authorized_keys (๋ณ€๊ฒฝ ํ›„)


์•ŒํŒŒ๋ฒณ o Key๋ฅผ ๋ˆŒ๋Ÿฌ ๋งจ ๋ฐ‘์œผ๋กœ ์ด๋™ํ•œ ๋’ค ๋ณต์‚ฌํ•œ Key ๊ฐ’์„ ๋ถ™ํ˜€๋„ฃ์–ด ์ฃผ์—ˆ์–ด์š”.


์ด๋Ÿฌํ•œ ์„ค์ •์„ Tomcat Server์—๋„ ๋™์ผํ•˜๊ฒŒ ์ ์šฉํ• ๊ฒŒ์š”.


vim ~/.ssh/authorized_keys



ssh {๊ณ„์ •๋ช…}@{๋Œ€์ƒ Server IP}


์œ„์™€ ๊ฐ™์ด Docker Server์— SSH๋กœ ์ ‘์†ํ•ด๋ณด๋‹ˆ ๊ณ„์ •์„ ๋ฌป์ง€ ์•Š๊ณ , ๋ฐ”๋กœ ์ ‘์†ํ•˜๋Š” ๊ฑธ ๋ณผ ์ˆ˜ ์žˆ์–ด์š”.


ssh {๊ณ„์ •๋ช…}@{๋Œ€์ƒ Server IP}


Tomcat Server๋„ ์ •์ƒ ์ ‘์† ๋˜์—ˆ์–ด์š”.


์ด๋ฒˆ์—๋Š” Ansible Server์—์„œ ๋“ฑ๋ก๋œ Server๋“ค์—๊ฒŒ Ping์„ ๋‚ ๋ ค๋ณผ๊ฒŒ์š”.

ansible {Ansble Hosts File์— ๋“ฑ๋ก๋œ Group ์ด๋ฆ„} -m ping


์œ„์™€ ๊ฐ™์ด ์ •์ƒ์ ์œผ๋กœ Ping์ด ๊ฐ”์–ด์š”.



Localhost ์ฆ‰, Ansible ์ž๊ธฐ ์ž์‹ ์€ SSH์— ๋Œ€ํ•œ ์„ค์ •์„ ํ•ด ์ฃผ์ง€ ์•Š์•„ ์œ„์™€ ๊ฐ™์ด Ping Test๊ฐ€ ๊ฐ€์ง€ ์•Š์•„์š”.

Tomcat, Docker Server์— ํ•ด ์ฃผ์—ˆ๋“ฏ์ด SSH Key ๊ฐ’์„ ์ „๋‹ฌํ•ด ์ค˜์•ผํ•ด์š”.


vim ~/.ssh/authorized_keys


Ansible Server๋„ SSH Key๋ฅผ ๋“ฑ๋กํ•ด ์ฃผ์—ˆ์–ด์š”.


ansible {Ansble Hosts File์— ๋“ฑ๋ก๋œ Group ์ด๋ฆ„} -m ping


์ž๊ธฐ ์ž์‹ ์—๊ฒŒ ์ œ๋Œ€๋กœ Ping์ด ๋‚ ์•„๊ฐ„๊ฑธ ํ™•์ธํ•  ์ˆ˜ ์žˆ์–ด์š”.


ansible all -m ping











        ๐Ÿ“ฆ SonarQube Server ๊ตฌ์ถ•

AWS t2.micro ์ธ์Šคํ„ด์Šค๋กœ SonarQube๋ฅผ ์„ค์น˜ํ•˜๊ฒŒ ๋˜๋ฉด ์ž์› ๋ถ€์กฑ์œผ๋กœ ์ธํ•ด ๊ธฐ๋™์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
๊ทธ๋ž˜์„œ ์œ ๋ฃŒ๋กœ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ตœ์†Œ ์ธ์Šคํ„ด์Šค t2.small ์ด์ƒ์„ ์ด์šฉํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ฃผ๋‹ˆํ•˜๋ž‘์€ ๊ตณ์ด ์œ ๋ฃŒ๋กœ ์ด์šฉํ•ด ๋ณด๊ณ  ์‹ถ์ง€๋Š” ์•Š๊ณ , Synology NAS Docker์— SonarQube๊ฐ€ ์˜ฌ๋ผ๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์„ค์น˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋งŒ ์ •๋ฆฌํ•˜๊ณ , ๊ธฐ๋™ํ•˜์ง„ ์•Š๊ฒ ์Šต๋‹ˆ๋‹ค.

 

sudo amazon-linux-extras install epel -y


์ตœ์ดˆ AWS Linux ํ™•์žฅ Package๋ฅผ ์„ค์น˜ํ•ด ์ค„๊ฒŒ์š”.



yum update -y


๊ทธ๋Ÿฐ ๋’ค yum Repository ์ตœ์‹ ํ™”๋ฅผ ์ง„ํ–‰ํ•ด ์ค„๊ฒŒ์š”.

 

sudo mkdir /opt/sonarqube


์ตœ์ดˆ opt Directory ๋ฐ‘์— sonarqube Directory๋ฅผ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ์–ด์š”.
๊ทธ๋ฆฌ๊ณ  sonarqube Directory๋กœ ๋“ค์–ด๊ฐ€ ์ค๋‹ˆ๋‹ค.



sudo wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-7.6.zip


Sonarqube 7.6 Version์„ ๋‚ด๋ ค๋ฐ›๊ธฐ ํ•˜์˜€์–ด์š”.


sudo unzip {์••์ถ• File ์ด๋ฆ„.zip}

zip์œผ๋กœ ์••์ถ•๋œ File์€ unzip์ด๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์••์ถ• ํ•ด์ œํ•  ์ˆ˜ ์žˆ์–ด์š”.



์••์ถ• File์„ ์ง€์›Œ์คฌ์–ด์š”.


์ด์ œ ๋ช‡๊ฐ€์ง€ ๊ถŒํ•œ์„ ๋ฐ”๊พธ๋Š” ์ž‘์—…์„ ํ•ด ๋ณผ๊ฑฐ์—์š”.

๊ทธ ์ด์œ ๋Š” SonarQube๋Š” Elastic Search์™€ ๊ฐ™์€ Service์™€ ์—ฐ๊ณ„ ๋˜์–ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋Š”๋ฐ,
root ๊ถŒํ•œ์ด ์•„๋‹ ๊ฒฝ์šฐ ํ•ด๋‹น Service๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์—†๋‹ค๊ณ  Error๊ฐ€ ๋‚˜์˜ฌ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.


sudo chown -R ec2-user:ec2-user /opt/sonarqube


SonarQube Directory ์†Œ์œ ๊ถŒ์„ ec2-user์—๊ฒŒ ๋ชจ๋‘ ์ด์ „ํ•˜์˜€์–ด์š”.


cd sonarqube-7.6

 

cd /opt/sonarqube/sonarqube-7.6/conf


์ด๋ฒˆ์—๋Š” SonarQube ์„ค์ •์„ ํ™•์ธ ํ•ด ๋ณผ๊ฒŒ์š”.


vim /opt/sonarqube/sonarqube-7.6/conf/sonar.properties


์ฐธ๊ณ ๋กœ vi๋‚˜, vim Editor์—์„œ Line Number๋ฅผ ์•Œ๊ธฐ ์œ„ํ•ด์„  :์„ ๋ˆ„๋ฅด๊ณ , set nu๋ฅผ ์ž…๋ ฅํ•˜๊ณ , Enter๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

113๋ฒˆ์งธ ์ค„์— ๋ณด๋ฉด ํ˜„์žฌ SonarQube์— ์›น ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ด์šฉํ•ด์„œ ๋ถ™์„ ์ˆ˜ ์žˆ๋Š” Port ๋ฒˆํ˜ธ๊ฐ€ ๋‚˜์˜ค๋Š”๋ฐ,
์ด ๊ณณ์„ ๋ณ€๊ฒฝํ•˜๋ฉด ํ•ด๋‹น Port ๋ฒˆํ˜ธ๋กœ ๋ถ™์„ ์ˆ˜ ์žˆ์–ด์š”.


sudo ./sonar.sh start


์œ„์˜ ๋ช…๋ น์–ด๋กœ SonarQube๋ฅผ ๊ธฐ๋™ ์‹œ์ผœ ์ฃผ์—ˆ์–ด์š”.


AWS ์ธ๋ฐ”์šด๋“œ์—์„œ 9000๋ฒˆ Port๋„ ์—ด์–ด์ค˜์•ผ ๊ฒ ์–ด์š”.




์œ„์™€ ๊ฐ™์ด 9000 Port๋„ Open ํ•ด ์ฃผ์—ˆ์–ด์š”.


SonarQube์— ์„ค์ • ๋ฐฉ๋ฒ• ๋“ฑ์— ๋Œ€ํ•ด์„œ๋Š” ์ด ๊ณณ์— ์ •๋ฆฌ๋ฅผ ํ•ด ๋‘์—ˆ์–ด์š”.




    ๐Ÿ”ฝ  AWS EC2 ๋ฐฐํฌํ•˜๊ธฐ

        ๐Ÿ“ฆ Tomcat Server


์ตœ์ดˆ Jenkins์˜ Jenkins ๊ด€๋ฆฌ์—์„œ 'ํ”Œ๋Ÿฌ๊ทธ์ธ ๊ด€๋ฆฌ'๋กœ ๋“ค์–ด๊ฐˆ๊ฒŒ์š”.


Maven Integration, Deploy to container plugin ์„ค์น˜






์ด๋ฒˆ์—” Jenkins ๊ด€๋ฆฌ์— 'Global Tool Configuration'์œผ๋กœ ๋“ค์–ด๊ฐˆ๊ฒŒ์š”.



์ด ๊ณณ์—์„œ Maven ์„ค์ •์„ ํ•ด ์ค„๊ฒŒ์š”.

์ตœ์ดˆ Add Maven์„ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



์ฃผ๋‹ˆํ•˜๋ž‘์€ Jenkins Server์— Maven์„ ์„ค์น˜ํ•ด ์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์—
'Install automatically'๋ฅผ ํ•ด์ œํ•ด ์ค„๊ฑฐ์—์š”.

MAVEN_HOME์€ Maven Directory๊ฐ€ ์žˆ๋Š” ๊ณณ์„ ์„ค์ •ํ•ด ์ฃผ๊ณ ,
์ด๋ฆ„์€ ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ์ฃผ์—ˆ์–ด์š”.

์ €์žฅํ•˜๊ณ , ํ•ด๋‹น ์ฐฝ์„ ๋‚˜์™€์ฃผ์—ˆ์–ด์š”.


์ด์ œ Item์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด ๋ณผ๊ฒŒ์š”.

Item ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๊ณ , 'Maven project'๋ฅผ ๋ˆŒ๋Ÿฌ์ค€ ๋’ค 'OK'๋ฅผ ๋ˆŒ๋Ÿฌ์ค๋‹ˆ๋‹ค.


์ตœ์ดˆ Git Repository๋ถ€ํ„ฐ ๋“ฑ๋กํ•ด ์ค„๊ฒŒ์š”.

Credentials๋Š” ํ˜„์žฌ Repository๊ฐ€ Pubilc์ด๋ผ ๋”ฐ๋กœ ์„ค์ •ํ•˜์ง„ ์•Š์ง€๋งŒ,

Private์ด๋ผ๋ฉด Git Hub Token์„ ๋“ฑ๋กํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

์ด ๋‚ด์šฉ์— ๋Œ€ํ•ด์„  ์ด ๊ณณ์— ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.


๋งŒ์•ฝ ๊ด€๋ฆฌํ•˜๋Š” Branch ์ด๋ฆ„์ด master๊ฐ€ ์•„๋‹ˆ๋ผ๋ฉด ์ˆ˜์ •ํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.



๊ทธ๋ฆฌ๊ณ , Build ๋ถ€๋ถ„์—์„œ ์œ„์™€ ๊ฐ™์ด ์„ค์ •ํ•ด ์ค๋‹ˆ๋‹ค.


๋นŒ๋“œ ํ›„ ์กฐ์น˜ ๋ถ€๋ถ„์—์„œ '๋นŒ๋“œ ํ›„ ์กฐ์น˜ ์ถ”๊ฐ€'๋ฅผ ๋ˆ„๋ฅธ ๋’ค 'Deploy war/ear to...'์„ ์„ ํƒํ•ด ์ฃผ์„ธ์š”.

์œ„์™€ ๊ฐ™์ด WAR File ์ •๋ณด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ๊ณ , Tomcat Version์„ ์„ ํƒํ•ด ์ฃผ์„ธ์š”.


Tomcat Server์™€ ์—ฐ๋™์„ ์œ„ํ•ด Credentials๋ฅผ ๋“ฑ๋กํ•ด ์ค„๊ฒŒ์š”.
'Add'๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์„ธ์š”.



์œ„์™€ ๊ฐ™์ด Tomcat Script์—์„œ ๋งŒ๋“  deployer ๊ณ„์ •์„ ๋“ฑ๋กํ•ด ์ฃผ์—ˆ์–ด์š”.


 

๋‚˜๋จธ์ง€๋Š” ์œ„์™€ ๊ฐ™์ด ๋“ฑ๋กํ•ด ์ฃผ์—ˆ์–ด์š”.
Tomcat URL์€ Tomcat Server์˜ ๊ณต์ธ IP๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์–ด์•ผ ํ•ด์š”.

์ €์žฅ์„ ํ•˜๊ณ , Build๋ฅผ ์ง„ํ–‰ํ•ด ๋ณผ๊ฒŒ์š”.



Build๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์™„๋ฃŒ๊ฐ€ ๋˜๋ฉด ์œ„์™€ ๊ฐ™์ด workspace Directory์— Project Directory๊ฐ€ ๋งŒ๋“ค์–ด์ ธ์š”.


์ด์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด ๊ณณ์— ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.






        ๐Ÿ“ฆ Docker Server


์ตœ์ดˆ Jenkins ๊ด€๋ฆฌ์—์„œ 'ํ”Œ๋Ÿฌ๊ทธ์ธ ๊ด€๋ฆฌ'๋กœ ๋“ค์–ด๊ฐ€ ์ค„๊ฒŒ์š”.

publish over ssh ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜


์œ„์˜ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•ด ์ฃผ์„ธ์š”.



์ด๋ฒˆ์—” Jenkins ๊ด€๋ฆฌ์— '์‹œ์Šคํ…œ ์„ค์ •'์„ ๋“ค์–ด๊ฐ€ ์ค๋‹ˆ๋‹ค.


๋งจ ๋ฐ‘์— SSH Server๋ฅผ ์ถ”๊ฐ€ํ•ด ์ค„๊ฒŒ์š”.



๋“ฑ๋กํ•˜๊ธฐ ์ „์— Jenkins์—์„œ Docker Server๋กœ ssh๋ฅผ ํ†ตํ•ด ์ ‘์†ํ•˜๋ ค ํ–ˆ์ง€๋งŒ, ๊ถŒํ•œ์ด ์—†๋‹ค๊ณ  ๋‚˜์˜ค๊ณ  ์žˆ์–ด์š”.

Ansible Server๋ฅผ ๋งŒ๋“ค ๋•Œ, Docker์™€ Tomcat Server์— SSH Key ๊ฐ’์„ ์ „๋‹ฌํ•ด ์ฃผ์—ˆ๋Š”๋ฐ, ๋™์ผํ•œ ์ž‘์—…์„ ํ•ด์ค„๊ฒŒ์š”.


ssh-keygen -t rsa


Jenkins Server์—์„œ SSH Key๋ฅผ ๋งŒ๋“ค์—ˆ์–ด์š”.


cat ~/.ssh/id_rsa.pub


์œ„ ๊ณต๊ฐœํ‚ค๋ฅผ Tomcat๊ณผ Docker์— ์ „๋‹ฌํ•ด ์ค„๊ฒŒ์š”.


vim ~/.ssh/authorized_keys


Docker Server์— ์œ„์™€ ๊ฐ™์ด ๋“ฑ๋กํ•ด ์ฃผ์—ˆ์–ด์š”.



Docker Server์— SSH๋กœ ์ธ์ฆ ์—†์ด ์ •์ƒ์ ์œผ๋กœ ์ ‘์†ํ–ˆ์–ด์š”.



Jenkins์—์„œ SSH๋กœ Docker์™€ ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •์„ ์œ„์™€ ๊ฐ™์ด ํ•ด์คฌ๋Š”๋ฐ, ์—ฐ๊ฒฐ์ด ๋˜์ง€ ์•Š๊ณ  ์žˆ์–ด์š”.
์ด ๋ฌธ์ œ์˜ ์ด์œ ๋Š” ์ง€์ •ํ•œ Key๋ฅผ ํ†ตํ•ด์„œ SSH ์ ‘์† ์‹œ๋„๋ฅผ ํ•˜์ง€ ์•Š์•„์„œ์—์š”.

'๊ณ ๊ธ‰' Button์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.

์œ„์™€ ๊ฐ™์ด 'Use Password authentication ..'์„ ํ™œ์„ฑํ™” ํ•ด์ค„๊ฒŒ์š”.
๊ทธ๋Ÿฐ ๋’ค SSH Key ๊ฐ’์„ ๋“ฑ๋กํ•ด์ค˜์•ผ ํ•ด์š”.


์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‚˜์˜ค๋Š” ์•”ํ˜ธํ™” ๋œ ๋ฌธ์ž์—ด์„ ๋“ฑ๋กํ•ด ์ค˜์•ผ ํ•ด์š”.


ํ•ด๋‹น ๊ฐ’์„ Key ๋ถ€๋ถ„์— ๋ชจ๋‘ ๋ณต์‚ฌํ•ด์„œ ๋“ฑ๋กํ•ด ์ค๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋กœ -----BEGIN RSA PRIVATE KEY----- ๋ถ€ํ„ฐ
-----END RSA PRIVATE KEY----- ๊นŒ์ง€์˜ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ๋‹ค ๋ณต์‚ฌํ•ด์„œ ๋„ฃ์–ด์ค˜์•ผ ํ•ด์š”.


๋‹ค์‹œ Test๋ฅผ ์ง„ํ–‰ํ•˜๋‹ˆ ์ •์ƒ ์—ฐ๊ฒฐ ๋˜์—ˆ์–ด์š”.

์ €์žฅํ•˜๊ณ , ํ•ด๋‹น ์ฐฝ์„ ๋‚˜๊ฐ€์ค„๊ฒŒ์š”.



์œ„์™€ ๊ฐ™์ด Item์„ ๋งŒ๋“œ๋Š”๋ฐ, ์œ„์—์„œ ๋งŒ๋“ค์—ˆ๋˜ Item์— ๋‚ด์šฉ์„ ๊ทธ๋Œ€๋กœ ๊ฐ€์ ธ์˜ฌ๊ฒŒ์š”.


Build ํ›„ ์กฐ์น˜์— Tomcat ์„ค์ • ๋‚ด์šฉ์„ ์ง€์›Œ์ค„๊ฒŒ์š”.



๊ทธ๋Ÿฐ ๋’ค ๋‹ค์‹œ '๋นŒ๋“œ ํ›„ ์กฐ์น˜ ์ถ”๊ฐ€'๋ฅผ ๋ˆŒ๋Ÿฌ์ค€ ๋’ค 'Send build ...'๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.



์œ„ ์„ค์ •์—์„œ ๋“ฑ๋กํ–ˆ๋˜ Docker Server ์ด๋ฆ„์„ ์ฐพ์•„ Name์— ์„ ํƒํ•ด ์ฃผ๊ณ , Build ๋Œ€์ƒ File์„ ์„ ํƒํ•ด ์ฃผ๋ฉด ๋˜์š”.

์ด์— ๋Œ€ํ•œ ์ž์„ธํ•œ ๋‚ด์šฉ์€ ์ด ๊ณณ์— ์ •๋ฆฌํ•ด ๋‘์—ˆ์–ด์š”.



์œ„์™€ ๊ฐ™์ด Build๊ฐ€ ์„ฑ๊ณตํ–ˆ์–ด์š”.



Docker Server์—์„œ ec2-user์˜ Home Directory๋ฅผ ํ™•์ธํ•ด ๋ณด๋‹ˆ 'hello-world.war'๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ „๋‹ฌ ๋˜์—ˆ์–ด์š”.


vim ~/Dockerfile


์œ„์™€ ๊ฐ™์ด Dockerfile์„ ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”.

docker build --tag={Docker Image Name(์ž์œ  ๊ธฐ์žฌ)} -f Dockerfile .;
docker run -d -p 8080:8080 --name {Docker Container Name(์ž์œ  ๊ธฐ์žฌ)} {Docker Image Name(์ž์œ  ๊ธฐ์žฌ)}:{Image Version ์ •๋ณด}


๋‹ค๋ฅธ ์„ค์ •์€ ๊ทธ๋Œ€๋กœ ๋‘๊ณ , ํ•ด๋‹น Dockerfile๋กœ Image๋ฅผ ๋งŒ๋“ค๊ณ , Container๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ๋Š” ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”.



Build๊ฐ€ ์„ฑ๊ณตํ–ˆ์–ด์š”.





Docker Image์™€ Container๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ๋งŒ๋“ค์–ด์ ธ ์žˆ์–ด์š”.



Docker ๊ณต์ธ IP์˜ 8080 Port์— URI๋ฅผ ๋„ฃ์–ด์ฃผ๋‹ˆ ์œ„์™€ ๊ฐ™์ด ์ •์ƒ ์ ‘์† ๋˜์—ˆ์–ด์š”.










        ๐Ÿ“ฆ Ansible Server


์ตœ์ดˆ Jenkins์— Ansible ๋“ฑ๋ก์„ ์œ„ํ•ด Jenkins ๊ด€๋ฆฌ์—์„œ '์‹œ์Šคํ…œ ์„ค์ •'์— ๋“ค์–ด๊ฐ€ ์ค„๊ฒŒ์š”.



SSH Server์— '์ถ”๊ฐ€'๋ฅผ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.


๊ทธ๋Ÿฐ ๋’ค ์ด๋ฆ„์„ ์ž์œ ๋กญ๊ฒŒ ์ •์˜ํ•ด ์ฃผ๊ณ , Hostname์—๋Š” Ansible Server Private IP๋ฅผ ์ ์–ด์ค๋‹ˆ๋‹ค.


'๊ณ ๊ธ‰'์„ ๋ˆŒ๋Ÿฌ์ค„๊ฒŒ์š”.




Jenkins Server์—์„œ ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‚˜์˜ค๋Š” ์•”ํ˜ธํ™” ๋œ ๋ฌธ์ž์—ด์„ ๋“ฑ๋กํ•ด ์ค˜์•ผ ํ•ด์š”.




ํ•ด๋‹น ๊ฐ’์„ Key ๋ถ€๋ถ„์— ๋ชจ๋‘ ๋ณต์‚ฌํ•ด์„œ ๋“ฑ๋กํ•ด ์ค๋‹ˆ๋‹ค.

์ฐธ๊ณ ๋กœ -----BEGIN RSA PRIVATE KEY----- ๋ถ€ํ„ฐ
-----END RSA PRIVATE KEY----- ๊นŒ์ง€์˜ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ๋‹ค ๋ณต์‚ฌํ•ด์„œ ๋„ฃ์–ด์ค˜์•ผ ํ•ด์š”.

 

cat ~/.ssh/id_rsa.pub


์œ„์™€ ๊ฐ™์ด Jenkins Server์˜ SSH Public Key์„ ๋ณต์‚ฌํ•˜์—ฌ Ansible Server์— ๋„ฃ์–ด์ค„๊ฒŒ์š”.


vim ~/.ssh/authorized_keys


์œ„์™€ ๊ฐ™์ด Key ๊ฐ’์„ ๋ณต์‚ฌํ•ด์„œ ์ €์žฅํ•ด ์ฃผ์„ธ์š”.






๊ทธ๋Ÿฐ ๋’ค Test๋ฅผ ๋ˆŒ๋Ÿฌ์ค˜์„œ ์„ฑ๊ณต ์—ฌ๋ถ€๋ฅผ ํ™•์ธํ•ด ์ฃผ์—ˆ์–ด์š”.




์œ„์™€ ๊ฐ™์ด Project๋ฅผ ๋งŒ๋“ค์–ด ์ค„๊ฒŒ์š”.


 

๊ธฐ์กด์— Docker Project ๋‚ด์šฉ์—์„œ ๋นŒ๋“œ ํ›„ ์กฐ์น˜์— Docker Container๋ฅผ ๋งŒ๋“œ๋Š” ๋ช…๋ น์–ด๋งŒ ์ง€์›Œ์คฌ์–ด์š”.

Image๋Š” Docker Server์—์„œ ๋งŒ๋“ค๊ณ , Docker Container๋Š” Ansible Server์—์„œ ๋งŒ๋“ค๋ ค๊ณ  ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด์—์š”.



'Add Server'๋ฅผ ๋ˆŒ๋Ÿฌ Ansible์— ๋Œ€ํ•œ ์„ค์ •์„ ํ•ด์ค„๊ฒŒ์š”.



๋‹ค๋ฅธ ๊ณณ์€ ๋ชจ๋‘ ๊ทธ๋Œ€๋กœ ๋‘๊ณ , Exec command์— playbook์„ ์‚ฌ์šฉํ•˜๋Š” ๋ช…๋ น์–ด๋ฅผ ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.


- hosts: all
#   become: true  

  tasks:
  - name: stop current running container
    command: docker stop junyharang-cicd-study-ansible
    ignore_errors: yes

  - name: remove stopped cotainer
    command: docker rm junyharang-cicd-study-ansible
    ignore_errors: yes

  - name: create a container using cicd-project-ansible image
    command: docker run -d --name junyharang_cicd_project -p 8080:8080 junyharang/junyharang-cicd-study-ansible

vim ~/create-cicd-devops-container.yml


Docker Server์—์„œ ๋งŒ๋“ค์–ด์ง„ Image๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ž‘์—…์„ ํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์ด Script ๋ฌธ์„ ์ž‘์„ฑํ•ด ์ฃผ์—ˆ์–ด์š”.


vim /home/ec2-user/hosts


์ž„์˜๋กœ ๋งŒ๋“  hosts File์— Docker ์ •๋ณด๋ฅผ ์œ„์™€ ๊ฐ™์ด ๋„ฃ์–ด์ฃผ์—ˆ์–ด์š”.


Jenkins์˜ Project๋ฅผ ์ €์žฅํ•˜๊ณ , Build๋ฅผ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.










๐Ÿง ์ฐธ๊ณ  ์ž๋ฃŒ

 

 

 

 

 

 

 

 

 

728x90
๋ฐ˜์‘ํ˜•