I know this is a *BSD forum but yall have given Solaris a place so I figured
this would be a good place to post my recent pet project.
This is
not a HOWTO, it is more of a guide.
Any comments corrections are welcome..
We run a Solaris environment at work with primarily Solaris 10
and a few Solaris 9 boxes that are hopefully going away soon..
Nagios is something I learned about from this community years ago.
I set it up on an OPenBSD box at my old job and it is still running today..
Ok.. On with the guide:
This was done in a full root Solaris 10 zone on both SPARC and x86 architecture.
Installation of Nagios 3.03
Download the following Source code from SourceForge or
their respective site:
Nagios -- nagios-3.03
Nagios Plugins -- nagios-plugins-1.4.12
http://www.nagios.org/download/
RRdTool -- rrdtool-1.2.9
http://oss.oetiker.ch/rrdtool/download.en.html
CgiLib
http://www.infodrom.org/projects/cgilib/download.php
PHP -- php-5.2.6
http://www.php.net/downloads.php
Lightweight CGI Library -- cgilib-0.5
http://www.infodrom.org/projects/cgilib/download.php
PNP4Nagios -- pnp-0.4.10
http://www.pnp4nagios.org/pnp/start
PNP4Nagios along with Rrdtool uses performance data and produces some very nice graphs.
Set Root path to:
Code:
/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/mysql/bin:/usr/sfw/bin:/usr/ccs/bin:/usr/ucb
Set configure runtime linking environment
Code:
# crle -u -l /usr/local/lib
# crle -u -l /usr/local/ssl/lib
Install the following Sunfreeware packages..
If pkg-get in not installed on your system then download it here:
http://www.bolthole.com/solaris/pkg-get.html
After installing pkg-get
Sunfreeware packages
Code:
# pkg-get install autoconf-2.62 bison-2.3 coreutils-6.4 expat-2.0.1 \
flex-2.5.4a fontconfig-2.4.2 freetype-2.3.1 gcc-3.4.6 \
gd-2.0.35 gtk+-1.2.10 jpeg-6b libpng-1.2.29 libtool-1.5.24 \
libiconv-1.9.2 libintl-3.4.0 make-3.81 mysql-5.0.51 \
ncurses-5.6 openssl-0.9.8h pkgconfig-0.20 \
zlib-1.2.3 netsnmp-5.4.1.1 libxml2- 2.6.31
Add the nagios user and group
Code:
# groupadd -g 667 nagios
# useradd -d /usr/local/nagios -g nagios -u 666 -s /bin/false nagios
Configure nagios
Code:
# ./configure \
--prefix=/usr/local/nagios \
--enable-event-broker \
--with-gd-lib=/usr/local/lib \
--with-gd-inc=/usr/local/include \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-command-user=webservd \
--with-command-group=webservd \
--with-checkresult-dir=/usr/local/nagios/tmp/results \
--with-temp-dir=/usr/local/nagios/tmp \
--with-init-dir=/etc/init.d \
--with-lockfile=/usr/local/nagios/var/nagios.lock \
--with-cgiurl=/nagios/cgi-bin \
--with-htmurl=/nagios
if everything works
Code:
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
Solaris 10 uses apache2
Code:
# cp /etc/apache2/httpd.conf-example /etc/apache2/httpd.conf
Add the following at the bottom of http.conf
Code:
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Now check the httpd.conf
Code:
# /usr/apache2/bin/apachectl configtest
Syntax OK
Enable apache2 and check
Code:
# svcadm enable http
# svcs http
STATE STIME FMRI
online 12:10:19 svc:/network/http:apache2
Create the htpasswd.users file
Code:
# /usr/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users <username>
# New password:
# Re-type new password:
Adding password for user <username>
Check Nagios
Code:
# /etc/init.d/nagios checkconfig
Running configuration check...Killed
CONFIG ERROR! Check your Nagios configuration.
If you get this error chances are you didn't run the
crle command to link the necessary libraries..
There should be
/lib:/usr/lib:/usr/local/lib:/usr/local/ssl/lib
in your crle output.
Read on
Quote:
Lets check the nagios binaries
# ldd /usr/local/nagios/bin/nagios
libm.so.2 => /lib/libm.so.2
libpthread.so.1 => /lib/libpthread.so.1
libltdl.so.3 => (file not found)
librt.so.1 => /lib/librt.so.1
libglib-2.0.so.0 => /usr/lib/libglib-2.0.so.0
libc.so.1 => /lib/libc.so.1
libaio.so.1 => /lib/libaio.so.1
libmd.so.1 => /lib/libmd.so.1
Note the "file not found"
|
After we check again..(
after setting our crle options)
Quote:
# ldd /usr/local/nagios/bin/nagios
libm.so.2 => /lib/libm.so.2
libpthread.so.1 => /lib/libpthread.so.1
libltdl.so.3 => /usr/local/lib/libltdl.so.3
librt.so.1 => /lib/librt.so.1
libc.so.1 => /lib/libc.so.1
libdl.so.1 => /usr/lib/libdl.so.1
libgcc_s.so.1 => /usr/local/lib/libgcc_s.so.1
libaio.so.1 => /lib/libaio.so.1
libmd.so.1 => /lib/libmd.so.1
|
Check nagios again.
Code:
# /etc/init.d/nagios checkconfig
Running configuration check... OK.
Start nagios
Code:
# /etc/init.d/nagios start
-n Starting nagios:
done.
# tail /usr/local/nagios/var/nagios.log
[1214068735] Nagios 3.0.2 starting... (PID=13222)
[1214068735] Local time is Sat Jun 21 12:18:55 CDT 2008
[1214068735] LOG VERSION: 2.0
[1214068735] Finished daemonizing... (New PID=13223)
[1214068735] Error: Could not create external command file
'/usr/local/nagios/var/rw/nagios.cmd' as named pipe: (13) -> Permission
denied. If this file already exists and you are sure that another copy of
Nagios is not running, you should delete this file.
[1214068735] Bailing out due to errors encountered while trying to
initialize the external command file... (PID=13223)
Oops Nagios isn't starting
We must add nagios to the webservd group
Code:
# usermod -G webservd nagios
Notice that webservd is the owner of the rw which is
used to run commands from the Web.
*That* is why nagios needs to be a member of the webservd group
Code:
# pwd
/usr/local/nagios/var
# ls -al
total 64
drwxrwxr-x 4 nagios nagios 512 Jun 21 12:21 .
drwxr-xr-x 9 root root 512 Jun 21 12:04 ..
drwxrwxr-x 2 nagios nagios 512 Jun 21 12:03 archives
-rw-r--r-- 1 nagios nagios 6 Jun 21 12:19 nagios.lock
-rw-r--r-- 1 nagios nagios 755 Jun 21 12:19 nagios.log
-rw-r--r-- 1 nagios nagios 12943 Jun 21 12:19 objects.cache
drwxrwsr-x 2 webservd webservd 512 Jun 21 12:19 rw
-rw-rw-r-- 1 nagios nagios 13165 Jun 21 12:21 status.dat
# tail /usr/local/nagios/var/nagios.log
[1214068797] Nagios 3.0.2 starting... (PID=13237)
[1214068797] Local time is Sat Jun 21 12:19:57 CDT 2008
[1214068797] LOG VERSION: 2.0
Good Nagios is started and apache2 is also started..
Now let's check to see if we can access the web gui.
Ok.. we can see the web after we get logged in but
we don't have any permissions.. yet .. :-)
Quote:
Web Page Banner
It appears as though you do not have permission to view information for
any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication
requirements for accessing this CGI
and check the authorization options in your CGI configuration file.
|
It tells us what to do..
Mod the cgi file..
Code:
# vi /usr/local/nagios/etc/cgi.cfg
and add <username> to every place nagiosadmin is located..
Then just refresh your browser..
Woot..
Now lets compile the plugins
After downloading the latest from Sourceforge
Code:
# wget http://internap.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.12.tar.gz
We set up our configure (notice that mysql needs to be installed to compile)
Code:
# ./configure \
--prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-cgiurl=/nagios/cgi-bin \
--with-openssl=/usr/local/ssl \
--with-mysql=/usr/local/mysql/bin/mysql_config \
--with-snmpget-command=/usr/local/bin/snmpget \
--with-snmpgetnext-command=/usr/local/bin/snmpgetnext
# make
# make install
Check to see that are plugins are there:
Code:
# ls /usr/local/nagios/libexec
check_apt check_file_age check_load check_ntp_peer
check_rpc check_udp
check_breeze check_flexlm check_log check_ntp_time
check_sensors check_ups
check_by_ssh check_ftp check_mailq check_nwstat
check_simap check_users
check_clamd check_hpjd check_mrtg check_oracle
check_smtp check_wave
check_cluster check_http check_mrtgtraf check_overcr
check_snmp negate
check_dig check_ifoperstatus check_nagios check_pgsql
check_spop urlize
check_disk check_ifstatus check_nntp check_ping
check_ssh utils.pm
check_disk_smb check_imap check_nntps check_pop
check_ssmtp utils.sh
check_dns check_ircd check_nt check_procs
check_tcp
check_dummy check_jabber check_ntp check_real
check_time
Now lets compile PHP
Compile php (
note: php will not compile in a sparse root zone)
Code:
# ./configure \
--prefix=/usr/local \
--with-apxs2=/usr/apache2/bin/apxs \
--with-openssl=/usr/local/ssl \
--with-gd=/usr/local \
--with-jpeg-dir=/usr/local \
--with-png-dir=/usr/local \
--with-freetype-dir=/usr/local \
--with-zlib=/usr/local \
--with-pear
Looks like everything configured ok..
# make
# make test (states that I may have found a bug in PHP)
# make install
Add to /etc/apache2/httpd.conf
Quote:
LoadModule php5_module libexec/libphp5.so
DirectoryIndex index.html index.html.var index.php
AddType application/x-httpd-php .php
|
Check apache2
Code:
# /usr/apache2/bin/apachectl configtest
[Sat Jun 21 20:12:06 2008] [warn] module php5_module is already loaded,
skipping
Syntax OK
Install rrdtool
I tried the sunfreeware package 1.3.0 but it was missing something
at the end could not find a path (which existed) so I went back to 1.2.9
Rrdtool 1.2.9(this version) uses cgilib-0.5.tar.gz
Note: compile cgilib-0.5 and copy the files or rrdtool 1.2.9 will not compile
properly.
Add to Makefile
Code:
CC=gcc
then
# make
Copy the necessary files to their respective location
# cp libcgi.a /usr/local/lib
# cp cgi.h /usr/local/include
Rrdtool 1.2.9
Code:
# ./configure
# make
# make install
Pnp4nagios
Code:
# ./configure \
--prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-rrdtool=/usr/local/rrdtool-1.2.9/bin/rrdtool
Change the permissions if needed
# chown -R nagios:nagios /usr/local/nagios/var/rrd
# make all
# make install
# make install-init
# make-nstall-config
Now make changes to the nagios.cfg
Quote:
Change
process_performance_data=0
to
process_performance_data=1
Uncomment
#host_perfdata_command=process-host-perfdata
#service_perfdata_command=process-service-perfdata
Change
#host_perfdata_file=/tmp/host-perfdata
#service_perfdata_file=/tmp/service-perfdata
to
host_perfdata_file=/usr/local/nagios/tmp/host-perfdata
service_perfdata_file=/usr/local/nagios/tmp/service-perfdata
Commands.cfg
Comment out
# 'process-host-perfdata' command definition
##define command{
## command_name process-host-perfdata
## command_line /usr/bin/printf "%b"
"$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTAT TEMPT$\t$HOSTSTATETYPE$
\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA $\n" >>
/usr/local/nagios/var/host-perfdata.out
## }
# 'process-service-perfdata' command definition
##define command{
## command_name process-service-perfdata
## command_line /usr/bin/printf "%b"
"$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$S ERVICESTATE$\t$SERVICEA
TTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME $\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERF DATA$\n"
>> >> /usr/l
ocal/nagios/var/service-perfdata.out
## }
Add
define command{
command_name process-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl -d
HOSTPERFDATA
}
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
Edit templates.cfg
Add to "generic-host" HOST Template
action_url /nagios/pnp/index.php?host=$HOSTNAME$
Add to "generic-servic" Sevice Template
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
In /usr/local/nagios/etc/pnp
Code:
# cp rra.cfg-sample rra.cfg
# cp process_perfdata.cfg-sample process_perfdata.cfg
# cp npcd.cfg-sample npcd.cfg
Change permissions on the nagios tmp directory
# chown -R nagios:nagios /usr/local/nagios/tmp
|
You now have a very basic setup of Nagios running on a Solaris 10
box.
The configuration file is locahost.cfg
Use the localhost.cfg as a starting point to make other
*.cfg files
Note:
Check_swap
check_local_procs
do not work out of the box..
Update: I have made few changes (edits based on comments)
rk