nagios监控
1 安装nagios
tar jxf nagios-cn-3.2.3tar.bz2
yum install gd-deverl-2.0.35-11.el.x86_64.rpm
cd nagios-cn-3.2.3
groupadd nagcmd
useradd -M -d /usr/local/nagios -G nagcmd nagios ##创建用户nagios并使他从属于nagcmd组##
usermod -G nagcmd apache ##将apache加入nagcmd组
./configure --with-command-group=nagcmd ##配置编译环境中的指定组为nagcmd
make all ##编译
make install ##安装
make install-init ##安装启动脚本
make install-config ##安装配置文件
make install-commandmode ##安装命令模式
make install-webconf ##安装网页配置文件
htpasswd /usr/local/nagios/etc/htpasswd.users nagiosadmin ##设定nagios的登陆密码
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ##检测是否正确
/etc/init.d/nagios start ##启动nagios
2 安装nagios插件
tar zxf nagios-plugin-1.4.14.tar.gz
cd nagios-plugin-1.4.14
yum install mysql-deverl openssl-devel -y
./configure
make ##编译
make install ##安装
cd /usr/local/nagios/libexec/ ##进入nagios插件的目录下
chown nagios.nagios * -R ##将该目录下文件权限都改成nagios所有组和所有用户
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ##检测是否正确
/etc/init.d/nagios reload ##重新加载nagios
3 nagios配置
cd /usr/local/nagios/etc/
vim nagios.cfg ##编辑nagios的主配置文件
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cd objects/
cp -p localhost.cfg host.cfg ##复制示例到host.cfg
cp -p localhost.cfg services.cfg ##复制示例到services.cfg
vim /usr/local/nagios/etc/objects/hosts.cfg
define host {
use linux-server
host_name server3.example.com ##改主机名
address 172.25.35.3 ##改地址
alias Manager
# parents MainSwitch ##由于只监控一台主机所有注销掉关联主机
icon_image server.gif
statusmap_image server.gd2
2d_coords 500,200
3d_coords 500,200,100
}
vim /usr/local/nagios/etc/objects/services.cfg
:%s/田朝阳家用机/server3.example.com/g
define servicegroup{
servicegroup_name 系统负荷检查
alias 负荷检查
Members server3.example.com,进程总数,server3.example.com,登录用户数,server3.example.com,根分区,server3.example.com,交换空间利用率
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ##检测nagios配置是否正确
/etc/init.d/nagios reload ##重新加载nagios
http://172.25.35.3/nagios ##访问nagios
4 添加监控数据库mysql
在server2上:
yum install -y mysql-server ##安装
/etc/init.d/mysqld start ##开启
mysql_secure_installation ##数据库安全初始化,设置密码:westos
mysql -pwestos ##用root用户登录
mysql> create database nagdb; ##建立数据库nagdb
mysql> grant select on nagdb.* to nagios@‘172.25.35.3‘ identified by ‘nagios‘; ##给用户nagios授权,设定登陆密码为nagios
在server3上:
cd /usr/local/nagios/libexec/
check_mysql -H 172.25.35.2 -u nagios -p nagios ##检测能否连上server2的mysql
在nagios上添加对mysql监控的定义:
cd /usr/local/nagios/etc/objects/
vim commands.cfg
####‘check_mysql‘command definition####
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$
}
vim services.cfg
####check_mysql####
define service {
use local-service
host_name server2.example.com
service_description MYSQL
check_command check_mysql!nagios!nagios
}
vim hosts.cfg
define host {
use linux-server
host_name server2.example.com ##改主机名
address 172.25.35.2 ##改地址
alias server2
parents server3.example.com ##与server3建立关联
icon_image server.gif
statusmap_image server.gd2
2d_coords 400,100
3d_coords 400,100,100
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ##检测nagios配置是否正确
/etc/init.d/nagios reload ##重新加载nagios
5 安装nrpe
在server2上:
tar zxf nrpe-2.15.tar.gz
yum install -y gcc nagios-plugins-2.1.1 openssl-devel mysql-devel
cd nrpe-2.15/docs/
useradd -M -d /usr/local/nagios nagios ##建立nagios用户
cd nrpe-plugins-2.1.1/
./configure
make all
make install
cd /usr/local/nagios/
chown nagios.nagios . -R ##把当前目录下的文件全改成nagios的所有用户和所有组
yum install -y xinetd
cd nrpe-2.15/
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
6 配置nrpe
cd nrpe2-15/etc/xinetd/
vim nrpe
only_from = 172.25.35.3 ##nagios的IP
vim /etc/services
nrpe 5666/tcp ##nrpe的端口为5666
/etc/init.d/xinetd start ##启动xinetd
cd /usr/local/nagios/etc/
vim nrpe.cfg
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / ##监控根分区
/etc/init.d/xinetd restart ##重启xinetd服务
scp check_nrpe 172.25.35.3:/usr/local/nagios/libexec/ ##将nrpe传到server3上
在server3上:
cd /usr/local/nagios/libexec/
chown nagios.nagios check_nrpe ##将check_nrpe的所有人所有组都改成nagios
./check_nrpe -H 172.25.35.2
./check_nrpe -H 172.25.35.2 -c check_disk ##监控磁盘的状况
vim /usr/local/nagios/etc/objects/commands.cfg
####‘check_nrpe‘command definition####
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
vim /usr/local/nagios/etc/objects/services.cfg
####check_nrpe####
define service {
use local-service
host_name server2.example.com
service_description 根分区
check_command check_nrpe!check_disk
}
define service {
use local-service
host_name server2.example.com
service_description 登陆用户数
check_command check_nrpe!check_users
}
cd /usr/local/nagios/etc/objects/
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload
本文出自 “8875406” 博客,转载请与作者联系!
原文地址:http://8885406.blog.51cto.com/8875406/1788482