centos 7 下nagios 安装和配置
为恒山等地区用户提供了全套网页设计制作服务,及恒山网站建设行业解决方案。主营业务为网站设计、成都网站建设、恒山网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!一、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 –zxvf nrpe-2.9.tar.gz
#./configure –prefix=/usr/local/nagios
#make all
#make install-pluhin
#make install-daemon
#make install-daemon-config
#chown–R 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
5、添加需要监控的插件和程序
#vim nrpe.conf ##例:
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 50% -c 20%
6、yum install net-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
host_name 10.1.13.213
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
}
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description Current Load
check_command check_nrpe!check_load
}
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description Swap Usage
check_command check_nrpe!check_swap
}
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description SSH
check_command check_ssh!-p 2222!10.1.13.213
}
define service{
use generic-service ; Name of service template to u se
host_name 10.1.13.213
service_description HTTP
check_command check_nrpe!check_http
}
define service{
use generic-service ; Name of service template to u se
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 --hostname localhost --username root --port 3306 --password 910218 --mode threads-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,u,r,f,s
host_notification_commands notify-service-by-email
service_notification_commands notify-service-by-email
}
#vim contacts.cfg
define contact{
contact_name kobe
use kobe
alias bryant
host_notification_period workday
service_notification_period workday
email root@localhost
}
#service group 服务组
#vim object/servicegroup.cfg
define servicegroup{
servicegroup_name kobeservicegroup
alias kobeservicegroup
}
define servicegroup{
servicegroup_name bryantservicegroup
alias bryantservicegroup
}
#vim conf.d/10.1.13.213.cfg 添加servicegroups 名字
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。