2004 发表于 2019-1-16 12:59:22

CentOS5.5 +Nagios+pnp4nagios

  centos 5.5 +httpd-2.26+mysql-5.0.41+php-5.3.3+nagios-3.2.3

************安装gcc环境***********************
yum -y install gcc*

*************删除原带apache*******************
rpm -qa | grep httpd
rpm -e --nodeps httpd-***

************安装httpd 2.2.6*******************

tar zxvf httpd-2.2.6.tar.gz
cd httpd-2.2.6
./configure --prefix=/usr/local/webroot/httpd --enable-so --enable-rewrite --with-mpm-worker
make
make install


************安装mysql-5.0.41*******************
安装之前首先安装ncurses-5.6
tar zxvf ncurses-5.6.tar.gz
cd ncurses-5.6
./configure
make && make install


tar zxvf mysql-5.0.41.tar.gz
cd mysql-5.0.41
./configure --prefix=/usr/lcoal/webroot/mysql
make
make install

groupadd mysql
useradd -g mysql mysql
#####################调整数据存储位置,未测试通过###########################
mkdir -p /date/mysql/3306/date
mkdir -p /date/mysql/3306/binlog
mkdir -p /date/mysql/3306/relaylog
chown -R mysql:mysql /date/mysql
/usr/local/webroot/mysql/bin/mysql_install_db --basedir=/usr/local/webroot/mysql/ --datadir=/date/mysql/3306 --user=mysql
############################################################################

/usr/local/webroot/mysql/bin/mysql_install_db --user=mysql

chown -R root .
chown -R mysql var
chgrp -R mysql .

echo "/usr/local/webroot/mysql/lib/mysql">>/etc/ld.so.conf
ldconfig

echo "export PATH=$PATH:/usr/local/webroot/mysql/bin">>/etc/profile
source /etc/profile

启动mysql服务
/etc/init.d/mysqld start

更改mysql运行级别
chkconfig --level 345 mysqld on

进入mysql更改root用户密码为123456
mysql
use mysql
update user set password=password("123456") where user='root';
flush privileges;
exit


*****************安装PHP*****************
首先安装php支持库
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss-ldap openldap-clients openldap-servers libmcript libmcript-devel

tar zxvf php-5.3.3.tar.gz
cd php-5.3.3


./configure --prefix=/usr/local/webroot/php --with-config-file-path=/usr/local/webroot/php/etc -with-apxs2=/usr/local/webroot/httpd/bin/apxs --with-mysql=/usr/local/webroot/mysql --with-mysqli=/usr/local/webroot/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --disable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --disable-magic-quotes disable-magic-quotes-gpc


注:曾经我在编译php的时候,对于--disable-safe-mode 以及 --disable-magic-quotes 写成了enable
make
make install

cp php.ini-dist /usr/local/webroot/php/etc/php.ini
vi /usr/local/webroot/php/etc/php.ini

编译php时错误make *** Error 1
/usr/bin/ld: cannot find -lltdl
collect2: ld returned 1 exit status
make: *** Error 1

解决方法:安装libtool.i386还是不能解决

所以再安装个libtool-ltdl-devel.i386


检查一下apache配置文件是否正确(/usr/local/webroot/httpd/bin/apachectl -t),输出"Syntax OK"表示正常

启动apache:/usr/local/webroot/httpd/bin/apachectl start
编辑一个测试页test.php
vi test.php



******************安装nagios*********************
首先下载
Apache 实现nagios监控通过web查看 Nagios
nagios监控程序
Nagios-plugins nagios监控插件
Pnp4nagios nagios监控插件
Nrpe nagios监控客户端
Rrdtool pnp4nagios生成图形工具

Nagios http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.2.1/nagios-3.2.1.tar.gz
Nagios-plugins http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz Pnp4nagios http://sourceforge.net/projects/pnp4nagios/files/PNP-0.6/pnp4nagios-0.6.6.tar.gz/download
Nrpe http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz

添加没有登录权限用户nagios
useradd nagios -s /sbin/nologin

tar zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios --with-user=nagios --with-group=nagios
make all
make install
make install-commandmode
make install-init
make install-config

cd ..
tar zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make
make install

cd ..

tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --prefix=/usr/local/nrpe
make && make install
make all


更改nagios 属性
chown -R nagios:nagios /usr/local/nagios

Nagios 启动
/usr/local/nrpe/bin/nrpe -c /usr/local/nrpe/etc/nrpe.cfg -d


@@@@@@整合nagios与apache配合使用@@@@@@@@@

首先修改httpd属性
chown -R nagios:nagios
编辑httpd.conf文件
在文件尾部增加

ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin

AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user


Alias /nagios /usr/local/nagios/share

AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user


然后执行
useradd -g nagios st
再执行
/usr/local/webroot/httpd/bin/htpasswd -c /usr/local/nagios/etc/htpasswd st
设置st用户密码


######################################################################
在httpd.conf 加入include conf/nagios.conf
并且在conf文件夹内加入
Alias /nagios "/usr/local/nagios/share"

Options None
AllowOverride None
Order allow,deny
Allow from all

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" #该行有些小的错误

Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all

#######################################################################
安装rrdtool
rrdtool所需要的支持架包

更新yum
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
rpm -ivh rpmforge-release-0.5.1-1.el5.rf.i386.rpm
yum -y install rrdtool


安装pnp4nagios
#####################################################
#
#
#pnp4nagios 主机名前面的小太阳详细记录有参数主机的情况
#
#
###################################################

tar
cd
./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all

最后显示:
*** Configuration summary for pnp4nagios-0.6.6 08-07-2010 ***

General Options:
-------------------------         -------------------
Nagios user/group:                nagios nagios
Install directory:                /usr/local/pnp4nagios
HTML Dir:                         /usr/local/pnp4nagios/share
Config Dir:                     /usr/local/pnp4nagios/etc
Location of rrdtool binary:       /usr/bin/rrdtool Version 1.4.4
RRDs Perl Modules:                FOUND (Version 1.4004)
RRD Files stored in:            /usr/local/pnp4nagios/var/perfdata
process_perfdata.pl Logfile:      /usr/local/pnp4nagios/var/perfdata.log
Perfdata files (NPCD) stored in:/usr/local/pnp4nagios/var/spool

Web Interface Options:-------------------------         -------------------
HTML URL:                         http://localhost/pnp4nagios
Apache Config File:               /etc/httpd/conf.d/pnp4nagios.conf


Review the options above for accuracy.If they look okay,
type 'make all' to compile.
############################################################


根据./configure --help以及上面信息进行调整
./configure --prefix=/usr/local/pnp4nagios --with-user=nagios --with-group=nagios --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-httpd-conf=/usr/local/webroot/httpd/conf --with-init-dir=/etc/init.d
make all

make install
make install-webconf

make install-config
make install-init
make fullinstall

复制所有的pnp4nagios 目录下etc下的*.cfg.simple 复制为*.cfg

整合pnp4nagios与apache配合

首先在httpd.conf尾部增加include conf/pnp4nagios.conf
然后在/usr/local/webroot/httpd/conf/中添加pnp4nagios.conf文件
Alias /pnp4nagios "/usr/local/pnp4nagios/share"

AllowOverride None
Order allow,deny
Allow from all

RewriteEngine On
Options FollowSymLinks
RewriteBase /pnp4nagios/
RewriteRule ^(application|modules|system) -
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0



vi /usr/local/nagios/etc/object/templates.cfg
define host {
name host-pnp
register 0
action_url /pnp4nagios/graph?host=$HOSTNAME$
}
define service {
name srv-pnp
register 0
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
}


##################################################################################
重新安装apache +php




##########################################################
********************错误解决*********************************






安装之后提示“无权查看任何主机的信息。 请检查HTTP服务器关于该CGI的访问权限设置。”


在/usr/local/nagios/etc/

ll 查看了下
htpasswd.users的属主组都是root

修改成nagios

nagios目录结构

nagios
|-- bin
|-- etc
|   |-- linux
|   |   |-- host
|   |   `-- service
|   `-- objects
|-- include
|-- libexec
|-- sbin
|-- share
|   |-- contexthelp
|   |-- docs
|   |   `-- images
|   |-- images
|   |   `-- logos
|   |-- includes
|   |-- locale
|   |   |-- de
|   |   |   `-- LC_MESSAGES
|   |   `-- fr
|   |       `-- LC_MESSAGES
|   |-- media
|   |-- ssi
|   `-- stylesheets
`-- var
    |-- archives
    |-- rrd
    |-- rw
    |-- spool
    |   `-- checkresults
    `-- start

bin Nagios 执行程序所在目录,这个目录只有一个文件nagios
etc Nagios 配置文件位置,初始安装完后,只有几个*.cfg-sample 文件
sbin Nagios Cgi 文件所在目录,也就是执行外部命令所需文件所在的目录
share Nagios 网页文件所在的目录
var Nagios 日志文件、spid 等文件所在的目录
libexec Nagios监控所需要的插件位置



etc当中存放主配置文件

#####当创建或编辑配置文件时,要遵守如下要求:#########

    * 以符号'#'开头的行将视为注释不做处理;
    * 变量必须是新起的一行 - 变量之前不能有空格符;
    * 变量名是大小写敏感的;
######################################################

nagios.cfg主配置文件包括了一系列的设置,它们会影响Nagios守护进程
cgi.cfgCGI配置文件包含了一系列的设置,它们会影响CGIs程序模块。
resource.cfg资源文件可以保存用户自定义的宏。
nagiosgraph.cfg
htpasswd存放nagios登录用户名以及密码
htpasswd.users存放pnp4nagios用户名以及密码





首先配置 nagios.cfg 文件

增加linux 组文件夹
mkdir /usr/local/nagios/etc/linux
更改nagios.cfg
vi /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/linux

process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata


修改cgi.cfg
vi /usr/local/nagios/etc/cgi.cfg
找到并修改 use_authentication=0
否则,ngios会报错

修改commands.cfg
#添加pnp4nagios 插件命令
define command {
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
define command {
command_name process-service-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
#添加check_nrpe命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

修改contacts.cfg

添加 联系人
格式
define contact{
contact_name                  jdoe#联系人名
alias                           John Doe#联系人别名
host_notifications_enabled1#Values: 0 = don't send notifications, 1 = send notifications.
service_notifications_enabled1#Values: 0 = don't send notifications, 1 = send notifications.
service_notification_period   24x7
host_notification_period      24x7
service_notification_options    w,u,c,r
host_notification_options       d,u,r

service_notification_commands   notify-by-email #服务报警 通知方式   
host_notification_commands      host-notify-by-email#主机报警通知方式
emailjdoe@localhost.localdomain
pager555-5555@pagergateway.localhost.localdomain
address1xxxxx.xyyy@icq.com
address2555-555-5555
can_submit_commands1
}





页: [1]
查看完整版本: CentOS5.5 +Nagios+pnp4nagios