403.blog.51cto.come/u261/themes/default/images/spacer.gif">
一、yum -y install httpd gcc glibc glibc-common *gd* PHP PHP-MysqL MysqL MysqL-server MysqL-devel PHP-snmp net-snmp net-snmp-libs net-snmp-utils PHP-pdo perl-DBD-MysqL rrd-tool
perl-rrdtool rrdtool-devel mariadb-server mariadb-devel
二、yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
上面在cacti 安装配置中已经安装,这里就不再进行安装了
centos 7 yum 安装nagios
yum install nagios
yum install nagios-plugins-all
1、tar -zxvf nagios ...tar.gz
#useradd nagios
#passwd nagios
#cd nagios..
#./configure --prefix=/usr/local/nagios
#make all
#make install
#make install-init
# make install-commandmode
#make install-config
#make install-webconf安装到了Apache目录下conf.d目录了
#make install-exfoliation
#make install-classicui
#修改httpd.conf里的User和Group为nagios 改了之后cacti注意,能不能使用cacti了
2、编译安装nagios-plugins-2.0 #./configure --prefix=/usr/local/nagios
#make&&make install
3、安装nrpe,#tar �Czxvf nrpe-2.9.tar.gz
#./configure �Cprefix=/usr/local/nagios
#make all
#make install-pluhin
#make install-daemon
#make install-daemon-config
#chown�CR nagios:nagios /usr/local/nagios
#更改/usr/local/nagios/etc/cgi.cfg 里面nagiosadmin 改成nagios
#service nagios start
#service httpd start
#service MysqL start
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
#vim nagios/etc/objects/command.cfg 添加
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 30
}
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
#/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
被监控主机配置:
4、安装nrpe
#./configure --prefix=/usr/loca/nagios
#make all && make install-plugin && make install-daemon && make install-daemon-conig
#vim /usr/local/nagios/etc/nrpe.conf 添加监控服务器IP
allowed_hosts=127.0.0.1,10.1.13.176
#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.conf -d 开启的端口是5666
#安装nagios-plugin
#vim nrpe.conf ##例:
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 20%
6、yum installnet-snmp-libs net-snmp-utils net-snmp
监控主机配置nrpe service
#mkdir server
#vim nagios.conf 添加 cfg_dir=/usr/local/nagios/etc/server
#vim/usr/local/nagios/etc/server/group.cfg
define hostgroup{
hostgroup_name Servers ; The name of the hostgroup
alias Servers ; Long name of the group
}
define hostgroup{
hostgroup_name backup ; The name of the hostgroup
alias backup ; Long name of the group
}
#cd /usr/local/nagios/etc/server && vim 10.1.13.213.cfg
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
hostgroups Servers
; in (or inherited by) the linux-server host template definition.
host_name 10.1.13.213
alias backup
address 10.1.13.213
}
define service{
use generic-service
service_description Ping
check_command check_ping!100.0,20%!150.0,60%
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description Root Partition
check_command check_nrpe!check_sda1
service_description Current Users
check_command check_nrpe!check_users
service_description Total Processes
check_command check_nrpe!check_total_procs
service_description Current Load
check_command check_nrpe!check_load
service_description Swap Usage
check_command check_nrpe!check_swap
service_description SSH
check_command check_ssh!-p 2222!10.1.13.213
define service{
service_description HTTP
check_command check_nrpe!check_http
host_name 10.1.13.213
service_description zombie_proces
check_command check_nrpe!check_zombie_procs
}
#上面的红色字体,在被监控主机的nrpe.conf 的command 中要定义
监控MysqL
#cd check_MysqL_health
#./configure --prefix=/usr/local/nagios
#make && make install
#./usr/local/nagios/libexec/check_MysqL_health 出现Can't locate Time/HiRes.pm in @INC 的perl 错误 ,解决办法:安装
#yum install -y perl-Time-HiRes
#vim 10.1.1.13.213.cfg
define service{
use local-service
host_name 10.1.13.213
service_description MysqL
check_command check_nrpe!check_MysqL_health
}
在被监控的主机上:#vim nrpe.conf 添加:command[check_MysqL_health]=/var/www/nagios/libexec/check_MysqL_health--hostnamelocalhost--usernameroot--port3306--password910218--modethreads-connected
#MysqL -u root -p
>grant all privileges on *.* to 'root'@'%' identified by '910218';
>flush privileges;
>quit
在主监控服务器上测试被监控机上的MysqL连接:MysqL -u root -p 10.1.13.213
定义时间段和联系人
#vim timeperiods.cfg
define timeperiod{
name workday
timeperiod_name workday
alias workday
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
define timeperiod {
name weekends
timeperiod_name weekends
alias weekends
saturday 00:00-24:00
sunday 00:00-24:00
#vim templates.cfg
define contact{
name kobe
service_notification_period workday
host_notification_period workday
service_notification_options w,u,r,f,s
host_notification_options d,255);"> host_notification_commands notify-service-by-email
service_notification_commands notify-service-by-email
#vim contacts.cfg
definecontact{
contact_namekobe
usekobe
aliasbryant
host_notification_periodworkday
service_notification_periodworkday
emailroot@localhost
}
#service group 服务组
#vim object/servicegroup.cfg
define servicegroup{
servicegroup_name kobeservicegroup
alias kobeservicegroup
}
servicegroup_name bryantservicegroup
alias bryantservicegroup
}
#vim conf.d/10.1.13.213.cfg 添加servicegroups 名字
403.blog.51cto.come/u261/themes/default/images/spacer.gif">