nagios+pnp4nagios配置实例

发布时间:2019-07-17编辑:脚本学堂
nagios+pnp4nagios配置实例

nagios+pnp4nagios配置实例,供大家学习参考。
没有过多的文字介绍,仅提供了安装步骤,大家自行研读吧。

复制代码 代码如下:

yum  -y install wget openssl-devel vixie-cron   libart_lgpl-devel pango-devel cairo-devel gd-devel perl-devel zlib-devel libjpeg-devel libpng-devel freetype-dir vim* curl-devel libxml2-devel bzip2-devel

host nagios.manwrx.com
alias vi=vim

groupadd -g 1000 mysql
useradd -g 1000 -u 1000 -d /dev/null -s /sbin/nologin mysql
cd  /usr/src
tar xvzf mysql-5.1.55-linux-i686-glibc23.tar.gz
mv mysql-5.1.55-linux-i686-glibc23 /usr/local/mysql
cd /usr/local/mysql/
chown -R mysql.mysql  .
./scripts/mysql_install_db --datadir=/usr/local/mysql/data/ --user=mysql
chown -R root .
chown -R mysql.mysql  data/
rm -fr  /etc/my.cnf
cp support-files/my-medium.cnf  /etc/my.cnf
bin/mysqld_safe --datadir=/usr/local/mysql/data/ --user=mysql  &
cp support-files/mysql.server  /etc/rc.d/init.d/mysqld
chmod 700 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
service mysqld restart
echo 'PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
echo '/usr/local/mysql/lib/' >> /etc/ld.so.conf
ldconfig  -v

cd /usr/src
wget http://mirrors.ispros.com.bd/apache/httpd/httpd-2.2.19.tar.bz2
tar  xvjf httpd-2.2.19.tar.bz2
cd httpd-2.2.19
./configure  --prefix=/usr/local/apache --enable-so  --enable-rewrite  --enable-ssl
make
make install
echo '/usr/local/apache/bin/apachectl start' >> /etc/rc.local
vi /usr/local/apache/conf/httpd.conf
 AddType application/x-httpd-php .php .phps
  DirectoryIndex index.php index.html

cd /usr/src
wget http://cn.php.net/distributions/php-5.3.6.tar.bz2
tar xvjf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/usr/local/php  --with-apxs2=/usr/local/apache/bin/apxs  --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-gd --enable-zip --with-zlib-dir --with-libxml-dir --enable-sockets --with-openssl-dir --enable-mbstring   --enable-gd-native-ttf  --with-png-dir --with-freetype-dir  --with-jpeg-dir --with-pcre-dir --with-bz2 --with-curl
make
make install
cp php.ini-production  /usr/local/php/lib/php.ini

groupadd -g 1002 nagios
useradd -g 1002 -u 1002 -d /dev/null -s /sbin/nologin nagios

cd /usr/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
tar xvzf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios
make all
make install
make install-init
make install-config
make install-commandmode
cat sample-config/httpd.conf |grep -v "#" >> /usr/local/apache/conf/httpd.conf

cd /usr/src
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
tar xvzf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make
make install

cd /usr/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar xvzf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure  --prefix=/usr/local/nagios
make
make install

chown -R nagios:nagios  /usr/local/nagios

#### 添加浏览nagios用户名,###
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

/usr/local/apache/bin/htpasswd  /usr/local/nagios/etc/htpasswd.users manwrx

vi/usr/local/nagios/etc/cgi.cfg

复制代码 代码如下:
authorized_for_system_information=nagiosadmin,manwrx
authorized_for_configuration_information=nagiosadmin,manwrx
authorized_for_system_commands=nagiosadmin,manwrx
authorized_for_all_services=nagiosadmin,manwrx
authorized_for_all_hosts=nagiosadmin,manwrx
authorized_for_all_service_commands=nagiosadmin,manwrx
authorized_for_all_host_commands=nagiosadmin,manwrx

vi /usr/local/nagios/etc/objects/commands.cfg
 

复制代码 代码如下:
define command{
        command_name    check_nrpe       
    command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

 

复制代码 代码如下:

chkconfig nagios on
service nagios restart

/usr/local/apache/bin/apachectl start
echo '/usr/local/apache/bin/apachectl start' >> /etc/rc.local

cd /usr/src
wget http://mirrors.xmu.edu.cn/CPAN/authors/id/T/TI/TIMB/DBI-1.616.tar.gz
tar xvzf DBI-1.616.tar.gz
cd DBI-1.616
perl Makefile.PL
make install

cd /usr/src
wget http://mirrors.xmu.edu.cn/CPAN/authors/id/C/CA/CAPTTOFU/DBD-mysql-4.019.tar.gz
tar xvzf DBD-mysql-4.019.tar.gz
cd DBD-mysql-4.019
perl Makefile.PL --with-mysql=/usr/local/mysql --mysql_config=/usr/local/mysql/bin/mysql_config
make install

cd /usr/src
wget http://ncu.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz
tar xvzf ndoutils-1.4b9.tar.gz
cd ndoutils-1.4b9
./configure  --prefix=/usr/local/nagios  CPPFLAGS=-I/usr/local/mysql/include/ --with-mysql-inc=/usr/local/mysql/include/ LDFLAGS=-L/usr/local/mysql/lib/mysql/  --with-mysql-lib=/usr/local/mysql/lib/mysql/ --enable-mysql --with-mysql=/usr/local/mysql/  --with-ndo2db-user=nagios  --with-ndo2db=nagios  --disable-pgsql
sed -i 's!<mysql/mysql.h>! </usr/local/mysql/include/mysql.h!g>' include/config.h
sed -i 's! <mysql/errmsg.h>! </usr/local/mysql/include/errmsg.h>!g' include/config.h
make

/usr/local/mysql/bin/mysql 
mysql> create database nagios;
mysql> grant all privileges on nagios.*  to nagios@'localhost' identified by '123456';

cd src
cp ndo2db-3x ndomod-3x.o file2sock log2ndo /usr/local/nagios/bin/

cd ..
cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

/usr/local/mysql/bin/mysql  -u nagios -p'123456' nagios <  ./db/mysql.sql

vi /usr/local/nagios/etc/ndo2db.cfg
 

复制代码 代码如下:
lock_file=/usr/local/nagios/var/ndo2db.lock
ndo2db_user=nagios
ndo2db_group=nagios
socket_type=tcp
socket_name=/usr/local/nagios/var/ndo.sock
tcp_port=5668
use_ssl=0
db_servertype=mysql
db_host=localhost
db_port=3306
db_name=nagios
db_prefix=nagios_
db_user=nagios
db_pass=123456
max_timedevents_age=1440
max_systemcommands_age=10080
max_servicechecks_age=10080
max_hostchecks_age=10080
max_eventhandlers_age=44640
max_externalcommands_age=44640
debug_level=0
debug_verbosity=1
debug_file=/usr/local/nagios/var/ndo2db.debug
max_debug_file_size=1000000

vi /usr/local/nagios/etc/ndomod.cfg
 

复制代码 代码如下:
instance_name=default
output_type=tcpsocket
output=127.0.0.1
tcp_port=5668
use_ssl=0
output_buffer_items=5000
buffer_file=/usr/local/nagios/var/ndomod.tmp
file_rotation_interval=14400
file_rotation_timeout=60
reconnect_interval=15
reconnect_warning_interval=15
data_processing_options=-1
config_output_options=2

 

复制代码 代码如下:

cat config/nagios.cfg |grep -v "#" |sed  's!2!3!g' >> /usr/local/nagios/etc/nagios.cfg

/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
echo '/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg '  >> /etc/rc.local

cd /usr/src
tar xvzf rrdtool-1.4.5.tar.gz
cd rrdtool-1.4.5
./configure  --prefix=/usr/local/rrdtool
make
make install

cd /usr/src
wget http://ncu.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.14.tar.gz
tar xvzf pnp4nagios-0.6.14.tar.gz
cd pnp4nagios-0.6.14
./configure  --prefix=/usr/local/pnp4nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool
make all
make install
make install-webconf
make install-config
make install-init

sed -n '7,13p' ./sample-config/nagios.cfg-sample  |sed  '/^$/d' >> /usr/local/nagios/etc/nagios.cfg

cat ./sample-config/httpd.conf |grep -v "#" >> /usr/local/apache/conf/httpd.conf

编辑命令配置文件
vi /usr/local/nagios/etc/objects/commands.cfg
 

复制代码 代码如下:

define command {
       command_name process-host-perfdata
       command_line   /usr/bin/perl    /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}

define command {
       command_name process-service-perfdata
       command_line   /usr/bin/perl    /usr/local/pnp4nagios/libexec/process_perfdata.pl
}

编辑模板文件
vi /usr/local/nagios/etc/objects/templates.cfg
 

复制代码 代码如下:
define host {
       name          host-pnp
       register      0
       action_url   /pnp4nagios/index.php?host=$hostname
}
define service {
       name          srv-pnp
       register      0
       action_url   /pnp4nagios/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}

rm -fr /usr/local/pnp4nagios/share/install.php
####在添加主机的时候可以用use 两个模版
###如 use linux-servers,host-pnp