您好,登錄后才能下訂單哦!
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 (如果報依賴不想處理的話加--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為單位,KMB為1000MB(1GB),MMB為1000000MB(即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是否正常,不能正常顯示的話就看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"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”(此處可改)——確認防火墻關閉
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。