设为首页 收藏本站
查看: 2298|回复: 0

[经验分享] Redhat安装icinga2

[复制链接]

尚未签到

发表于 2018-5-10 10:31:35 | 显示全部楼层 |阅读模式
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-intl、php-pecl-imagick需要单独下
  需要的包:libboost_system1、libboost_thread1、libboost_regex1、libedit、boost-license1、libboost_program_options1、icinga2、icinga2-bin、icinga2-common、icinga2-ido-mysql、icingaweb2、icingaweb2-common、icingaweb2-vendor-*(6个)、php-icinga、icingacli、nagios-plugins
  安装httpd:
  # yum install httpd
  # yum install php php-gd (注意php版本和icinga2等匹配,如果不匹配就得手动下重装了)
  php相关包有:php、php-cli、php-common、php-gd、php-intl、php-mysql、php-pdo、php-xml
  额外包:fping、perl-NET-SNMP、perl-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
  如果提示下面相关报错,做下链接即可
  # 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
  # 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&quot;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;&quot;
  然后将乱码贴到页面上
  模块部分全勾,然后会提示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&quot;hudson15&quot; {
    import &quot;generic-host&quot;
    address = &quot;10.0.0.2&quot;
    vars.os = &quot;Linux Servers&quot;
    vars.sla = &quot;24x7&quot;
  }
  :wq
  # chown icinga:icinga shhudson.conf
  # service icinga2 restart  
  
  此时页面上就会显示“hudson15”主机
  
  添加主机组:
  
  # cd /etc/icinga2/conf.d/
  # vi groups.conf
  
  object HostGroup&quot;shhudson&quot; {
    display_name = &quot;shhudson&quot;
    assign where host.vars.os ==&quot;shhudson&quot;
  }
  :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为单位,KMB为1000MB(1GB),MMB为1000000MB(即1TB)
  

  另check_mem.pl需额外下载插件使用(步骤略)
  # vi /etc/icinga2/conf.d/templates.conf
  templateCheckCommand &quot;nrpe-common&quot; {
  import &quot;plugin-check-command&quot;
  command = [ PluginDir +&quot;/check_nrpe&quot; ]
  arguments = {
  &quot;-H&quot; = &quot;$nrpe_address$&quot;
  &quot;-p&quot; = &quot;$nrpe_port$&quot;
  &quot;-c&quot; = &quot;$nrpe_command$&quot;
  &quot;-a&quot; = {
  value = &quot;$nrpe_args$&quot;
  repeat_key = false
  order = 1
  }
  }
  vars.nrpe_address = &quot;$address$&quot;
  vars.nrpe_port = 5666
  }
  objectCheckCommand &quot;nrpe-disk&quot; {
  import &quot;nrpe-common&quot;
  vars.nrpe_command = &quot;check_disk&quot;
  }
  objectCheckCommand &quot;nrpe-load&quot; {
  import &quot;nrpe-common&quot;
  vars.nrpe_command = &quot;check_load&quot;
  }
  objectCheckCommand &quot;nrpe-users&quot; {
  import &quot;nrpe-common&quot;
  vars.nrpe_command = &quot;check_users&quot;
  }
  :wq
  # vi/etc/icinga2/conf.d/services.conf
  applyService &quot;nrpe-disk&quot; {
  import &quot;generic-service&quot;
  check_command = &quot;nrpe-disk&quot;
  assign where host.address
  }
  apply Service&quot;nrpe_load&quot; {
    import &quot;generic-service&quot;
    check_command = &quot;nrpe-load&quot;
    assign where host.address
  }
  
  applyService &quot;nrpe_users&quot; {
  import &quot;generic-service&quot;
  check_command = &quot;nrpe-users&quot;
  assign where host.address
  }
  :wq
  # vi /etc/icinga2/conf.d/shhudson.conf
  object Host&quot;hudson15&quot; {
    import &quot;generic-host&quot;
    address = &quot;10.0.0.2&quot;
    vars.os = &quot;Linux Servers&quot;
    vars.sla = &quot;24x7&quot;
  }
  
  :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 &quot;pnp-hst&quot; {
  action_url =&quot;/pnp4nagios/graph?host=$HOSTNAME$'rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=_HOST_&quot;
  }
  template Service &quot;pnp-svc&quot; {
  action_url =&quot;/pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$'rel='/pnp4nagios/popup?host=$HOSTNAME$&srv=$SERVICEDES$&quot;
  }
  template Host &quot;generic-host&quot; {
  max_check_attempts = 3
  check_interval = 1m
  retry_interval = 30s
  check_command = &quot;hostalive&quot;
  import &quot;pnp-hst&quot;
  }
  template Service &quot;generic-service&quot; {
  max_check_attempts = 5
  check_interval = 1m
  retry_interval = 30s
  import &quot;pnp-svc&quot;
  }
  :wq
  # chown icinga /var/lig/pnp4nagios
  # icinga2 feature enable perfdata
  # service httpd restart
  # service npcd restart
  # service icinga2 restart
  可先访问下http://ip/pnp4ngaios是否正常,不能正常显示的话就看httpd的log吧
  发报警邮件
  说明:默认为30分钟发一次
  # vi/etc/icinga2/conf.d/users.conf
  Email = zhi.yang@ming.com
  :wq
  # vi /etc/icinga2/conf.d/shhudson.conf
  object Host&quot;hudson15&quot; {
    import &quot;generic-host&quot;
    address = &quot;10.0.0.2&quot;
    vars.os = &quot;Linux Servers&quot;
    vars.sla = &quot;24x7&quot;
    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 &quot;bj&quot;
  import &quot;generic-user&quot;
  states = [ OK,Critical]  (此处对报警类型也可定制)
  email = &quot;zhi.yang@ming.com,ming.yang@ming.com&quot;  (此处可以写多人)

  :wq
# vi /etc/icinga2/conf.d/shhudson.conf
object Host&quot;hudson15&quot; {
  import &quot;generic-host&quot;
  address = &quot;10.0.0.2&quot;
  vars.os = &quot;Linux Servers&quot;
  vars.sla = &quot;24x7&quot;
  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 &quot;check-netapp&quot; {
  import &quot;plugin-check-command&quot;
  command = [ PluginDir +&quot;/check-netapp-ng.pl&quot; ]
  arguments = {
  &quot;-H&quot; = &quot;$address$&quot;
  &quot;-C&quot; = &quot;$snmp$&quot;
  &quot;-T&quot; = &quot;$checktype$&quot;
  &quot;-w&quot; = &quot;$warn$&quot;
  &quot;-c&quot; = &quot;$crit$&quot;
  }
  }
  :wq
  # vi/etc/icinga2/conf.d/services.conf
  applyService &quot;check_netapp&quot; {
  import &quot;generic-service&quot;
  check_command = &quot;check-netapp&quot;
  vars.snmp=&quot;public&quot;
  vars.checktype=&quot;GLOBALSTATUS&quot;
  vars.vol=&quot;/vol/Backup/&quot;
  assign where host.vars.os ==&quot;netapp&quot;
  }
  :wq
  # vi/etc/icinga2/conf.d/netapp.conf
  objectHost &quot;shnas7&quot; {
  import &quot;generic-host&quot;
  address = &quot;10.0.1.21&quot;
  vars.os = &quot;netapp&quot;
  vars.sla = &quot;24x7&quot;
  vars.notification[&quot;mail&quot;] = {
  groups = [ &quot;icingaadmins&quot; ]
  }
  }
  :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 &quot;check-win-disk&quot; {
  import &quot;plugin-check-command&quot;
  command = [ PluginDir +&quot;/check_snmp_storage.pl&quot; ]
  arguments = {
  &quot;-H&quot; = &quot;$address$&quot;
  &quot;-C&quot; = &quot;$snmp$&quot;
  &quot;-m&quot; = &quot;$disk$&quot;
  &quot;-w&quot; = &quot;$warn$&quot;
  &quot;-c&quot; = &quot;$crit$&quot;
&quot;-f&quot; = {
         set_if = &quot;$perf$&quot;
    }
}
}


objectCheckCommand &quot;check-win-mem&quot; {
  import &quot;plugin-check-command&quot;
  command = [ PluginDir +&quot;/check_snmp_memory.pl&quot; ]
  arguments = {
  &quot;-H&quot; = &quot;$address$&quot;
  &quot;-C&quot; = &quot;$snmp$&quot;
  &quot;-w&quot; = &quot;$warn$&quot;
  &quot;-c&quot; = &quot;$crit$&quot;
&quot;-f&quot; = {
         set_if = &quot;$perf$&quot;
    }
}
}


objectCheckCommand &quot;check-win-load&quot; {
  import &quot;plugin-check-command&quot;
  command = [ PluginDir +&quot;/check_snmp_load.pl&quot; ]
  arguments = {
  &quot;-H&quot; = &quot;$address$&quot;
  &quot;-C&quot; = &quot;$snmp$&quot;
  &quot;-w&quot; = &quot;$warn$&quot;
  &quot;-c&quot; = &quot;$crit$&quot;
  &quot;-f&quot; = {
  set_if = &quot;$perf$&quot;
  }
}
}
:wq
# vi /etc/icinga2/conf.d/services.conf

applyService &quot;check_win_disk&quot; {
  import &quot;generic-service&quot;
  check_command = &quot;check-win-disk&quot;
  vars.snmp=&quot;public&quot;
  vars.disk=&quot;C:&quot;
  vars.warn=&quot;80&quot;
  vars.crit=&quot;90&quot;
  vars.perf = true
  assign where host.vars.os ==&quot;shwin&quot;
}


  apply Service &quot;check_win_load&quot; {
  import &quot;generic-service&quot;
  check_command = &quot;check-win-load&quot;
  vars.snmp=&quot;public&quot;
  vars.warn=&quot;80&quot;
  vars.crit=&quot;90&quot;
  vars.perf = true
  assign where host.vars.os == &quot;shwin&quot;
  }


  apply Service &quot;check_win_mem&quot; {
  import &quot;generic-service&quot;
  check_command = &quot;check-win-mem&quot;
  vars.snmp=&quot;public&quot;
  vars.warn=&quot;80&quot;
  vars.crit=&quot;90&quot;
  vars.perf = true
  assign where host.vars.os == &quot;shwin&quot;
  }


:wq
# vi /etc/icinga2/conf.d/shwin.conf
object Host&quot;shwin&quot; {
  import &quot;generic-host&quot;
  address = &quot;10.0.0.3&quot;
  vars.os = &quot;shwin&quot;
  vars.sla = &quot;24x7&quot;
  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”(此处可改)——确认防火墙关闭

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-457997-1-1.html 上篇帖子: Redhat 7修改httpd的默认端口 下篇帖子: Redhat 7 ntp(时间同步)客户端配置
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表