blog/content/posts/2014/2014-03-02-00001587.md

280 lines
8.5 KiB
Markdown
Raw Normal View History

2019-03-31 11:00:21 +00:00
---
title: 'DevOps Troubleshooting: Linux Server Best Practiceはすごい本'
2021-02-27 13:04:45 +00:00
date: 2014-03-02T15:04:05Z
2021-11-13 03:11:49 +00:00
author: kazu634
2019-03-31 11:00:21 +00:00
categories:
2021-11-17 13:56:35 +00:00
- インフラ
2021-02-27 12:05:32 +00:00
- Linux
tags:
- troubleshooting
2019-03-31 11:00:21 +00:00
---
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h2>
この本の立ち位置
</h2>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
冒頭部分で次のように書かれています:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
要するにシステム管理者を読者としては想定せず、開発者・QAの人間を読者として位置付けている。この特殊な立ち位置がこの本をとても興味深くしていると思う。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h2>
問題の切り分け方について
</h2>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
こんなことが書いてあった:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h2>
Why is server slow?
</h2>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
Load Averageが高い場合には要因が三つ考えられる:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<ol>
<li>
CPU-bound
</li>
<li>
RAM-bound (high RAM usage)
</li>
<li>
I/O-bound (Disk or Network)
</li>
</ol>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
通常、CPUバウンドの時の方がI/Oバウンドの時よりもレスポンスが良い傾向にある。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h3>
topコマンドについて
</h3>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
負荷が高い場合にまずは<code>top</code>コマンドで解析を行う。<code>top</code>コマンドの出力例はこちら:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
まずはロードアベレージを確認する。ロードアベレージが適切かどうかは、CPUのコア数などによって異なる。コア数は<code>cat /proc/cpuinfo | grep processor | wc -l</code>で調べる。ロードアベレージがコア数の範囲であれば適切と判断できる。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
<code>CPU(s)</code>の部分の読み方は以下の通り:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
us: user CPU time
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
Nice値を変更していないユーザプロセスに対して割り当てられているCPU時間の割合。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
sy: system CPU time
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
カーネルとカーネルプロセスを実行するために割り当てられているCPU時間の割合。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
ni: nice CPU time
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
Nice値を変更したプロセスに対して割り当てられているCPU時間の割合。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
id: CPU idle time
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
この値が高い場合CPUバウンドではない。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
wa: I/O wait
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
I/O待ちをするために割り当てられているCPU時間の割合。この値が低い場合には、ディスク・ネットワークI/Oに起因して負荷が高まっているわけではないと言える。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
hi: hardware interrupts
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
ハードウェアの割り込みに割り当てられているCPU時間の割合。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
si: software interrupts
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
ソフトウェアの割り込みに割り当てられているCPU時間の割合。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h4>
st: steal time
</h4>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
ゲストOS内で<code>top</code>コマンドを実行している場合、この数値から他のタスクに割り当てられたために利用できなくなったCPU時間の割合がわかる。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h2>
Why can't I Write to the Disk
</h2>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
ディスク使用量の調査には、<code>du -ckx</code>を使う。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
<code>df -h</code>でディスク使用量を確認して異常が見当たらない場合は、inodeの枯渇を疑う。inodeが枯渇しているかどうかは、<code>df -i</code>コマンドで確認できる。
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
read-onlyになる原因は以下のものがかんがえられる:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<ol>
<li>
容量の枯渇
</li>
<li>
inodeの枯渇
</li>
<li>
マウントオプションなどで read-only を指定している
</li>
<li>
Linux Software RAIDを使用している場合、RAID障害の可能性を考慮する
</li>
</ol>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<h2>
Is the server down?
</h2>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<p>
サーバがダウンしているように見える場合の対応方法について:
</p>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<hr />
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<div class="amazlet-info" style="line-height:120%; margin-bottom: 10px">
<div class="amazlet-name" style="margin-bottom:10px;line-height:120%">
2021-11-13 03:11:49 +00:00
<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>
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<div class="amazlet-detail">
Addison-Wesley Professional (2012-11-09)
</div>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<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>
2021-11-13 03:11:49 +00:00
2019-03-31 11:00:21 +00:00
<div class="amazlet-footer" style="clear: left">
</div>
</div>
</div>