Fanpage Facebook

Cài Nagios trên Raspberry giám sát mạng

Đặt ip static raspberry


auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
auto wlan1
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Cài đặt các gói  sau để có thể cài nagios

Nagios needs a web server running PHP, the GNU build tools and the GD Graphics Library.

sudo apt-get install apache2 php5 libapache2-mod-php5 build-essential libgd2-xpm-dev

Tạo tài khoản và nhóm

We need a user ‘nagios’ and a group ‘nagcmd’ for allowing commands over the web interface. The Apache user (www-data) needs to be added to this group too.

sudo useradd -m -s /bin/bash nagios
sudo groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Optionally set a password for the ‘nagios’ user:

sudo passwd nagios

Download Nagios theo link dưới và giải nén

At the time of this writing Nagios is at version 4.1.1 and the plugins are at 2.2.1.

tar zxvf nagios-4.1.1.tar.gz
tar zxvf nagios-plugins-2.1.1.tar.gz

Cài đặt nagios

Build the required targets and install Nagios in /usr/local/nagios/ .

cd nagios-4.1.1
./configure --with-command-group=nagcmd
make all
sudo make install{,-init, -commandmode, -webconf}
sudo make install install-config


Tạo tài khoản nagiosadmin và đặt password để truy cập vào web interface

Reload Apache:

sudo /etc/init.d/apache2 reload

Cài đặt plugins

Change to the plugin sources directory. Build and install all plugins.

cd ../nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make install

Khởi động nagios

Create a symbolic link as an rc hook to run Nagios on system startup (is rcS.d truly the best place?):

ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Kiểm tra cài đặt

Check if all is well with your Nagios configuration:

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Start the Nagios service:

sudo /etc/init.d/nagios start

Log in to the web interface. (Of course, use the IP address or hostname of your Raspberry Pi.) In my example I surf to:

Cấu hình Nagios

Create a directory:

cd /usr/local/nagios/etc
sudo mkdir conf.d 
sudo chown nagios conf.d

Add this line to nagios.cfg:


We have a Raspberry Pi running a web server at We want to check if it’s reachable and if the HTTP port is available:


define host {
        use                     linux-server
        host_name               raspberrypi
        hostgroups              linux-servers
        notification_period     24x7

define service {
        use                     local-service
        host_name               raspberrypi
        service_description     PING
        check_command           check_ping!100.0,20%!500.0,60%

define service{
        use                     local-service        
        host_name               raspberrypi
        service_description     HTTP
        check_command           check_http

Bây giờ kiểm tra cấu hình mới :

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart Nagios:

sudo /etc/init.d/nagios restart

Tag:Cài Nagios trên Raspberry