nagios监控端部署
安装nagios-server端
#创建nagios用户组和用户
groupadd nagios
useradd -g nagios nagios
#编译安装nagios
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz
tar -zxvf nagios-4.3.1.tar.gz
cd nagios-4.3.1
./configure --prefix=/usr/local/nagios #检查编译环境
make all #编译
make install #安装Nagios程序的主要文件
make install-init #安装Nagios服务init脚本
make install-commandmode #安装Nagios权限相关
make install-webconf #安装Nagios网页配置文件
make install-config #安装Nagios配置文件目录
#生成Nagios网页认证文件并创建用户
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#添加nagios到开机自启
chkconfig --add nagios
chkconfig --level 35 nagios on
chkconfig --list nagios
#启动httpd和nagios
/etc/init.d/httpd restart
/etc/init.d/nagios restart
安装nagios-plugins
wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
tar -zxvf nagios-plugins-2.1.4.tar.gz
cd nagios-plugins-2.1.4
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
#注意:如果要监控mysql 需要添加 --with-mysql
安装nrpe
NRPE是监控软件nagios的一个扩展,它被用于被监控的服务器上,向nagios监控平台提供该服务器的一些本地的情况。例如,cpu负载、内存使用、硬盘使用等等。NRPE可以称为nagios的for linux 客户端。
yum -y install gcc gcc-c++ openssl-devel xinetd
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.15.tar.gz
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure --prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
配置NRPE
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=10.0.0.21
vim /etc/xinetd.d/nrpe
only_from = 10.0.0.21
#配置/etc/services
vim +429 /etc/services
nrpe 5666/tcp
nrpe 5666/udp
#启动NRPE
/etc/init.d/xinetd restart
#启动httpd和nagios
/etc/init.d/httpd restart
/etc/init.d/nagios restart
#测试nrpe效果
/usr/local/nagios/libexec/check_nrpe -H 10.0.0.21 -c check_load
浏览器访问
nagios.cfg
路径整理
Nagios安装目录:/usr/local/nagios
Nagios插件目录:/usr/local/nagios/libexec
Nagios配置文件目录:/usr/local/nagios/etc
配置文件整理
Nagios主配置文件:/usr/local/nagios/etc/nagios.cfg
Nagios定义命令的配置文件:/usr/local/nagios/etc/objects/commands.cfg
Nagios定义联系人的配置文件:/usr/local/nagios/etc/objects/contacts.cfg
Nagios定义监控windows系统的配置文件:/usr/local/nagios/etc/objects/windows.cfg
Nagios定义监控本机的配置文件:/usr/local/nagios/etc/objects/localhost.cfg
Nagios定义模板的配置文件:/usr/local/nagios/etc/objects/templates.cfg
Nagios定义监控时间模板的配置文件:/usr/local/nagios/etc/objects/timeperiods.cfg
Nagios定义变量的配置文件:/usr/local/nagios/etc/resource.cfg
nagios被监控端部署(linux)
监控另一台linux服务器
(1)添加nagios用户
useradd -s /sbin/nologin nagios
mkdir /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios
(2)安装nagios-plugins
wget https://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
tar -zxvf nagios-plugins-2.1.4.tar.gz
cd nagios-plugins-2.1.4
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
(3)安装NRPE
yum -y install gcc gcc-c++ openssl-devel xinetd
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.15.tar.gz
tar -zxvf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure --prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
(4) 配置NRPE
注意:此处的ip为nagios服务端的ip
vim /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=10.0.0.21
vim /etc/xinetd.d/nrpe
only_from = 10.0.0.21
#配置/etc/services
vim +429 /etc/services
nrpe 5666/tcp
nrpe 5666/udp
(5)启动NRPE
/etc/init.d/xinetd restart
nagios服务端配置
##在Nagios监控端10.0.0.21上添加一台被监控的主机 (1)新增一个配置文件linux.cfg
vim /usr/local/nagios/etc/nagios.cfg
增加
cfg_file=/usr/local/nagios/etc/objects/linux.cfg
(2)编辑新加主机的配置文件
vim /usr/local/nagios/etc/objects/linux.cfg
define host{
use linux-server
host_name c6s02
alias c6s02
address 10.0.0.22
}
#修改属主属组
chown -R nagios.nagios /usr/local/nagios/etc/objects/linux.cfg
(3)检查语法并重启
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
或者
/etc/init.d/nagios configtest
/etc/init.d/nagios restart