Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Gotanda.rb#48 ECS on Fargateでのハマりポイント
Search
Hiroki Tanaka
November 25, 2020
Technology
1
300
Gotanda.rb#48 ECS on Fargateでのハマりポイント
Gotanda.rb#48でLT発表した『ECS on Fargateでのハマりポイント』です。
Hiroki Tanaka
November 25, 2020
Tweet
Share
More Decks by Hiroki Tanaka
See All by Hiroki Tanaka
機能QA会のすゝめ
hiroki_tanaka
0
180
定期リリースの導入
hiroki_tanaka
0
140
noteの品質課題に立ち上げ直後のQAチームが挑んだ軌跡
hiroki_tanaka
1
1.4k
note初のBug Bashを やってみた
hiroki_tanaka
1
1.4k
コロナ禍の1年間でAWSの資格を 3つ取得した話
hiroki_tanaka
0
330
Rubocop対応のすゝめ
hiroki_tanaka
0
46
Gotanda.rb#47 Mailgun3分クッキング
hiroki_tanaka
1
6.9k
Gotanda.rb#46 権限管理のつらみとPundit
hiroki_tanaka
1
7k
Other Decks in Technology
See All in Technology
DevFest 2024 Incheon / Songdo - Compose UI 조합 심화
wisemuji
0
160
pg_bigmをRustで実装する(第50回PostgreSQLアンカンファレンス@オンライン 発表資料)
shinyakato_
0
120
ガバナンスを支える新サービス / New Services to Support Governance
sejima1105
0
140
コンテナセキュリティのためのLandlock入門
nullpo_head
2
330
組織に自動テストを書く文化を根付かせる戦略(2024冬版) / Building Automated Test Culture 2024 Winter Edition
twada
PRO
18
5.7k
ゼロから創る横断SREチーム 挑戦と進化の軌跡
rvirus0817
3
380
日本版とグローバル版のモバイルアプリ統合の開発の裏側と今後の展望
miichan
1
140
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
140
宇宙ベンチャーにおける最近の情シス取り組みについて
axelmizu
0
120
Qiita埋め込み用スライド
naoki_0531
0
5.3k
PHPerのための計算量入門/Complexity101 for PHPer
hanhan1978
5
720
DUSt3R, MASt3R, MASt3R-SfM にみる3D基盤モデル
spatial_ai_network
2
290
Featured
See All Featured
Agile that works and the tools we love
rasmusluckow
328
21k
Become a Pro
speakerdeck
PRO
26
5k
Optimising Largest Contentful Paint
csswizardry
33
3k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
7k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
26
1.9k
Building Adaptive Systems
keathley
38
2.3k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Transcript
Gotanda.rb#48 ECS on FargateͰͷϋϚΓϙΠϯτ 2020/11/25 גࣜձࣾτϨλ @hiroki_tanaka
ࣗݾհ ɾాத جɿ@hiroki_tanaka ɾSIerɿϑϡʔνϟʔΞʔΩςΫτ(4ؒ) →WebܥϕϯνϟʔɿגࣜձࣾτϨλ(1ؒ) ɾRubyɿ2ɾJavaɿ2ɾSQLɿ5 →࠷ۙΠϯϑϥΤϯδχΞݟश͍தɻ ɾझຯɿεϓϥτΡʔϯɾમ౬८Γ ※3࿈ٳʹࢿྉΛ࡞Ζ͏ͱࢥͬͨͷͰ͕͢ɺ ଳঢ়᙮Ͱ͙ͬͨΓ͍ͯͨͨ͠Ίಥ؏Ͱ͢…͢Έ·ͤΜ(*´Д⊂ʋŠƄŸƃūšŘ
ࠓ͢͜ͱɾ͞ͳ͍͜ͱ ʲ͢͜ͱʳ - nginx+unicorn+RailsΛECS on FargateͰӡ༻͠Α͏ͱࢥͬͨ ࡍʹϋϚͬͨ͜ͱ - nginx+unicornؒͷHTTP௨৴ɾSocket௨৴ͷҧ͍ -
unicornͷΞϓϦέʔγϣϯϩάΛCloudWatch Logsʹग़ྗ͢Δํ๏ ʲ͞ͳ͍͜ͱʳ - RailsͷΞϓϦέʔγϣϯαʔόͷҧ͍ →puma/Webrick/unicornͳͲ - puma/Webrick/unicornͷجຊతͳ͍ํ
ΠϯϑϥΤϯδχΞʹͳΓͨͯͷ ͋Δͷग़དྷࣄ
طଘͷRailsΞϓϦΛ EC2͔ΒECSʹҠߦͯ͠ΈΑ͏ɻ ઌഐ
ݩʑͷEC2ߏ - ҰൠతͳEC2ߏɻ - EC2্ͰnginxͱRails(unicorn)ΛͦΕͧΕىಈͤͯ͞ɺALB ͔Βnginxɺnginx͔ΒRails(unicorn)ʹΞΫηε͢Δɻ - ։ൃڥDockerԽͤͣʹࣗͷϗετ্ʹ࡞͍ͬͯͨɻ
ࠓճࢦͨ͠ͷECSߏ - ҰൠతͳECSߏɻ - ECS্ͰnginxͱRails(unicorn)ͷίϯςφΛͦΕͧΕىಈ͞ ͤͯɺALB͔Βnginxɺnginx͔ΒunicornʹΞΫηε͢Δɻ - ECSFargateͰཧ͠ɺΞϓϦέʔγϣϯϩά CloudWatch Logsʹग़ྗ͢Δɻ
- ։ൃڥdocker-composeΛ ༻͍ͯDockerίϯςφԽɻ
ECS on FargateͷϝϦοτ - FargateΛར༻͢Εɺ৭ʑͳ͜ͱ͕AWSଆʹΞτ ιʔεग़དྷΔͷͰӡ༻ෛՙ͕͍ɻ - EC2ΠϯελϯεͷϓϩϏδϣχϯάཧɻ - ੬ऑੑରԠͷͨΊͷύονͯOSΞοϓσʔτ
- EC2Πϯελϯε্ͷ֤ϛυϧΣΞͷΞοϓσʔτ - ֤ϛυϧΣΞͷόʔδϣϯ߹ੑཧ…etc - ঢ়ଶҟৗ͕ൃੜͨ͠EC2Πϯελϯεͷ࠶ىಈೖΕସ͑ɻ - ϗετϨϕϧͷεέʔϦϯάཧɻ
ECS on FargateͷσϝϦοτ - SSHଓग़དྷͳ͍ͷͰɺσόοΫ͕Γʹ͍͘ɻ - ʮίϯςφʹೖͬͯRailsίϚϯυΛ࣮ߦ͢ΔʯʮΞϓϦ έʔγϣϯϩάΛ֬ೝ͢Δʯͱ͍ͬͨ͜ͱ͕ग़དྷͳ͍ɻ - SSMઃఆ͢ΕೖΕΔΑ͏ʹͳΔ͕ઃఆ͕தʑ໘ɻ
Կͱ͋Ε3BJMTΞϓϦΛ %PDLFSίϯςφԽ͠Α͏ɻ ͦΕΛJNBHFԽͯ͠&$3ʹQVTI͢Εɺ ଟ͏·͍͘͘Ͱ͠ΐʂ
OHJOY͔ΒΤϥʔ͕ฦ٫ʂ
ϋϚΓᶃɿnginx+unicornؒͷ௨৴ํ๏ - nginxͱunicornؒͷଓํ๏ʹUNIXυϝΠϯι έοτ(Socket௨৴)ͱϦόʔεϓϩΩγ(HTTP௨৴)ͷ2 छྨ͋Δɻ - 2ͭͷҧ͍Λશ͘ҙࣝͤͣʹEC2ߏͷ࣌ಉ༷ʹSocket௨৴ Λબ͍ͯͨ͠ɻ - ͜Ε͕ݪҼͰECSʹஔ͖͑ͨࡍʹALB~nginx·ͰḷΓண
͕͘ɺnginx͔Βunicornͷ௨৴͕ग़དྷͣʹ404Τϥʔͱ ͳ͍ͬͯͨɻ
UNIXυϝΠϯιέοτ(Socket௨৴) - UNIXυϝΠϯιέοτ୯ҰϚγϯ্ͷߴޮͳϓ ϩηεؒ௨৴ʹ༻͍ΒΕΔ௨৴ΠϯλʔϑΣʔεɻ - ϑΝΠϧγεςϜΛհͯ͠ϓϩηεಉ࢜ͷ௨৴Λߦ͏ɻ - ϦόʔεϓϩΩγΑΓߴʹಈ࡞͢Δ͕ɺϑΝΠϧγες ϜΛհ͢ΔͷͰ୯ҰϚγϯ্Ͱ͔͠ಈ࡞Ͱ͖ͳ͍ɻ -
EC2ߏͷΑ͏ʹnginxͱunicorn͕ಉҰϚγϯ্ʹ͋Δ߹ ͷҰൠతͳํ๏ɻ
UNIXυϝΠϯιέοτ(Socket௨৴) - Rails্ͷunicornͷઃఆϑΝΠϧͷunicorn.rbͱnginx ͷઃఆϑΝΠϧͷnginx.confԼهͷܗʹͳΔɻ - unicorn.rbϦΫΤετΛड͚औΔϦεφʔʹιέοτͷ PathΛࢦఆ͢Δɻ - nginx.confserverʹunicornͰࢦఆͨ͠UNIXυϝΠϯι έοτͷPathΛࢦఆ͢Δɻ
- nginx.confͷઃఆ - unicorn.rbͷઃఆ
ϦόʔεϓϩΩγ(HTTP௨৴) - ϦόʔεϓϩΩγ௨ৗͷTCP௨৴Λ༻͍ͯɺunicorn ʹϦΫΤετΛߦ͏௨৴ΠϯλʔϑΣʔεɻ - UNIXυϝΠϯιέοτΑΓɻ - nginxͱunicorn͕ผϚγϯ্ʹ͋Δ߹ͷҰൠతͳํ๏ɻ →ECSߏͰɺಉҰλεΫ͕ͩnginxͱRailsผίϯςφͳ ͷͰͪ͜ΒΛ࠾༻͢Δඞཁ͕͋ͬͨɻ
ϦόʔεϓϩΩγ(HTTP௨৴) - Rails্ͷunicornͷઃఆϑΝΠϧͷunicorn.rbͱnginx ͷઃఆϑΝΠϧͷnginx.confԼهͷܗʹͳΔɻ - unicorn.rbϦΫΤετΛड͚औΔϦεφʔʹϙʔτ൪߸Λ ࢦఆ͢Δɻ - nginx.confserverʹ`υϝΠϯ:ϙʔτ൪߸`ͷܗࣜͰunicorn ͕͋ΔRailsΞϓϦΛసૹઌͱͯ͠ࢦఆ͢Δɻ
→ಉҰECSλεΫͷίϯςφؒ௨৴localhostܦ༝Ͱߦ͏ɻ - nginx.confͷઃఆ - unicorn.rbͷઃఆ
RailsΞϓϦʹΞΫηεग़དྷͨʂ
ิɿFargateͰSocket௨৴͍ͨ͠ - FargateͰߴͳ௨৴͕ٻΊΒΕSocket௨৴ʹ ͍ͨ͠߹FargateͷλεΫετϨʔδΛ༻͢Δɻ - Fargate֤ECSλεΫͷϓϩϏδϣχϯά࣌ʹ20GBͷΤ ϑΣϝϥϧετϨʔδׂ͕ΓͯΒΕΔɻ - ͜ͷΤϑΣϝϥϧετϨʔδʹSocketϑΝΠϧΛஔ͠ɺ֤ ίϯςφؒͰڞ༗͢ΔΑ͏ʹઃఆ͢Δ͜ͱͰSocket௨৴͕Մ
ೳʹͳΔɻ
Τϥʔൃੜʂ Ͱɺ3BJMTΞϓϦͷϩά͕$MPVE8BUDI-PHT ʹग़ͯͳ͍͔ΒݪҼෆ໌ʂ
ϋϚΓᶄɿCloudWatch Logsʹϩάग़ྗ - RailsΞϓϦʹ͕ى͖ͨ߹ɺCloudWatch Logs ܦ༝ͰΞϓϦϩάΛ֬ೝ͢Δඞཁ͕͋Δɻ - ECS on EC2ͰSSHग़དྷ͠ίϯςφʹΞΫηεग़དྷΔͨΊ
ϩάϑΝΠϧΛ֬ೝग़དྷΔ͕ɺFargateSSHग़དྷͳ͍ͨ Ίࢀর͕ग़དྷͳ͍ɻ - ͜ΕΛߟྀ͍ͯ͠ͳ͔ͬͨͨΊɺRailsͷΤϥʔ͕ൃੜͨ͠ࡍ ʹϩάΛ֬ೝͰ͖ͣʹࠔͬͨɻ
EC2ɿಛఆͷϩάϑΝΠϧʹग़ྗ - unicorn.rbͷԼهͷՕॴͰunicornͷϩάͷग़ྗઌΛ ఆٛ͢Δɻ - stderr_pathɾstdout_pathʹϩάͷग़ྗઌϑΝΠϧΛࢦఆ ͠ɺͦΕΛखಈͰࢀর͢Δɻ
ECSɿCloudWatch Logsʹग़ྗ - unicornͷϩάΛϩάϑΝΠϧͰͳ͘ɺඪ४ग़ྗ͢ ΔΑ͏ʹ͢Δɻ - unicorn.rbͷstdout_pathstderr_pathΛهࡌ͠ͳ͍͜ͱͰ unicornଆඪ४ग़ྗͱͳΔɻ - ඪ४ग़ྗͷॻ͖ग़͠ઌͱͯ͠ɺECSͷTaskఆٛJSONͰRails
ίϯςφͷlogConfiguration߲ͷϩάग़ྗઌͷ CloudWatch LogsΛࢦఆ͢Δɻ
CloudWatch Logsʹग़ྗग़དྷͨʂ
·ͱΊ - ECSΛ༻͍ͯίϯςφؒͰnginxͱunicornͷ௨৴Λߦ ͏߹ɺݫ֨ͳߴ௨৴͕ٻΊΒΕΔ߹Ҏ֎ HTTP௨৴Λ༻͢Δɻ - Fargateͷ߹SSHଓग़དྷͳ͍ͨΊɺΞϓϦϩά Λඪ४ग़ྗͱͯ͠ɺCloudWatch Logsʹग़ྗ͢Δɻ
͓ΘΓʹ - EC2͔ΒECS on FargateʹRailsΞϓϦΛͤ͑Δͷ ຊհͨ͠ՕॴҎ֎Ͱ୯७Ͱͳ͔͚ͬͨΕͲ ɺख࡞ۀͷഉআɾڥΛҙࣝͤͣʹ։ൃʹूதग़དྷ Δͷ͔ͳΓͷϝϦοτͩͱײͨ͡ɻ - ॳΊͯͷίϯςφԽͳΒɺSSHଓ͕Ͱ͖ͯσόοΫ
͕Γ͍͢ECS on EC2ʹ͢Εྑ͔ͬͨ…ͱ10ճ ޙչͨ͠ɻɻɻ
͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ