ブログ?

もうだめぽ

nginx + Nagios のインストール(前編)

Fedora16にnginxとNagiosを使った監視サーバを構築してみます。
nginx固有の部分を覗いて基本的に公式のマニュアル通り *1 です。

パッケージのインストール

まずコンパイル、Web UI表示のために色々いれます。

$ sudo yum install gcc glibc glibc-common gd gd-devel nginx php  fcgi-devel spawn-fcgi php-fpm

ユーザ、グループ作成

Nagios用のユーザを作成します。

$ sudo useradd -m nagios
$ sudo passwd nagios


次にグループを作成し、nagiosユーザとnginxユーザを所属させます。
これはWebインタフェースからのコマンド実行のため用います。

$ sudo useradd -m nagios
$ sudo groupadd nagios
$ sudo usermod -a -G nagios nagios
$ sudo usermod -a -G nagios nginx

Nagiosのコンパイル・インストール

Nagiosの公式サイトからNagios Coreのソースファイルをダウンロード、展開します。
sedの箇所を実施しないとmake installの途中でエラーになりますので気をつけてください。

$ cd /tmp
$ curl http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.3.1/nagios-3.3.1.tar.gz | tar zxv
$ cd nagios
$ ./configure
$ sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile
$ sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile
$ make all

なお、configureのオプションを指定しない場合こんな感じになります。

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /bin/traceroute


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

次にインストールします。

$ sudo make install install-init install-commandmode
$ sudo make install-config

ちなみにApacheの場合はfullinstallとするとApache向けのコンフィグもインストールしてくれます。
install-configについてはサンプルのコンフィグをインストールしてくれます。

あとはお好みで自動起動設定でもすればOKです。

nagios-pluginsのコンパイル・インストール

nagios pluginsはNagiosが監視をするためのコマンドたちです。
先ほどインストールしたコンフィグで監視するためにはnagios pluginsが必要になります。

現時点での最新版は1.4.15ですが、しばらくリリースされていないのでGit版にします。
autoconf, automake, gitが必要になるのでインストールしておいてください。

こちらは特に難しいことはなく、レポジトリをクローンしてconfigureスクリプトを作成、実行、make、make installして完了です。

$ cd /tmp
$ git clone git://nagiosplug.git.sourceforge.net/gitroot/nagiosplug/nagiosplug
$ cd nagiosplug
$ ./tools/setup
$ ./configure
$ make && sudo make install

なお、ライブラリ等の有無によって作成されるプラグインに違いが出てきますので詳しくはドキュメントを確認してください。
例えばMySQLの接続性を監視したい場合はmysql-develなどが必要になります。

Nagiosを起動する

とりあえず監視するのに必要なものはインストールされたので、Nagiosを起動してみます。

$ sudo service nagios start

ただし、これだけでは何も見えません。
Webサーバの設定については次回書こうと思います。