Nagios and NagiosQL on CentOS 4.x
From Nagios Wiki
Contents
|
[edit] Intro
NagiosQL, frontend GUI applications that manages Nagios (similar to Groundwork's Fruity), uses MySQL database to create the /etc/nagios/*.cfg files necessary for the Nagios daemon.
Until we can "yum install nagiosql", this HOWTO will demonstrate how to install NagiosQL on CentOS. In our example here, we'll use CentOS 4.x, Nagios 2.x. After you follow this HOWTO, you will have a NagiosQL box with no default configuration. If you have no prior experience with Nagios, read Nagios' documentation, as NagiosQL's web-based GUI uses Nagios terms and concepts quite heavily.
[edit] CentOS Requirements
[edit] Installing Centos 4.x Single Server CD
- Grab latest CentOS Server CD ISO
- Do a minimal install (with as few packages as possible)
- Turn off SELinux (if you leave this on, you will likely experience many problems trying to get Nagios working)
- Reboot
[edit] Post CentOS Install
- Update CentOS 4.4 to latest 4.x
yum update && yum upgrade
[edit] Adding RPMforge Repository
(optional)
- install vim-enhanced ("yum install vim-enhanced")
- RPMforge repository for CentOS 4 required to "yum install" Nagios stuff]
- install protectbase by typing "yum install yum-plugin-priorities"
- hit Y twice
- edit following files according to RPMforge info
- /etc/yum/pluginconf.d/priorities.conf
[main] enabled=1
- .repo files in /etc/yum.repos.d/
priority=N
and
[base], [addons], [update], [extras] ... priority=1 [centosplus],[contrib] ... priority=2 Third Party Repos such as rpmforge ... priority=N (where N is > 10 and based on your preference)
- d/l and add rpmforge repository
wget http://dag.wieers.com/packages/rpmforge-release/rpmforge-release-0.3.6-1.el4.rf.i386.rpm rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt rpm -K rpmforge-release-0.3.6-1.el4.rf.*.rpm rpm -i rpmforge-release-0.3.6-1.el4.rf.*.rpm
- make sure it all works ok (i.e. show which packages were held back)
yum check-update . . . yum check-update --> 176 packages excluded due to repository priority protections
Then you can run
yum update
[edit] LAMP Requirements for Nagios + NagiosQL
(LAMP = Linux Apache MySQL + PHP or Perl)
- General instructions
- http://www.flmnh.ufl.edu/linux/install_apache.htm
[edit] LAMP components needed
- MySQL required for NagiosQL
- yum install mysql: MySQL client
- yum install mysql-server: MySQL server for NagiosQL
- yum install mysql-devel: not required for any of these, but good for when you compile (e.g. ./configure) other Nagios tools, such as NDOutils.
- PHP and PHP-Pear required for NagiosQL
- Apache required for Nagios
- Not required to use CGIs included in Nagios, but strongly advised.
- Thomas Boutell's gd library version 1.6.3 or higher (required by the statusmap and trends CGIs) for Nagios
yum -y install httpd php mysql mysql-server mysql-devel php-mysql php-pear httpd-manual /etc/init.d/mysqld start chkconfig mysqld on /etc/init.d/httpd start chkconfig httpd on
- http://192.168.1.x (or whatever IP) in browser to test
[edit] Nagios
[edit] Vanilla Nagios Install
- yum search nagios
- install Nagios base
yum install Nagios yum install nagios-plugins
or
yum install nagios*
start services, and start services upon boot
/etc/init.d/nagios start chkconfig nagios on (to add to startup service
[edit] Configuring Nagios
After you "yum install" Nagios, here is where Nagios lives:
- Config CFG files - /etc/nagios
- Web interface files - /usr/share/nagios
- Log files - /var/log/
- CGI files - /usr/lib/nagios/cgi
Knowing where Nagios puts things will help you as you configure NagiosQL.
[edit] Configure Apache for Nagios
- http://www.cisl.ucar.edu/nets/tools/nagios/
- vim /etc/httpd/conf/httpd.conf
ServerName nagios.yourDomain.com:80
- htpasswd -c /etc/nagios/htpasswd.users nagiosadmin (then put in your password)
- vim /etc/nagios/cgi.cfg
# AUTHENTICATION USAGE use_authentication=1 # SYSTEM/PROCESS INFORMATION ACCESS authorized_for_system_information=nagiosadmin # CONFIGURATION INFORMATION ACCESS authorized_for_configuration_information=nagiosadmin # SYSTEM/PROCESS COMMAND ACCESS authorized_for_system_commands=nagiosadmin # GLOBAL HOST/SERVICE VIEW ACCESS authorized_for_all_services=nagiosadmin authorized_for_all_hosts=nagiosadmin # GLOBAL HOST/SERVICE COMMAND ACCESS authorized_for_all_service_commands=nagiosadmin authorized_for_all_host_commands=nagiosadmin
- type in IP address in browser, make sure page is served and that you can see host checks (otherwise permissions probably aren't set right)
- to troubleshoot what might be wrong with Apache, type in "tail /etc/httpd/logs/error_log"
[edit] NagiosQL
NagiosQL documentation (adapted for CentOS environment)
[edit] Requirements for NagiosQL
- Webserver (Apache 1.3.x/2.0.x)
- PHP Version 4.1 or higher / 5.0 or higher
- MySQL Version 4.1 or higher / 5.0 or higher
- Pear Module HTML_Template_IT Version 1.1 (http://pear.php.net)
- Nagios Version 2.x (1.x is not supported)
- Javascript supported by your browser
- Cookies accepted by your browser
[edit] Pear Template
pear install HTML_Template_IT
[edit] Installing NagiosQL
cd /tmp wget http://superb-west.dl.sourceforge.net/sourceforge/nagiosql/nagiosql-2.00-P00.tar.gz tar zxfv nagiosql-2.00-P00.tar.gz cp nagiosQL/ /var/www/html/ -R
[edit] configuring MySQL (so that script can run)
- cd /var/www/html/nagiosQL/config
- mysql -u root -p <nagiosQL_v2_db_mysql.sql
- (password is NULL by default)
[edit] Apache
- vim /etc/httpd/conf/httpd.conf
- add to bottom of conf
<Directory /var/www/html/nagiosQL>
<FilesMatch \.(?i:ini)$>
Order allow,deny
Deny from all
</FilesMatch>
</Directory>
- /etc/init.d/httpd reload
[edit] PHP
- vim /etc/php.ini
put 'magic_quotes_gpc = On'
- configuring permissions
[edit] Directory Structure in /etc/nagios
mkdir /etc/nagios/hosts /etc/nagios/services mkdir /etc/nagios/backup /etc/nagios/backup/hosts /etc/nagios/backup/services
- gives us the following directory structure
- /etc/nagios
- /etc/nagios/hosts
- /etc/nagios/services
- /etc/nagios/backup
- /etc/nagios/backup/hosts
- /etc/nagios/backup/services
- above is the default, recommended directory structure (note: must reflect /var/www/html/nagiosQL/config/settings.ini and /etc/nagios/nagios.cfg)
[edit] settings.ini
- vim /var/www/html/nagiosQL/config/settings.ini
; Absolute (physical) path to the software directory ; -------------------------------------------------- ;physical = /insert/path/to/nagiosQL/ physical = /var/www/html/nagiosQL/
[nagios] ;Nagios main configuration directory ; ----------------------------------- ;config = "/usr/local/nagios/etc/" config = "/etc/nagios/" ;Nagios host configuration directory ; ----------------------------------- ;confighosts = "/usr/local/nagios/etc/hosts/" confighosts = "/etc/nagios/hosts/" ; Nagios service settings directory ;--------------------------------- ;configservices = "/usr/local/nagios/etc/services/" configservices = "/etc/nagios/services/" ;Backup directories ; ------------------ ;backup = "/usr/local/nagios/etc/backup/" ;backuphosts = "/usr/local/nagios/etc/backup/hosts/" ;backupservices = "/usr/local/nagios/etc/backup/services/" backup = "/etc/nagios/backup/" backuphosts = "/etc/nagios/backup/hosts/" backupservices = "/etc/nagios/backup/services/"
Enabling English
[data] ; Language ; -------- ; lang_de = Deutsch ; lang_en = English ; ;lang = lang_de lang = lang_en
[edit] nagios.cfg
vim /etc/nagios/nagios.cfg
# Command definitions #cfg_file=/etc/nagios/commands.cfg cfg_file=/etc/nagios/checkcommands.cfg cfg_file=/etc/nagios/misccommands.cfg
#old config that comes with Nagios #cfg_file=/etc/nagios/localhost.cfg #new configs that are generated by NagiosQL cfg_file=/etc/nagios/contactgroups.cfg cfg_file=/etc/nagios/contacts.cfg cfg_file=/etc/nagios/timeperiods.cfg cfg_file=/etc/nagios/hostgroups.cfg cfg_file=/etc/nagios/servicegroups.cfg #old configs that Nagios puts in by default (and comments out) #cfg_file=/etc/nagios/servicedependencies.cfg #cfg_file=/etc/nagios/serviceescalations.cfg #cfg_file=/etc/nagios/hostdependencies.cfg #cfg_file=/etc/nagios/hostescalations.cfg #cfg_file=/etc/nagios/hostextinfo.cfg #cfg_file=/etc/nagios/serviceextinfo.cfg cfg_dir=/etc/nagios/hosts cfg_dir=/etc/nagios/services
#check_external_commands=0 check_external_commands=1
(So "chown nagios:apache /var/log/nagios/rw/nagios.cmd" and "chmod 660 /var/log/nagios/rw/nagios.cmd" will work properly, enabling you to restart service from NagiosQL gui, rather than go to command line and type "/etc/init.d/nagios restart" each time) Insert non-formatted text here
[edit] Permissions
make files we referenced in
touch /etc/nagios/checkcommands.cfg touch /etc/nagios/misccommands.cfg touch /etc/nagios/contactgroups.cfg touch /etc/nagios/contacts.cfg touch /etc/nagios/timeperiods.cfg touch /etc/nagios/hostgroups.cfg touch /etc/nagios/servicegroups.cfg
Give Apache appropriate permissions.
chmod 6755 /etc/nagios chown apache:apache /etc/nagios chmod 6755 /etc/nagios/hosts chown apache:apache /etc/nagios/hosts chmod 6755 /etc/nagios/services chown apache:apache /etc/nagios/services chmod 6755 /etc/nagios/backup chown apache:apache /etc/nagios/backup chmod 6755 /etc/nagios/backup/hosts chown apache:apache /etc/nagios/backup/hosts chmod 6755 /etc/nagios/backup/services chown apache:apache /etc/nagios/backup/services chmod 644 /etc/nagios/*.cfg chown apache:apache /etc/nagios/*.cfg
optional (not applicable on new box)
chmod 644 /etc/nagios/hosts/*.cfg chown apache:apache /etc/nagios/hosts/*.cfg chmod 644 /etc/nagios/services/*.cfg chown apache:apache /etc/nagios/services/*.cfg
Making Nagios binary executable by Apache user
chown nagios:apache /usr/bin/nagios chmod 750 /usr/bin/nagios chmod +x /usr/bin/nagios
Making sure Nagios can write to command file. If it is not there, then you will need to enable the check_external_commands option to 1 in nagios.cfg.
chown nagios:apache /var/log/nagios/rw -R chmod 660 /var/log/nagios/rw -R chmod +w /var/log/nagios/rw/ -R chmod +x /var/log/nagios/rw/ -R
chown apache:apache /var/www/html/nagiosQL/ -R
[edit] Nagios Configuration Settings in NagiosQL's settings.ini file
Before customizing for CentOS environment, run http://IPaddress/nagiosQL/test.php. You should get something like the following:
Nagios configuration directories Nagios Binary not found - parameter wrong in settings.ini: section "[nagios]", parameter "binary"! Nagios Command File not found - parameter wrong in settings.ini: section "[nagios]", parameter "cmdfile"! Nagios Configuration Directory not found - parameter wrong in settings.ini: section "[nagios]", parameter "config"! Nagios Hosts Configuration Directory not found - parameter wrong in settings.ini: section "[nagios]", parameter "confighosts"! Nagios Services Configuration Directory not found - parameter wrong in settings.ini: section "[nagios]", parameter "configservices"! Nagios Backup Directory not found - parameter wrong in settings.ini: section "[nagios]", parameter "backup"! Nagios Hosts Backup Directory not found - parameter wrong in settings.ini: section "[nagios]", parameter "backuphosts"! Nagios Services Backup Directory not found - parameter wrong in settings.ini: section "[nagios]", parameter "backupservices"!
To fix these errors, change your settings.ini file.
; Nagios system files ; ------------------- ;binary = "/usr/local/nagios/bin/nagios" binary = "/usr/bin/nagios" ;nagios.cmd file created only if you have ;check_external_commands=1 enabled in /etc/nagios/nagios.cfg ;cmdfile = "/usr/local/nagios/var/rw/nagios.cmd" cmdfile = "/var/log/nagios/rw/nagios.cmd" ;pidfile = "/var/run/nagios/nagios.pid" pidfile = "/var/run/nagios.pid"
Once good, go to http://IPaddress/nagiosQL/test.php and you should get the following:
Webserver paths Parameter in settings.ini: section "[path]", parameter "physical" seems to be correct! Parameter in settings.ini: section "[path]", parameter "root" seems to be correct! Parameter in settings.ini: section "[path]", parameter "IT" seems to be correct - file found and included! Templates Main template file found and readable Admin template file found and readable Main template successfully loaded Admin template successfully loaded Main template successfully parsed Admin template successfully parsed Style sheet CSS file found and readable CSS file via HTTP found and readable
If get permissions error (e.g. "Nagios Binary found but not executable, please check permissions!"), running the following should give you the "Nagios Binary found and executable" message you need for NagiosQL to properly run.
chmod +x /usr/bin/nagios
[edit] Troubleshooting
tail /var/log/httpd/error_log
Look at error page:
- http://ip/nagiosQL/testQL.php (be sure to capitalize QL in both nagiosQL and testQL)
[edit] Post-NagiosQL Install
http://IP/nagiosQL/index.php (with caps)
default password: admin / admin; where to change password
nothing installed by default, how to make a simple check.
problems you have when you
...basic set of things you can do to do a simple check....some of the problems you experience when you import localhost.cfg file
commands.cfg (in Nagios) now checkcommands.cfg and misccommands.cfg (in NagiosQL)
commands.cfg stuff you need to do for your environment (examples)
backing up nagiosql and restoring to another nagiosql server
- mysqldump -uroot -p db_nagiosql_v2 > /tmp/nagiosQL.sql
- scp nagiosQL.sql root@newNagiosBox.domain.com:/tmp
- (on destination box) mysql -uroot db_nagiosql_v2 < /tmp/nagiosQL.sql

