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
690
おうちのインターネットが少しだけ早くなるかもしれないおはなし
st1t
0
110
GitLab MeetupでLTした内容
st1t
0
70
SRE本完走して社内勉強会で共有したもの
st1t
0
46
Other Decks in Technology
See All in Technology
[PyCon Korea 2024] Lightning Talk: PyPI패키지를 의심하세요
studioego
PRO
0
130
失敗しないOpenJDKの非互換調査
tabatad
0
230
都市伝説バスターズ「WebアプリのボトルネックはDBだから言語の性能は関係ない」 - Kaigi on Rails 2024
osyoyu
13
4.8k
Kubernetes Summit 2024 Keynote:104 在 GitOps 大規模實踐中的甜蜜與苦澀
yaosiang
0
270
日経ビジュアルデータにおける スクロールテリングと地図/nikkei-tech-talk-26
nikkei_engineer_recruiting
0
160
EKS初心者が早めに知っておきたかったこと
cuorain
0
140
Nix入門パラダイム編
asa1984
1
160
KaigiOnRails2024
igaiga
6
3.6k
入門『状態』#kaigionrails / "state" for beginners with Rails
shinkufencer
2
810
来年もre:Invent2024 に行きたいあなたへ - “集中”と“つながり”で楽しむ -
ny7760
0
110
Why and Why not of enabling swap in Kubernetes
hwchiu
0
470
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
130
Featured
See All Featured
We Have a Design System, Now What?
morganepeng
50
7.2k
RailsConf 2023
tenderlove
29
870
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Happy Clients
brianwarren
97
6.7k
The Cost Of JavaScript in 2023
addyosmani
45
6.2k
Adopting Sorbet at Scale
ufuk
73
9k
Rails Girls Zürich Keynote
gr2m
93
13k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Art, The Web, and Tiny UX
lynnandtonic
296
20k
Code Reviewing Like a Champion
maltzj
519
39k
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