To add 2GB of SWAP memory on this droplet:
dd if=/dev/zero of=/swap bs=1024 count=2097152 mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap echo /swap swap swap defaults 0 0 >> /etc/fstab echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p
apt-get install -y nagios3 nagios-nrpe-plugin usermod -a -G nagios www-data chmod -R g+x /var/lib/nagios3/ sed -i 's/check_external_commands=0/check_external_commands=1/g' /etc/nagios3/nagios.cfg
You will be prompted for MySQL root password, we chose "PassWord", you should change it to something stronger.
Set Nagios Admin Panel Password:
htpasswd -c /etc/nagios3/htpasswd.users nagiosadmin service nagios3 restart && service apache2 restart
Make sure to keep this username as "nagiosadmin" - otherwise you would have to change /etc/nagios3/cgi.cfg and redefine authorized admin.
Now you can navigate over to your droplet's Nagios panel at http://IP/nagios3 (http://198.211.117.129/nagios3/ for our example):
You will be prompted to enter your password, which you've specified in Step 3.
As you can see, we don't have any hosts currently being monitored, so lets set that up next.
Now we should add our hosts that will be monitored by Nagios. For example, we will setup monitoring for cloudads.tk (198.211.117.101), which runs Ubuntu 12.10 as well.
From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.
For internal services that are listening on localhost, such as MySQL, memcached, system services, we will need to use NRPE.
apt-get install -y nagios-plugins nagios-nrpe-server
This next step is where you get to specify any manual commands that Monitoring server can send via NRPE to these client hosts.
Make sure to change allowed_hosts to your own values.
Edit /etc/nagios/nrpe.cfg
log_facility=daemon pid_file=/var/run/nagios/nrpe.pid server_port=5666 nrpe_user=nagios nrpe_group=nagios allowed_hosts=198.211.117.129 dont_blame_nrpe=1 debug=0 command_timeout=60 connection_timeout=300 include=/etc/nagios/nrpe_local.cfg include_dir=/etc/nagios/nrpe.d/ command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10 command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/vda command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
Note:
In check_disk above, the partition being checked is /dev/vda - make sure your droplet has the same partition by running df -h /
You can also modify when to trigger warnings or critical alerts - above configuration sets Warning at 20% free disk space remaining, and Critical alert at 10% free space remaining.
We should also setup firewall rules to allow connections from our Monitoring server to those clients and drop everyone else:
iptables -N NRPE iptables -I INPUT -s 0/0 -p tcp --dport 5666 -j NRPE iptables -I NRPE -s 198.211.117.129 -j ACCEPT iptables -A NRPE -s 0/0 -j DROP /sbin/iptables-save
Now you can start NRPE on your client host:
service nagios-nrpe-server restart
Back on our Monitoring server, we will have to create config files for each of our client servers:
All configs can be stored in /etc/nagios3/conf.d in individual .cfg files (for example: /etc/nagios3/conf.d/cloudads.tk.cfg)
Edit /etc/nagios3/conf.d/cloudads.tk.cfg and add the following lines:
define host { use generic-host host_name cloudads.tk alias cloudads.tk address 198.211.117.101 } define service { use generic-service host_name cloudads.tk service_description PING check_command check_ping!100.0,20%!500.0,60% } define service { use generic-service host_name cloudads.tk service_description SSH check_command check_ssh notifications_enabled 0 } define service { use generic-service host_name cloudads.tk service_description Current Load check_command check_load!5.0!4.0!3.0!10.0!6.0!4.0 }
After you are done editing your config files, make sure to restart Nagios for changes to take effect:
service nagios3 restart
You can add more services to be monitored as desired, and even create your own Nagios plugins.
Navigate over to your Monitoring Server's IP address http://IP/nagios3 and enter password set in Step 2.
Now you should be able to see all the hosts and services.
And you are all done!
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This is probably the best guide I have found regarding Nagios and Ubuntu
@chrisgolden72 awesome! Thanks for the feedback :]
RE: Step 1, I receive an error message when I enter the 2nd line. I type:
sudo mkswap /swap && chown root. /swap && chmod 0600 /swap && swapon /swap
and receive the following response:
Setting up swapspace version 1, size = 2097148 KiB no label, UUID=f076cc68-733a-4d96-85fd-f2551d2df688 chown: changing ownership of `/swap’: Operation not permitted
Is the “Operation not permitted” part anything to be concerned about?
@Pablo: You have to prefix all commands with “sudo”, so:
sudo mkswap /swap && sudo chown root. /swap && sudo chmod 0600 /swap && sudo swapon /swap
It worked! Thanks @Kamal! Didn’t realize that one had to type “sudo” after each “&&”. On that note, I was also having trouble w/the 3rd & 4th lines of Step 1, b/c I was merely typing:
<pre>sudo echo /swap swap swap defaults 0 0 >> /etc/fstab</pre>
and the system would respond with: -bash: /etc/fstab: Permission denied
<pre>sudo echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p</pre>
and the system would respond with: -bash: /etc/sysctl.conf: Permission denied
But, I then followed your advise from my previous ? and added “sudo” not only at the beginning of the line, but also after the “>>” in lines 3 & 4 of Step 1, i.e.:
<pre>sudo echo /swap swap swap defaults 0 0 >> sudo /etc/fstab</pre>
<pre>sudo echo vm.swappiness = 0 >> sudo /etc/sysctl.conf && sysctl -p</pre>
It worked! Thanks, again!
RE: the overall instructions, what would have to be done different, if anything, if we hoped to use Nagios w/Nginx as opposed to Apache? I ask b/c in Step 3, we’re to execute the following command:
<pre>service apache2 restart</pre>
@Pablo: Awesome! Glad to hear that it worked :] The nagios package sets up the appropriate virtualhosts for Apache.
Take a look at http://johan.cc/2012/02/06/nagios-nginx/ and let me know if it works.
i Im getting an Error while addiding the Hosts …
Checking services… Error: Service check command ‘check_local_mrtgtraf’ specified in service ‘Bandwidth on Downstream To Rw-1’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_local_mrtgtraf’ specified in service ‘Bandwidth on Downstream To Rw-2’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_local_mrtgtraf’ specified in service ‘Bandwidth on WAN’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! ’ not defined anywhere! Error: Service check command ‘check_crc_increase’ specified in service ‘CRC Error on LAN-R2’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_crc_increase’ specified in service ‘CRC Error on WAN’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_router_cpu’ specified in service ‘Device CPU Utilization’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_router_mem’ specified in service ‘Device Memory Utilization’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_snmp’ specified in service ‘Downstream To Router 1’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_snmp’ specified in service ‘Downstream To Router 2’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_snmp’ specified in service ‘Router Uptime’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere! Error: Service check command ‘check_snmp’ specified in service ‘Uplink Interface To ISP’ for host ‘Lab-RW-A-192.168.1.112’ not defined anywhere!
As per my understanding Check_snmp … Check the Opervalue, Uptime, CPU , Bandwidth … are a part of default example config … Please guide me If im missing …
I would also like to know the procedure of addidng fewmore command/services like check_BGP, Check_Temp … Ihave those snippets I would like toknow where to put those arguments … The loctions like libexec and commands
Regards Haris
after following this guide my installation just downloads the php file after I login. What would be the cause?
@damiandennis: Are you still experiencing this issue?