1,180 views

■概要

サーバーに不具合が起きても、気づくまでに時間がかかるのが常です。統合監視システムNagios(ナギオス)は、サーバーに不具合が起きるとメールをくれるので、不具合に気づくまでの時間を短縮できます。今回は、バックアップデータを活用して、Nagiosの復元をしてみました。インストールのし直しだと半時間は少なくとも必要ですが、復元だと10分以内には完了できます。

■事前準備

Webサーバー構築済であること
リポジトリ導入(EPEL,RPMforge)を参照してEPELリポジトリが導入済であること
Nagiosのバックアップが取られていること

■導入手順

統合監視システムNagiosをyumでインストールし、バックアップしたファイルをコピーするという単純な手順です。ついでに、Sambaを監視項目に追加すると不明のエラーが出る問題も応急手当ですが今回解消しています。

■Nagiosインストール

[root@ufuso ~]# yum --enablerepo=epel -y install nagios nagios-plugins nagios-plugins-all
 ← EPELからNagios、基本プラグインをインストール
Installed:
  nagios.x86_64 0:3.3.1-3.el6              nagios-plugins.x86_64 0:1.4.15-2.el6
  nagios-plugins-all.x86_64 0:1.4.15-2.el6

Dependency Installed:
  fping.x86_64 0:2.4b2-10.el6
  gd.x86_64 0:2.0.35-10.el6
  lm_sensors.x86_64 0:3.1.1-10.el6
  nagios-common.x86_64 0:3.3.1-3.el6
  nagios-plugins-breeze.x86_64 0:1.4.15-2.el6
  nagios-plugins-by_ssh.x86_64 0:1.4.15-2.el6
  nagios-plugins-cluster.x86_64 0:1.4.15-2.el6
  nagios-plugins-dhcp.x86_64 0:1.4.15-2.el6
  nagios-plugins-dig.x86_64 0:1.4.15-2.el6
  nagios-plugins-disk.x86_64 0:1.4.15-2.el6
  nagios-plugins-disk_smb.x86_64 0:1.4.15-2.el6
  nagios-plugins-dns.x86_64 0:1.4.15-2.el6
  nagios-plugins-dummy.x86_64 0:1.4.15-2.el6
  nagios-plugins-file_age.x86_64 0:1.4.15-2.el6
  nagios-plugins-flexlm.x86_64 0:1.4.15-2.el6
  nagios-plugins-fping.x86_64 0:1.4.15-2.el6
  nagios-plugins-game.x86_64 0:1.4.15-2.el6
  nagios-plugins-hpjd.x86_64 0:1.4.15-2.el6
  nagios-plugins-http.x86_64 0:1.4.15-2.el6
  nagios-plugins-icmp.x86_64 0:1.4.15-2.el6
  nagios-plugins-ide_smart.x86_64 0:1.4.15-2.el6
  nagios-plugins-ircd.x86_64 0:1.4.15-2.el6
  nagios-plugins-ldap.x86_64 0:1.4.15-2.el6
  nagios-plugins-load.x86_64 0:1.4.15-2.el6
  nagios-plugins-log.x86_64 0:1.4.15-2.el6
  nagios-plugins-mailq.x86_64 0:1.4.15-2.el6
  nagios-plugins-mrtg.x86_64 0:1.4.15-2.el6
  nagios-plugins-mrtgtraf.x86_64 0:1.4.15-2.el6
  nagios-plugins-mysql.x86_64 0:1.4.15-2.el6
  nagios-plugins-nagios.x86_64 0:1.4.15-2.el6
  nagios-plugins-nt.x86_64 0:1.4.15-2.el6
  nagios-plugins-ntp.x86_64 0:1.4.15-2.el6
  nagios-plugins-nwstat.x86_64 0:1.4.15-2.el6
  nagios-plugins-oracle.x86_64 0:1.4.15-2.el6
  nagios-plugins-overcr.x86_64 0:1.4.15-2.el6
  nagios-plugins-perl.x86_64 0:1.4.15-2.el6
  nagios-plugins-pgsql.x86_64 0:1.4.15-2.el6
  nagios-plugins-ping.x86_64 0:1.4.15-2.el6
  nagios-plugins-procs.x86_64 0:1.4.15-2.el6
  nagios-plugins-real.x86_64 0:1.4.15-2.el6
  nagios-plugins-rpc.x86_64 0:1.4.15-2.el6
  nagios-plugins-sensors.x86_64 0:1.4.15-2.el6
  nagios-plugins-smtp.x86_64 0:1.4.15-2.el6
  nagios-plugins-snmp.x86_64 0:1.4.15-2.el6
  nagios-plugins-ssh.x86_64 0:1.4.15-2.el6
  nagios-plugins-swap.x86_64 0:1.4.15-2.el6
  nagios-plugins-tcp.x86_64 0:1.4.15-2.el6
  nagios-plugins-time.x86_64 0:1.4.15-2.el6
  nagios-plugins-ups.x86_64 0:1.4.15-2.el6
  nagios-plugins-users.x86_64 0:1.4.15-2.el6
  nagios-plugins-wave.x86_64 0:1.4.15-2.el6
  net-snmp-utils.x86_64 1:5.5-37.el6
  postgresql-libs.x86_64 0:8.4.9-1.el6_1.1
  qstat.x86_64 0:2.11-9.20080912svn311.el6                                      

Complete!

[root@ufuso ~]#  /bin/cp -Rf /mnt/usbhd/all/backup/sl6/etc/nagios/objects/contacts.cfg /etc/nagios/objects/
 ← contacts.cfgの復元

[root@ufuso ~]#   /bin/cp -Rf /mnt/usbhd/all/backup/sl6/etc/httpd/conf.d/nagios.conf /etc/httpd/conf.d/
 ← nagios.confの復元

[root@ufuso ~]# /bin/cp -Rf /mnt/usbhd/all/backup/sl6/etc/nagios/passwd nagiosadmin /etc/nagios/ ← nagiosadminの復元
/bin/cp: cannot stat `nagiosadmin': そのようなファイルやディレクトリはありません ← バックアップの取り忘れでファイル無し

[root@ufuso ~]#  htpasswd /etc/nagios/passwd nagiosadmin
 ← Nagios管理ユーザー(nagiosadmin)のパスワード作成
New password: ← 任意のパスワード入力※表示はされない
Re-type new password: ← パスワード再入力(確認)※表示はされない
Updating password for user nagiosadmin

[root@ufuso ~]# /bin/cp -Rf /mnt/usbhd/all/backup/sl6/etc/nagios/nagios.cfg /etc/nagios/ ← nagios.cfgの復元

[root@ufuso ~]# /bin/cp -Rf /mnt/usbhd/all/backup/sl6/etc/nagios/objects/localhost.cfg  ← localhost.cfgの復元

[root@ufuso ~]# /bin/cp -Rf /mnt/usbhd/all/backup/sl6/etc/nagios/objects/commands.cfg  ← commands.cfgの復元

[root@ufuso ~]# /etc/rc.d/init.d/nagios start ← nagios起動
Starting nagios: done.
[root@ufuso ~]# chkconfig --add nagios ← 自動起動メニューに追加
[root@ufuso ~]# chkconfig nagios on ← 自動起動の設定

[root@ufuso ~]#  yum -y install gd-devel ← グラフや図の表示に必要なのでインストール
Installed:
  gd-devel.x86_64 0:2.0.35-10.el6                                               

Dependency Installed:
  fontconfig-devel.x86_64 0:2.8.0-3.el6
  freetype-devel.x86_64 0:2.3.11-6.el6_1.8
  libX11-devel.x86_64 0:1.3-2.el6
  libXau-devel.x86_64 0:1.0.5-1.el6
  libXdmcp-devel.x86_64 0:1.0.3-1.el6
  libXpm-devel.x86_64 0:3.5.8-2.el6
  libjpeg-devel.x86_64 0:6b-46.el6
  libpng-devel.x86_64 2:1.2.48-1.el6_2
  libxcb-devel.x86_64 0:1.5-1.el6
  xorg-x11-proto-devel.noarch 0:7.6-13.el6                                      

Complete!

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

http://サーバー名/nagios/へアクセスし、「サービス」で追加したサービスが表示されることを確認。

■Sambaを監視項目に追加

[root@ufuso ~]#  vi /usr/share/perl5/Getopt/Long.pm ← Long.pmファイルの 487行目当たりを表示
    # Process argument list
    my $goon = 1;
    while ( $goon && @$argv > 0 ) {

        # Get next argument.
        $opt = shift (@$argv) || ''; ← || ''(which is 2 | (pipe characters) and 2 ' (single quotes)を追記
        print STDERR ("=> arg "", $opt, ""n") if $debug;

[root@ufuso ~]# yum install samba-client ← samba-clientをインストール
Package samba-client-3.5.10-114.el6.x86_64 already installed and latest version
Nothing to do ← すでにインストール済み

[root@ufuso ~]# vi /etc/nagios/objects/localhost.cfg ← localhost.cfg編集
以下を最終行に追記
define service{
        use                             generic-service
        host_name                       localhost
        service_description             Samba
        check_command                   check_disk_smb!ufuso.dip.jp!public!workgroup!!
        } ← ufuso.dip.jpはSambaサーバーホスト名、publicはSamba共有名、workgroupはSambaワークグループ名、Sambaユーザー名とSambaユーザーパスワードは未設定のため、!のみ

[root@ufuso ~]#  vi /etc/nagios/objects/commands.cfg ← commands.cfg編集
以下を最終行に追記
# 'check_disk_smb' command definition
define command{
        command_name    check_disk_smb
        command_line    $USER1$/check_disk_smb -H $ARG1$ -s $ARG2$ -W $ARG3$ -u $ARG4$ -p $ARG5$
        }

[root@ufuso ~]# /etc/rc.d/init.d/nagios restart ← Nagios再起動
Running configuration check...done
Stopping nagios: done.
Starting nagios: done.

http://サーバー名/nagios/へアクセスし、「サービス」で追加したサービスが表示されることを確認。

我が家では18項目を監視しています。

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください