--- title: 'DevOps Troubleshooting: Linux Server Best Practiceはすごい本' date: 2014-03-02T15:04:05Z author: kazu634 images: - "ogp/2014-03-02-00001587.webp" categories: - インフラ - Linux tags: - troubleshooting --- <time datetime="2014-03-02T18:46:00+09:00" pubdate data-updated="true">Mar 2<span>nd</span>, 2014</time> <div class="entry-content"> <p> <a href="https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/" onclick="__gaTracker('send', 'event', 'outbound-article', 'https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/', 'DevOps Troubleshooting: Linux Server Best Practice');" name="amazletlink" target="_blank">DevOps Troubleshooting: Linux Server Best Practice</a>を読んでいました。この本、Linuxでトラブルシューティングする人にはとてもお勧めです。他のOSに普段触る人でも、ここで基本的な部分を押さえれば、応用が効かせられるようになるはず!!!とてもお勧め! </p> <h2> この本の立ち位置 </h2> <p> 冒頭部分で次のように書かれています: </p> <blockquote> <p> What makes this book more than just a sysadmin troubleshooting guide is the audience and focus. This book assumes the reader may not be a Linux sysadmin, but instead is a talented developer or QA engineer in a DevOps organization who may not have much system-level Linux experience. </p> </blockquote> <p> 要するにシステム管理者を読者としては想定せず、開発者・QAの人間を読者として位置付けている。この特殊な立ち位置がこの本をとても興味深くしていると思う。 </p> <h2> 問題の切り分け方について </h2> <p> こんなことが書いてあった: </p> <ol> <li> Divide the problem space </li> <li> Practice good communication when collaborating </li> <li> Favor quick simple tests, over slow, complex tests </li> <li> Favor past solutions </li> <li> Document your problems and solutions </li> <li> Know what changed </li> <li> Understand how system works </li> <li> Use the internet, but carefully </li> <li> Resist rebooting </li> </ol> <h2> Why is server slow? </h2> <p> Load Averageが高い場合には要因が三つ考えられる: </p> <ol> <li> CPU-bound </li> <li> RAM-bound (high RAM usage) </li> <li> I/O-bound (Disk or Network) </li> </ol> <p> 通常、CPUバウンドの時の方がI/Oバウンドの時よりもレスポンスが良い傾向にある。 </p> <h3> topコマンドについて </h3> <p> 負荷が高い場合にまずは<code>top</code>コマンドで解析を行う。<code>top</code>コマンドの出力例はこちら: </p> <p> <a href="http://www.flickr.com/photos/42332031@N02/12878045225/" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.flickr.com/photos/42332031@N02/12878045225/', '');" title="top_output by kazu634, on Flickr"><img src="https://c2.staticflickr.com/4/3825/12878045225_869b718f55_o.jpg" width="563" height="94" alt="top_output" /></a> </p> <p> まずはロードアベレージを確認する。ロードアベレージが適切かどうかは、CPUのコア数などによって異なる。コア数は<code>cat /proc/cpuinfo | grep processor | wc -l</code>で調べる。ロードアベレージがコア数の範囲であれば適切と判断できる。 </p> <p> <code>CPU(s)</code>の部分の読み方は以下の通り: </p> <h4> us: user CPU time </h4> <p> Nice値を変更していないユーザプロセスに対して割り当てられているCPU時間の割合。 </p> <h4> sy: system CPU time </h4> <p> カーネルとカーネルプロセスを実行するために割り当てられているCPU時間の割合。 </p> <h4> ni: nice CPU time </h4> <p> Nice値を変更したプロセスに対して割り当てられているCPU時間の割合。 </p> <h4> id: CPU idle time </h4> <p> この値が高い場合CPUバウンドではない。 </p> <h4> wa: I/O wait </h4> <p> I/O待ちをするために割り当てられているCPU時間の割合。この値が低い場合には、ディスク・ネットワークI/Oに起因して負荷が高まっているわけではないと言える。 </p> <h4> hi: hardware interrupts </h4> <p> ハードウェアの割り込みに割り当てられているCPU時間の割合。 </p> <h4> si: software interrupts </h4> <p> ソフトウェアの割り込みに割り当てられているCPU時間の割合。 </p> <h4> st: steal time </h4> <p> ゲストOS内で<code>top</code>コマンドを実行している場合、この数値から他のタスクに割り当てられたために利用できなくなったCPU時間の割合がわかる。 </p> <h2> Why can't I Write to the Disk </h2> <p> ディスク使用量の調査には、<code>du -ckx</code>を使う。 </p> <p> <code>df -h</code>でディスク使用量を確認して異常が見当たらない場合は、inodeの枯渇を疑う。inodeが枯渇しているかどうかは、<code>df -i</code>コマンドで確認できる。 </p> <p> read-onlyになる原因は以下のものがかんがえられる: </p> <ol> <li> 容量の枯渇 </li> <li> inodeの枯渇 </li> <li> マウントオプションなどで read-only を指定している </li> <li> Linux Software RAIDを使用している場合、RAID障害の可能性を考慮する </li> </ol> <h2> Is the server down? </h2> <p> サーバがダウンしているように見える場合の対応方法について: </p> <ol> <li> ケーブルが刺さっているか </li> <li> インターフェースの設定は正しいか? </li> <li> Default Gatewayの設定は適切か? </li> <li> DNSは動いているか? </li> <li> 対象サーバに到達できるか? </li> <li> リモートポートが開放されているか? </li> <li> リモート側で <code>netstat -lnp</code>や<code>iptables -L</code>してみる </li> </ol> <p> <code>ethtool デバイス名</code>でケーブルにつながっていることを確認できる。<code>ifconfig デバイス名</code>でインターフェースの設定を確認できる。<code>route -n</code>でDefault Gatewayを確認できる。DNSの動作は<code>nslookup</code>で確認する。<code>resolv.conf</code>のsearchの設定値に注意する。対象サーバに到達できるかかどうかは<code>traceroute</code>で確かめる。 </p> <hr /> <div class="amazlet-box" style="margin-bottom:0px;"> <div class="amazlet-image" style="float:left;margin:0px 12px 1px 0px;"> <a href="https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/" onclick="__gaTracker('send', 'event', 'outbound-article', 'https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/', '');" name="amazletlink" target="_blank"><img src="https://images-na.ssl-images-amazon.com/images/I/51RdMrou2NL._SL160_.jpg" alt="DevOps Troubleshooting: Linux Server Best Practices" style="border: none;" /></a> </div> <div class="amazlet-info" style="line-height:120%; margin-bottom: 10px"> <div class="amazlet-name" style="margin-bottom:10px;line-height:120%"> <a href="https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/" onclick="__gaTracker('send', 'event', 'outbound-article', 'https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/', 'DevOps Troubleshooting: Linux Server Best Practices');" name="amazletlink" target="_blank">DevOps Troubleshooting: Linux Server Best Practices</a> <div class="amazlet-powered-date" style="font-size:80%;margin-top:5px;line-height:120%"> posted with <a href="http://www.amazlet.com/" onclick="__gaTracker('send', 'event', 'outbound-article', 'http://www.amazlet.com/', 'amazlet');" title="amazlet" target="_blank">amazlet</a> at 14.03.02 </div> </div> <div class="amazlet-detail"> Addison-Wesley Professional (2012-11-09) </div> <div class="amazlet-sub-info" style="float: left;"> <div class="amazlet-link" style="margin-top: 5px"> <a href="https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/" onclick="__gaTracker('send', 'event', 'outbound-article', 'https://www.amazon.co.jp/exec/obidos/ASIN/B00A4G7M06/simsnes-22/ref=nosim/', 'Amazon.co.jpで詳細を見る');" name="amazletlink" target="_blank">Amazon.co.jpで詳細を見る</a> </div> </div> </div> <div class="amazlet-footer" style="clear: left"> </div> </div> </div>