Nagiosのインストール.
Nagiosに必要なモジュールをインストールします。
root@www:~# dnf -y install gd-devel
root@www:~# useradd -d /usr/local/nagios/ -M nagios
root@www:~# wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.4.6/nagios-4.4.6.tar.gz
root@www:~# tar zxvf nagios-4.4.6.tar.gz
root@www:~# cd nagios-4.4.6
root@www:~# dnf -y install patch
root@www:nagios-4.4.6# wget http://ftp.momo-i.org/pub/security/nagios/patches/nagios-jp-4.4.6.patch.gz
root@www:nagios-4.4.6# gzip -dc nagios-jp-4.4.6.patch.gz |patch -p1
root@www:nagios-4.4.6# ./configure && make all && make fullinstall && make install-config
root@www:nagios-4.4.6# cd
root@www:~# rm -rf nagios-4.4.6
root@www:~# rm -f nagios-4.4.6.tar.gz
Nagiosプラグインインストール.
Nagiosプラグインをダウンロードします。
root@www:~# wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.3.3/nagios-plugins-2.3.3.tar.gz
root@www:~# tar zxvf nagios-plugins-2.3.3.tar.gz
root@www:~# cd nagios-plugins-2.3.3
root@www:nagios-plugins-2.3.3# ./configure && make && make install
root@www:nagios-plugins-2.3.3# cd
root@www:~# rm -rf nagios-plugins-2.3.3
root@www:~# rm -f nagios-plugins-2.3.3.tar.gz
Nagios設定.
ファイルを設定します。
root@www:~# vi /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers
日付書式:YYYY-MM-DD HH:MM:SS
date_format=iso8601
root@www:~# mkdir /usr/local/nagios/etc/servers
root@www:~# vi /usr/local/nagios/etc/objects/contacts.cfg
define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email root@localhost }
root@www:~# vi /usr/local/nagios/etc/objects/localhost.cfg
define service{ use local-service ; Name of service template to use host_name localhost service_description SSH check_command check_ssh notifications_enabled 1 }
define service{ use local-service ; Name of service template to use host_name localhost service_description HTTP check_command check_http notifications_enabled 1 }
root@www:~# vi /usr/local/nagios/etc/objects/commands.cfg
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/nkf -j | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/nkf -j | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
Apache httpd設定.
Nagios用Apache httpd設定ファイルを設定します。
root@www:~# vi /etc/httpd/conf.d/nagios.conf
<RequireAny>
# Require all granted
Require ip 192.168.1.1/24
</RequireAny>
<RequireAny>
# Require all granted
Require ip 192.168.1.1/24
</RequireAny>
root@www:~# systemctl restart httpd
root@www:~# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
Nagios起動.
起動します。
root@www:~# systemctl restart nagios
nagios:http://ubuntuserver.jp/nagios/
管理ユーザー:nagiosadmin
コメント