温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Redhat安装icinga2

发布时间:2020-06-25 13:11:06 来源:网络 阅读:2231 作者:yangzhimingg 栏目:移动开发

Redhat安装icinga2

 

指导参考网址:http://docs.icinga.org/icinga2/latest/doc/module/icinga2/toc

所需rpm包下载网址:http://packages.icinga.org/epel/

https://packages.icinga.org/epel/6/release/noarch/  icingaweb2包)

 

php-intlphp-pecl-imagick需要单独下

 

 

需要的包:libboost_system1libboost_thread1libboost_regex1libeditboost-license1、libboost_program_options1icinga2icinga2-binicinga2-common、icinga2-ido-mysqlicingaweb2icingaweb2-commonicingaweb2-vendor-*6个)、php-icingaicingaclinagios-plugins

 

安装httpd

# yum install httpd

# yum install php php-gd (注意php版本和icinga2等匹配,如果不匹配就得手动下重装了)

 

php相关包有:phpphp-cliphp-commonphp-gdphp-intlphp-mysqlphp-pdophp-xml

 

额外包:fpingperl-NET-SNMPperl-Crypt-DES  (需先下载好)

 

# rpm -i libboost* boost-license (需先下载好)

# rpm -i libicu-4.2.1-8.2.x86_64.rpm (需先下载好)

# rpm -i icinga2*  php-icinga    (需先下载好)

# rpm -i perl-Crypt-DES perl-NET-SNMP fping perl-Digest-SHA1 perl-Digest-HMACperl-Socket6

# rpm -i nagios-plugins-1.4.16-1.el6.rf.x86_64.rpm  (如果报依赖不想处理的话加--nodeps)

如果提示下面相关报错,做下链接即可

# ln -s /usr/lib64/libicui18n.so.42 /usr/lib64/libicui18n.so.36

# ln -s /usr/lib64/libicuuc.so.42 /usr/lib64/libicuuc.so.36

# ln -s /usr/lib64/libicudata.so.42 /usr/lib64/libicudata.so.36

# ln -s /usr/lib64/libMagickWand.so.2 /usr/lib64/libMagickWand.so.5

 

Log路径:/var/log/icinga2/icinga2.log

 

安装mysql

# yum install mysql-server

# service mysqld start

 

# mysql-u root  

  • use mysql;

  • update user set password=password(’xxxx’) where user=’root’;

  • flush privileges;

  • quit

 

# mysql -u root -p’xxxx’

  • create database icinga2;

  • grant all on icinga2.* to icinga2@localhost identified by ‘xxxxxx’;

  • flush privileges;

  • quit

 

# mysql -u root -p’xxxx’  icinga2 </usr/share/icinga2-ido-mysql/schema/mysql.sql

 

 

# rpm -i icingaweb2-*

 

# service icinga2 restart

# service httpd restart


# vi /etc/php.ini (查找timezone) 


date.timezone = Asia/Shanghai

:wq


# service httpd restart (不然访问页面时会报timezone错误)

 

页面访问:http://ip/icingaweb2

 

暂时还不能登录,点击账号上面的web-basedsetup-wizard

 

然后照着提示在命令行里操作:

 

# icingacli setup config directory --group icingaweb2

# icingacli setup token create

# su -c"mkdir -m 2770 /etc/icingaweb2;chgrp icingaweb2 /etc/icingaweb2;head -c 12 /dev/urandom | base64 | tee /etc/icingaweb2/setup.token;chmod 0660 /etc/icingaweb2/setup.token;"

 

然后将乱码贴到页面上

 

模块部分全勾,然后会提示the phpconfig 'date.timezone' is not defined

 

# vi/etc/php5/apache2/php.ini

 

date.timezone= Asia/Shanghai   (默认是注释掉的)

 

:wq

# service httpd restart

 

再点击refresh即可(其它***提示可忽略)——Database——将数据库、用户名等补上,勾上Skip Validation——设置管理账号及密码

 

如果提示没有icingaweb_user表,就手动创建下吧,命令如下:

  • use icinga2;

  • create table icingaweb_user (name varchar(64) not null,activetinyint(1) not null,password_hash varbinary(255) not null,ctime timestamp,mtimetimestamp);

 

如果页面显示“icinga is currently notup and running” ,一是看/etc/icinga2/features-enabled/下是否有ido-mysql.conf,如果没有从/etc/icinga2/features-available/处链接过来即可;二是看/var/log/icinga2/icinga2.log提示

 

 

 

添加主机:

 

# cd /etc/icinga2/conf.d/

# vi shhudson.conf

 

object Host"hudson15" {

  import "generic-host"

  address = "10.0.0.2"

  vars.os = "Linux Servers"

  vars.sla = "24x7"

}

:wq

# chown icinga:icinga shhudson.conf

# service icinga2 restart 

 

此时页面上就会显示“hudson15”主机

 

添加主机组:

 

# cd /etc/icinga2/conf.d/

# vi groups.conf

 

object HostGroup"shhudson" {

  display_name = "shhudson"

  assign where host.vars.os =="shhudson"

}

:wq

# service icinga2 restart

 

此时页面上就会显示“shhudson”主机组

 

 

 

安装nrpe(管理多台主机)

 

# rpm -i nagios-plugins-nrpe-2.14-1.el6.rf.x86_64.rpm(需先下载好)

 

此时会生成/usr/lib64/nagios/plugins/check_nrpe

 

# /usr/lib64/nagios/plugins/check_nrpe-H 10.0.0.5   (显示NRPE v2.12即为正常,前提是客户端已安装nrpe插件)

 

 

配置nrpe

 

说明:空间大小以MB为单位,KMB1000MB1GB),MMB1000000MB(即1TB


另check_mem.pl需额外下载插件使用(步骤略)

 

# vi /etc/icinga2/conf.d/templates.conf

templateCheckCommand "nrpe-common" {

  import "plugin-check-command"

  command = [ PluginDir +"/check_nrpe" ]

  arguments = {

  "-H" = "$nrpe_address$"

  "-p" = "$nrpe_port$"

  "-c" = "$nrpe_command$"

  "-a" = {

       value = "$nrpe_args$"

       repeat_key = false

       order = 1

}

}

  vars.nrpe_address = "$address$"

  vars.nrpe_port = 5666

}

 

objectCheckCommand "nrpe-disk" {

   import "nrpe-common"

   vars.nrpe_command = "check_disk"

}

 

objectCheckCommand "nrpe-load" {

   import "nrpe-common"

   vars.nrpe_command = "check_load"

}

 

objectCheckCommand "nrpe-users" {

   import "nrpe-common"

   vars.nrpe_command = "check_users"

}

:wq

 

# vi/etc/icinga2/conf.d/services.conf

 

applyService "nrpe-disk" {

  import "generic-service"

  check_command = "nrpe-disk"

  assign where host.address

}

 

apply Service"nrpe_load" {

  import "generic-service"

  check_command = "nrpe-load"

  assign where host.address

}

 

applyService "nrpe_users" {

  import "generic-service"

  check_command = "nrpe-users"

  assign where host.address

}

:wq

 

# vi /etc/icinga2/conf.d/shhudson.conf

object Host"hudson15" {

  import "generic-host"

  address = "10.0.0.2"

  vars.os = "Linux Servers"

  vars.sla = "24x7"

}

 

:wq

# service icinga2restart

 

 

命令使用:

# /usr/lib64/nagios/plugins/check_nrpe -H shming03 -c check_disk -a 10,20

 

 

客户端安装nrpe插件:

 

Ubuntu

 

# useradd -s /sbin/nologin -M nagios
# apt-get install nagios-nrpe-server nagios-plugins
编辑nrpe配置文件
# vi /etc/nagios/nrpe.cfg

allowed_hosts=127.0.0.1,10.0.0.2   (默认为allowed_hosts=127.0.0.1)

dont_blame_nrpe=1
:wq

启动nrpe
# service nagios-nrpe-server start

 

 

Redhat:

 

# rpm -i perl-Crypt-DES perl-NET-SNMP fping perl-Digest-SHA1 perl-Digest-HMACperl-Socket6  (需要下载,有的本地yum里有)

# rpm -i nagios-plugins-1.4.16-1.el6.rf.x86_64.rpm

# rpm -i nagios-nrpe-2.14-1.el6.rf.x86_64.rpm  (需要下载)

# vi /etc/nagios/nrpe.cfg  (command都需加sudo)


command[check_cpu]=sudo /usr/lib64/nagios/plugins/check_snmp_load.pl -H 127.0.0.1 -C 'xxxxx' -w 80 -c 90 --perf

allowed_hosts=127.0.0.1,10.0.0.2   (默认为allowed_hosts=127.0.0.1)

dont_blame_nrpe=1
:wq

启动nrpe
# service nrpe start


# vi /etc/sudoers (此处不配会报NRPE: Unable to read output)

nagiosALL=(ALL) NOPASSWD:/usr/lib64/nagios/plugins/*

#Defaults    requiretty

:wq


 

记得开防火墙端口(199、5666,即snmp和nrpe)

# vi /etc/sysconfig/iptables

 

-A INPUT–p tcp –dport 199 –j ACCEPT

-A INPUT–p tcp –dport 5666 –j ACCEPT

:wq

# service iptables restart

 

 

安装pnp4nagios

 

下载网址:https://github.com/Icinga/icinagweb2-module-pnp4ngaios

 

下载后解压并改名为pnp4nagios,剪切到/usr/share/icingaweb2/modules/

重启icinga2后,到页面——Configuration——Modules——pnp4nagios——enable

 

下载pnp4nagios rpm

 

# rpm –i pnp4nagios –nodeps

# rpm –i perl-rrdtool –nodeps

 

安装后会自动生成/etc/httpd/conf.d/pnp4ngaios.conf  (如果不设置用户、密码,可在此处取消)

 

主配置文件路径:/etc/pnp4ngaios

 

还有1路径:/usr/share/nagios/html/pnp4ngios  (实际web路径)

 

# vi/etc/pnp4nagios/npcd.cfg

 

User  = icinga

Group =icinga

Perfdata_spool_dir=/var/spool/icinga2/perfdata

:wq

 

 

# vi/etc/icinga2/conf.d/templates.conf

 

template Host "pnp-hst" {

   action_url ="/pnp4nagios/graph?host=$HOSTNAME$'rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_"

}

 

template Service "pnp-svc" {

   action_url ="/pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDES$"

}

 

 

template Host "generic-host" {

  max_check_attempts = 3

  check_interval = 1m

  retry_interval = 30s

  check_command = "hostalive"

  import "pnp-hst"

}

 

template Service "generic-service" {

  max_check_attempts = 5

  check_interval = 1m

  retry_interval = 30s

  import "pnp-svc"

}

:wq


# chown icinga /var/lig/pnp4nagios

 

# icinga2 feature enable perfdata

 

# service httpd restart

# service npcd restart

# service icinga2 restart

 

 

可先访问下http://ip/pnp4ngaios是否正常,不能正常显示的话就看httpdlog

 

 

发报警邮件

说明:默认为30分钟发一次

 

# vi/etc/icinga2/conf.d/users.conf

 

Email = zhi.yang@ming.com

:wq

 

# vi /etc/icinga2/conf.d/shhudson.conf

object Host"hudson15" {

  import "generic-host"

  address = "10.0.0.2"

  vars.os = "Linux Servers"

  vars.sla = "24x7"

  vars.notification[“mail”] = {

   groups = [ “icingaadmins” ]

}

}

:wq

 

# service icinga2 restart

 

# vi/etc/postfix/main.cf

 

Relayhost= 10.0.1.5    (公司的邮箱服务器

:wq

 

# service postfix restart

 

可手动发邮件验证下:

# mail –s“aa” zhi.yang@ming.com < aa

 

# cat/var/log/maillog

 

调整发邮件级别:

 

# vi/etc/icinga2/conf.d/templates.conf

 

调整states部分即可

:wq

 

可以对user进行定制(多邮件人通知):


# vi /etc/icinga2/conf.d/users.conf


object User "bj"

 import "generic-user"

 states = [ OK,Critical]  (此处对报警类型也可定制)

 email = "zhi.yang@ming.com,ming.yang@ming.com"  (此处可以写多人)

:wq


# vi /etc/icinga2/conf.d/shhudson.conf

object Host"hudson15" {

  import "generic-host"

  address = "10.0.0.2"

  vars.os = "Linux Servers"

  vars.sla = "24x7"

  vars.notification[“mail”] = {

  users = [ “bj” ]    (多user中间用“,”隔开)

}

}

:wq

 




 

监控存储(check-netapp-ng.pl):

 

下载网址:https://github.com/ranl/monitor-utils/blob/master/nagios/check-netapp-ng.pl

 

# mv check-netapp-ng.pl/usr/lib64/nagios/plugins/

# chmod +x /usr/lib64/nagios/plugins/check-netapp-ng.pl

 

使用:

 

卷:

# /usr/lib64/nagios/plugins/check-netapp-ng.pl–H 10.0.0.3 –C public –T DISKUSED –vol /vol/Backup –w 90 –c 95

 

整体状态:

# /usr/lib64/nagios/plugins/check-netapp-ng.pl–H 10.0.0.3 –C public –T GLOBALSTATUS

 

CPU:

# /usr/lib64/nagios/plugins/check-netapp-ng.pl–H 10.0.0.3 -C public -T CPULOAD –w 90 –c 95




icinga2监控存储整体状态(单个卷超过98%会报警的):

 

# vi/etc/icinga2/conf.d/templates.conf

 

objectCheckCommand "check-netapp" {

  import "plugin-check-command"

  command = [ PluginDir +"/check-netapp-ng.pl" ]

  arguments = {

  "-H" = "$address$"

  "-C" = "$snmp$"

  "-T" = "$checktype$"

  "-w" = "$warn$"

  "-c" = "$crit$"

}

}

:wq

 

# vi/etc/icinga2/conf.d/services.conf

 

applyService "check_netapp" {

  import "generic-service"

  check_command = "check-netapp"

  vars.snmp="public"

  vars.checktype="GLOBALSTATUS"

  vars.vol="/vol/Backup/"

  assign where host.vars.os =="netapp"

}

:wq

 

# vi/etc/icinga2/conf.d/netapp.conf

 

objectHost "shnas7" {

  import "generic-host"

  address = "10.0.1.21"

  vars.os = "netapp"

  vars.sla = "24x7"

  vars.notification["mail"] = {

  groups = [ "icingaadmins" ]

}

}

:wq

 

# chownicinga:icinga /etc/icinga2/conf.d/netapp.conf

# service icinga2 restart

 


监控windows主机:


需要借助3个插件:check_snmp_storage.pl、check_snmp_memory.pl、check_snmp_load.pl


下载网址:

http://nagios.manubulon.com/check_snmp_load.pl

https://exchange.nagios.org/directory/Plugins/Network-Protocols/SNMP/Simple-snmp-memory-check/details

https://github.com/dnsmichi/manubulon-snmp/blob/master/plugins/check_snmp_storage.pl



使用:


# ./check_snmp_load.pl -H 10.0.0.3 -C public -w 80 -c 90

# ./check_snmp_memory.pl -H 10.0.0.3 -C public -w 80 -c 90

# ./check_snmp_storage.pl -H 10.0.0.3 -C public -m D: -w 80 -c 90


# vi/etc/icinga2/conf.d/templates.conf

 

objectCheckCommand "check-win-disk" {

  import "plugin-check-command"

  command = [ PluginDir +"/check_snmp_storage.pl" ]

  arguments = {

  "-H" = "$address$"

  "-C" = "$snmp$"

  "-m" = "$disk$"

  "-w" = "$warn$"

  "-c" = "$crit$"

 "-f" = {

         set_if = "$perf$"

    }

}

}


objectCheckCommand "check-win-mem" {

  import "plugin-check-command"

  command = [ PluginDir +"/check_snmp_memory.pl" ]

  arguments = {

  "-H" = "$address$"

  "-C" = "$snmp$"

  "-w" = "$warn$"

  "-c" = "$crit$"

 "-f" = {

         set_if = "$perf$"

    }

}

}


objectCheckCommand "check-win-load" {

  import "plugin-check-command"

  command = [ PluginDir +"/check_snmp_load.pl" ]

  arguments = {

  "-H" = "$address$"

  "-C" = "$snmp$"

  "-w" = "$warn$"

  "-c" = "$crit$"

 "-f" = {

         set_if = "$perf$"

    }

}

}

:wq


# vi /etc/icinga2/conf.d/services.conf

 

applyService "check_win_disk" {

  import "generic-service"

  check_command = "check-win-disk"

  vars.snmp="public"

  vars.disk="C:"

  vars.warn="80"

  vars.crit="90"

  vars.perf = true

  assign where host.vars.os =="shwin"

}


apply Service "check_win_load" {

  import "generic-service"

  check_command = "check-win-load"

  vars.snmp="public"

  vars.warn="80"

  vars.crit="90"

  vars.perf = true

  assign where host.vars.os == "shwin"

}


apply Service "check_win_mem" {

  import "generic-service"

  check_command = "check-win-mem"

  vars.snmp="public"

  vars.warn="80"

  vars.crit="90"

  vars.perf = true

  assign where host.vars.os == "shwin"

}


:wq


# vi /etc/icinga2/conf.d/shwin.conf

object Host"shwin" {

  import "generic-host"

  address = "10.0.0.3"

  vars.os = "shwin"

  vars.sla = "24x7"

  vars.notification[“mail”] = {

  users = [ “bj”,“aa” ]    (多user中间用“,”隔开)

}

}

:wq


# chown icinga:icinga /etc/icinga2/conf.d/shwin.conf


修改groups.conf略


# service icinga restart



windows安装snmp


控制面板——程序和功能——打开或关闭windows功能——勾选SNMP——开始——搜索——输入服务——确保SNMP service是启动状态——双击——安全——添加社区“public”(此处可改)——确认防火墙关闭

 


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI