Nagiosのインストール。
nagiosユーザーを作成します。
root@www:~# useradd -d /usr/local/nagios/ -M nagios
root@www:~# wget https://downloads.sourceforge.net/project/nagios/nagios-4.x/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: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プラグインインストール。
mysql-clientをインストールします。
root@www:~# apt -y install mysql-client
root@www:~# apt -y install libmysqlclient-dev
root@www:~# wget https://nagios-plugins.org/download/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設定。
nagios.cfgを設定します。
root@www:~# vi /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers
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$
}
Apache2設定。
Nagios用Apache2設定ファイルを設定します。
root@www:~# vi /etc/apache2/sites-available/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 apache2
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/
コメント