Nagios安装文档
1.创建nagios和apache用户和nagcmd用户组
useradd -M -s /sbin/nologin nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd apache
[[email protected] ~]# useradd -M -s /sbin/nologin nagios
[[email protected] ~]# groupadd nagcmd
[[email protected] ~]# usermod -G nagcmd nagios
[[email protected] ~]# usermod -G nagcmd apache
2.安装相关的软件包
yum install gcc gcc-c++ glibc glibc-common gd-devel gd -y
[[email protected] ~]# yum install gcc gcc-c++ glibc glibc-common gd-devel gd -y
3.安装Apache和php
yum install httpd php -y
[[email protected] ~]# yum install httpd php -y
4.下载nagios源码包。
5.解压nagios源码包并编译安装
tar xf nagios-4.0.8.tar.gz
cd nagios-4.0.8
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
[[email protected] ~]# tar xf nagios-4.0.8.tar.gz
[[email protected] ~]# cd nagios-4.0.8
[[email protected]nagios-4.0.8]#./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd
[[email protected] nagios-4.0.8]# make all
[[email protected] nagios-4.0.8]# make install
[[email protected] nagios-4.0.8]# make install-init
[[email protected] nagios-4.0.8]# make install-commandmode
[[email protected] nagios-4.0.8]# make install-config
[[email protected] nagios-4.0.8]# make install-webconf
make install-webconf这命令有个提示:因为这条命令默认是把配置文件复制到/etc/httpd/conf.d/下边的,如果是编译安装的Apache就需要创建/etc/httpd/conf.d/这个目录,然后在httpd.conf配置文件中添加include /etc/httpd/conf.d/。用yum安装的httpd则不需要创建/etc/httpd/conf.d/目录。
sed -i ‘s/[email protected]/[email protected]/‘ /usr/local/nagios/etc/objects/contacts.cfg
[[email protected] nagios-4.0.8]#sed -i ‘s/[email protected]/[email protected]/‘ /usr/local/nagios/etc/objects/contacts.cfg
#必须开启sendmail、检查端口
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
[[email protected] nagios-4.0.8]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#添加nagios管理用户、就是http://IP/nagios/所使用的用户。
#如果使用其他的用户名,请修改/usr/local/nagios/etc/cgi.cfg配置文件的参数
#我的建议是把nagiosadmin替换掉,因为nagiosadmin每个人都知道,这样不安全。
service nagios start
[[email protected] nagios-4.0.8]# service nagios start
#启动nagios服务
[[email protected] nagios-4.0.8]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
或
[[email protected] nagios-4.0.8]# /etc/init.d/nagios checkconfig
#检查配置文件语法
6.下载nagios-plugins插件包
7.解压nagios-plugins插件包并编译安装
tar xf nagios-plugins-2.0.3.tar.gz
cd nagios-plugins-2.0.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
[[email protected] ~]# tar xf nagios-plugins-2.0.3.tar.gz
[[email protected] ~]# cd nagios-plugins-2.0.3
[[email protected]nagios-plugins-2.0.3]#./configure --with-nagios-user=nagios --with-nagios-group=nagios
[email protected] nagios-plugins-2.0.3]# make
#如果编译遇到make:***[all] Error 2则confiure加--with-mysql=/usr/local/mysql 解决
[email protected] nagios-plugins-2.0.3]# make install
[[email protected] nagios-plugins-2.0.3]# ls /usr/local/nagios/libexec/ | wc -l
58
#查看安装了多少个插件、我这里是58个。
8.下载nrpe插件包
9.解压nrpe插件包并编译安装
[[email protected] ~]# tar xf nrpe-2.15.tar.gz
[[email protected] ~]# cd nrpe-2.15
[[email protected] nrpe-2.15]# ./configure
[[email protected] nrpe-2.15]# make all
[[email protected] nrpe-2.15]# make install-plugin
[[email protected] nrpe-2.15]# make install-daemon
[[email protected] nrpe-2.15]# make install-daemon-config
[[email protected] nrpe-2.15]# /usr/sbin/ntpdate pool.ntp.org
[[email protected] nrpe-2.15]# echo ‘*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1‘ >>/var/spool/cron/root
#同步时间并定义计划任务
[[email protected] nrpe-2.15]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[[email protected] nrpe-2.15]# netstat -lnpt | grep 5666
#启动nrpe服务
[[email protected] nrpe-2.15]# pkill nrpe
#关闭nrpe服务
10.客户端安装nagios-plugins和nrpe插件
useradd -M -s /sbin/nologin nagios
tar xf nagios-plugins-2.0.3.tar.gz
cd nagios-pligins-2.0.3
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
[[email protected] ~]# useradd -M -s /sbin/nologin nagios
[[email protected] ~]# tar xf nagios-plugins-2.0.3.tar.gz
[[email protected] ~]# cd nagios-pligins-2.0.3
[[email protected] nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[[email protected] nagios-plugins-2.0.3]# make
[[email protected] nagios-plugins-2.0.3]# make install
[[email protected] ~]# tar xf nrpe-2.15.tar.gz
[[email protected] ~]# cd nrpe-2.15
[[email protected] nrpe-2.15]# ./configure
#出现这个错误是因为缺少openssl-devel软件包,使用yum install openssl-devel -y 即可
[[email protected] nrpe-2.15]# make all
[[email protected] nrpe-2.15]# make install-plugin
[[email protected] nrpe-2.15]# make install-daemon
[[email protected] nrpe-2.15]# make install-daemon-config
[[email protected] ~]# sed -i ‘s/allowed_hosts=127.0.0.1/allowed_hosts=192.168.0.148/‘ /usr/local/nagios/etc/nrpe.cfg
#允许192.168.0.148的主机来监控本主机
[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[[email protected] ~]# netstat -lnpt | grep 5666
或
[[email protected] ~]# lsof -i tcp:5666
#启动nrpe服务、关闭nrpe服务的命令是pkill nrpe
11.服务器配置
#hosts.cfg的配置
define host{
use linux-server
host_name lamp-1
alias lamp-1
address 192.168.1.114
check_command check-host-alive
}
#某些参数请看模板文件,templates.cfg
define hostgroup{
hostgroup_name linux-servers
alias Linux Servers
members lamp-1
}
#services.cfg配置
define service{
use generic-service
host_name lamp-1
service_description DISK
check_command check_disk!20%!10%!/
}
define service{
use generic-service
host_name lamp-1
service_description LOAD
check_command check_load!15,10,5!30,25,20
}
12.客户端配置
#编辑/usr/local/nagios/etc/nrpe.cfg,添加一下内容
#启动nrpe服务
[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[[email protected] ~]# netstat -lnpt | grep 5666