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
Linuxシステム概要
Search
Shota Ito
April 12, 2019
Technology
1
70
Linuxシステム概要
社内勉強会ではなしたもの
Shota Ito
April 12, 2019
Tweet
Share
More Decks by Shota Ito
See All by Shota Ito
PHPカンファレンス小田原2024/PHP Conference ODAWARA 2024
st1t
0
700
おうちのインターネットが少しだけ早くなるかもしれないおはなし
st1t
0
110
GitLab MeetupでLTした内容
st1t
0
71
SRE本完走して社内勉強会で共有したもの
st1t
0
47
Other Decks in Technology
See All in Technology
Security-JAWS【第35回】勉強会クラウドにおけるマルウェアやコンテンツ改ざんへの対策
4su_para
0
170
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
180
dev 補講: プロダクトセキュリティ / Product security overview
wa6sn
1
2.3k
オープンソースAIとは何か? --「オープンソースAIの定義 v1.0」詳細解説
shujisado
5
630
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
220
Why App Signing Matters for Your Android Apps - Android Bangkok Conference 2024
akexorcist
0
120
Platform Engineering for Software Developers and Architects
syntasso
1
510
Engineer Career Talk
lycorp_recruit_jp
0
120
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
誰も全体を知らない ~ ロールの垣根を超えて引き上げる開発生産性 / Boosting Development Productivity Across Roles
kakehashi
1
220
AGIについてChatGPTに聞いてみた
blueb
0
130
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Adopting Sorbet at Scale
ufuk
73
9.1k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
KATA
mclloyd
29
14k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
A designer walks into a library…
pauljervisheath
203
24k
Done Done
chrislema
181
16k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
6
410
Transcript
PLAT FORM TEAM SHOTA ITO LINUXγεςϜ֓ཁ
LINUXγεςϜʹ͍ͭͯ ͓ଋ ▸ ࠓΧʔωϧͦͷͷ·Ͱߦ͖ண͖·ͤΜ ▸ ࠓ͢͜ͱΉ͍ͣͰ͢ ▸ ͍ͯ͏͔ɺࢲΘ͔Βͳ͍͜ͱ͕΄΅શͯͰ͢ ▸ Θ͔Βͳ͍ͷ͕ී௨Ͱ͢
▸ ੲͷϓϩάϥϚʔCΛॻ͍ͨܦݧ͔ΒΘ͔Δ͔ ▸ ςʔϚ͕େ͖͗͢ΔͷͰ֓ཁఔͰ͢ ▸ ڵຯΛ࣋ͬͨਓ͕͍ͨΒݸผʹฉ͍͍ͯͩ͘͞
LINUXγεςϜʹ͍ͭͯ ಥવͰ͕͢ LinuxͬͯԿͰ͔͢ʁ
LINUXʢϦφοΫεɺଞͷಡΈޙड़ʣɺ UNIXϥΠΫͳOSΧʔωϧͰ͋ΔLINUXΧʔω ϧɺ͓ΑͼͦΕΛΧʔωϧͱͯ͠पลΛඋ͠ ͨγεςϜɻ Wikipedia
Χʔωϧ σόΠε σόΠευϥΠό εϨου εέδϡʔϥ ϑΝΠϧ γεςϜ ωοτϫʔΫ ελοΫ ԾϝϞϦ
γεςϜίʔϧ ϢʔβϨϕϧ ΧʔωϧϨϕϧ γεςϜϥΠϒϥϦ σʔλϕʔε ΞϓϦέʔγϣϯ
LINUXγεςϜʹ͍ͭͯ ΞϓϦͱΧʔωϧͷؔΘΓํ ▸ ΞϓϦέʔγϣϯϥΠϒϥϦΛ௨ͯ͠ΧʔωϧʹγεςϜ ίʔϧΛൃߦ͍ͯ͠Δ͚ͩ
LINUXγεςϜʹ͍ͭͯ γεςϜϥΠϒϥϦʹ͍ͭͯ
Χʔωϧ σόΠε σόΠευϥΠό εϨου εέδϡʔϥ ϑΝΠϧ γεςϜ ωοτϫʔΫ ελοΫ ԾϝϞϦ
γεςϜίʔϧ ϢʔβϨϕϧ ΧʔωϧϨϕϧ γεςϜϥΠϒϥϦ σʔλϕʔε ΞϓϦέʔγϣϯ
LINUXγεςϜʹ͍ͭͯ γεςϜϥΠϒϥϦͬͯʁ ▸ ༗໊Ͳ͜Ζglibc(GNU C Library) ▸ phpjava࠷ऴతʹglibcΛinclude͍ͯ͠Δ ˞ͪΖΜଞʹࢁinclude͍ͯ͠·͢ ▸
openldap-devel.x86_64, openssl-devel.x86_64, zlib- devel.x86_64… ▸ GNU: GNUͱΦϖϨʔςΟϯάγεςϜͰ͋Γɺ ͔ͭίϯϐϡʔλιϑτΣΞͷൣғʹΔίϨΫγϣϯͰ͋Δɻ (wiki͔ΒҾ༻)
LINUXγεςϜʹ͍ͭͯ MYSQLI.C
LINUXγεςϜʹ͍ͭͯ ZEND_ALLOC.H
LINUXγεςϜʹ͍ͭͯ ZEND_ALLOC.H
LINUXγεςϜʹ͍ͭͯ γεςϜίʔϧʹ͍ͭͯ
Χʔωϧ σόΠε σόΠευϥΠό εϨου εέδϡʔϥ ϑΝΠϧ γεςϜ ωοτϫʔΫ ελοΫ ԾϝϞϦ
γεςϜίʔϧ ϢʔβϨϕϧ ΧʔωϧϨϕϧ γεςϜϥΠϒϥϦ σʔλϕʔε ΞϓϦέʔγϣϯ
LINUXγεςϜʹ͍ͭͯ γεςϜίʔϧͬͯʁ ▸ γεςϜίʔϧɺΞϓϦέʔγϣϯͱ Linux Χʔωϧͱͷ ؒͷجຊతͳΠϯλʔϑΣʔεͰ͋Δɻ(※1) ▸ ϋʔυΣΞΛ͍͘͡ΔͱݖݶΛӽͯ͠ΞΫηεͰ͖ ͯ͠·͏ͨΊɺΧʔωϧ͕ࢦࣔΛड͚͚ΔͨΊͷΠϯλʔ
ϑΣʔε ▸ ex)ϝϞϦΛ֬อͯ͠ʂ௨৴͍͔ͨ͠ΒιέοτΛ։͍ ͯʂϓϩηεΛϑΥʔΫͯ͠ʂ
LINUXγεςϜʹ͍ͭͯ ͲΜͳγεςϜίʔϧ͕͋Δͷ͔ ▸ read/write: ϑΝΠϧσΟεΫϦϓλΛͬͯbyteΛಡΜͰ bufferʹͷͤΔ ▸ mallocɿϝϞϦΛ֬อ͢Δͱ͖ʹίʔϧ͢Δ ▸ clone(fork)ɿϓϩηεΛϑΥʔΫ͢Δ࣌ʹίʔϧ͢Δ
▸ getsocknameɿιέοτͷ໊લΛऔಘ͢Δ࣌ʹίʔϧ͢Δ ▸ accept,accept4 : ιέοτͷଓΛड͚Δ࣌ʹίʔϧ͢Δ
LINUXγεςϜʹ͍ͭͯ APACHE HTTPDͷγεςϜίʔϧΛͷ͍ͧͯݟΔ ▸ શίʔϧΛऔಘ # strace $(for pid in
`pgrep httpd`;do echo -n "-p $pid ";done) ▸ getsockname,accept,accept4Λऔಘ # strace $(for pid in `pgrep httpd`;do echo -n "-p $pid ";done) -e trace=getsockname,accept,accept4 ▸ grepͰߜΔ࣌ strace $(for pid in `pgrep httpd`;do echo -n "-p $pid ";done) 2>&1 | grep '192.168.120.129' ▸ iptablesͰःஅ͢Δͱίʔϧঢ়ଶͲ͏ͳΔʁ
LINUXγεςϜʹ͍ͭͯ TIPS: ύΠϓͷΈ ▸ Α͘͏ʮ|ʯͬͯͲ͏͍͏ͷͳͷ͔ ▸ ΧʔωϧͷϦϯάόοϑΝʹଓ͞ΕͨύΠϓσΟεΫϦϓ λΛհͯ͠௨৴͍ͯ͠Δ
LINUXγεςϜʹ͍ͭͯ TIPS: ύΠϓͷΈˏ֬ೝͯ͠ΈΔ ▸ ྫɿ$ cat hoge.txt | grep ito
▸ ʮcat | grep itoʯΛίʔϧϨϕϧͰ͍͔͚ͯΈΔ ▸ strace -p `pgrep cat` ▸ strace -p `pgrep grep` ▸ lsof -p `pgrep cat` ▸ lsof -p `pgrep grep`
ςΩετ
LINUXγεςϜʹ͍ͭͯ TIPS: ύΠϓͷΈˏղઆ CAT ϓϩηε GREP ϓϩηε Χʔωϧ͕༻ҙ͍ͯ͠ΔϦϯάόοϑΝ /DEV/PTS/0 ϓϩηε
pipe:[412981] ᶃϑΝΠϧσΟεΫϦϓλ̌(࣮ମɿ/dev/pts/0)ΛಡΉ read(0, “hoge¥n”, 65536) ᶄϑΝΠϧσΟεΫϦϓλ̍(࣮ମɿpipe:[412981])ॻ͖ࠐΉ write(1, “hoge¥n”, 5) ᶅϑΝΠϧσΟεΫϦϓλ̌(࣮ମɿpipe:[412981])ΛಡΉ read(0, “hoge¥n”, 32768) write callʹ͍ͭͯ read callʹ͍ͭͯ ϦϯάόοϑΝʹ͍ͭͯ ϑΝΠϧσΟεΫϦϓλʹ͍ͭͯ
LINUXγεςϜʹ͍ͭͯ ΧʔωϧपΓࠓҰ୴͜͜·Ͱ
LINUXγεςϜʹ͍ͭͯ ͜ͷࣝͲ͜Ͱ͍͖ͯ͘Δʁ
LINUXγεςϜʹ͍ͭͯ ϦϦʔεલੑೳτϥϒϧγϡʔτ(࣮ WEB APP ▸ ͳΜ͔Α͘Θ͔Βͳ͍͚Ͳɺ͍ʂௐࠪͯ͠ʂ DB LB ϨεϙϯεͲΕ͘Β ͍Ͱฦ͍ͯ͠Δʁ
Τϥʔʁ ͳͦ͞͏ ΞϓϦͷϨεϙϯε&Τϥʔ ͳͦ͞͏ʁ Ϩεϙϯε͕Ͱͯͳ͍ !! DBॏ͘ͳ͍ʁ ͳͦ͞͏
LINUXγεςϜʹ͍ͭͯ ϦϦʔεલੑೳτϥϒϧγϡʔτ(࣮ APP ▸ APPͷγεςϜίʔϧάϥϑΛऔͬͯΈͨΒ େମׂ̐҉߸ԽॲཧϥΠϒϥϦͷಡΈग़͠ʹ͔͔͍ͬͯͨ ▸ ΞϓϦνʔϜͷਓ͑ͯɺ ҉߸ԽॲཧͷΞϧΰϦζϜΛݟͯ͠Βͬͯղܾ γεςϜίʔϧΛऔಘͭͭ͠
ෛՙΛ͔͚ͯΒͬͯ༰Λ֬ೝ ࢀߟɿCPU Flame Graphs
LINUXγεςϜʹ͍ͭͯ ࣗମΛѲ͢Δ ࢀߟɿLinux Performance Tools
LINUXγεςϜʹ͍ͭͯ ύϑΥʔϚϯενϡʔχϯά ▸ ιέοτ௨৴͍ͯ͠Δ͔ΒϑΝΠϧσΟεΫϦϓλΛ૿͠ ͨํ͕ྑ͍ΑͶ ▸ σʔλϕʔεͷΩϟογϡཧOSͱΞϓϦͲͬͪʹͤ Δʁ ▸ CPU༻͕ߴ͍ʂ
▸ ϢʔβϥϯυʁΧʔωϧϥϯυʁίϯςΩετεΠονʁ
LINUXγεςϜʹ͍ͭͯ ϛυϧΣΞͷΦϓγϣϯ֬ೝ ▸ NginxͷϩάϑΥʔϚοτΦϓγϣϯͬͯυΩϡϝϯτ؆ ୯ʹ͔͠ॻ͍ͯͳ͍͚ͲɺͲ͏ͳ͍ͬͯΔʁ ▸ dstatͷग़ྗͰσʔλ߲͕Γͳ͍ؾ͕͢Δ͚Ͳɺ Ͳ͏ͳ͍ͬͯΔʁ
LINUXγεςϜʹ͍ͭͯ ࢀߟ
LINUXγεςϜʹ͍ͭͯ ࢀߟ(ΏΔ;Θ) ▸ ;ͭ͏ͷLinuxϓϩάϥϛϯά ▸ dstatͷίʔυ͔ΒಡΈղ͘Linuxೖ@tcpΦϓγϣϯฤ ▸ ApacheͷΞΫηε੍ޚݕূΛՄࢹԽ͠ͳ͕ΒͬͯΈͨ
LINUXγεςϜʹ͍ͭͯ ࢀߟ(Ψν) ▸ Linux Networking Architecture ▸ gdb Debugging Full
Example (Tutorial): ncurses
LINUXγεςϜʹ͍ͭͯ Q&A ▸ tcpdumpͲͷϨΠϠʔ͔ΒΩϟϓνϟͨ͠ύέοτΛ ࣋ͬͯདྷ͍ͯΔʁ ▸ Device driver͔Β ࣋ͬͯདྷ͍ͯΔ Ҿ༻ɿLinux
Network Internals