首先安裝相關依賴包.
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 openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd-devel pcre pcre-devel patch libart_lgpl libart_lgpl-devel php-gd gd* vsftpd php* mysql* httpd* //php53-common 衝突 需要 skip php53的包 使用 --skip-broken參數
建立相關用戶
useradd nagios
passwd nagios
usermod -G nagios nagios
usermod -G nagios apache
下載相應的軟件包
wget http://www.ofeio.com/soft/nagios.zip
開始安裝
tar -zxvf nagios-3.0.x.tar.gz
./configure
make all && make install && make install-init && make install-config && make install-commandmode && make install-webconf //nagios配置等安裝
nagios-plugins-1.4.X.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=nagios // 63個插件安裝
make && make install
nrpe_2.8.x.tar.gz
./configure
make all && make install-plugin && make install-daemon && make install-daemon-config //checp_nrpe 插件 nrpe daemon daemon-config配置安裝
libcgi的安裝
cd cgilib-0.5
make
cp libcgi.a /usr/local/lib
cp cgi.h /usr/include //拷貝這兩個文件,rrdtool編譯需要的
rdtool 1.2.*安裝
tar xzvf rrdtool-1.2.Xtar.gz //將rrdtool進行解壓
cd rrdtool-1.2.X //進入rrdtools目錄
./configure --prefix=/usr/local/rrdtool
make;make install //然後再編譯和安裝
安裝pnp
tar xzvf pnp-X.r.gz //將pnp進行解壓
cd pnp-X //進入pnp 目錄
./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata/ --with-perl_lib_path=
make all
make install
make install-config
...加新監控主機和相關服務
cfg_file=/usr/local/nagios/etc/objects/jiankong/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/jiankong/service.cfg
//#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 註釋掉本地的.有templates.cfg 模板引用
hosts.cfg
....
define host{
use linux-server
host_name 150
alias bieming150
address 192.168.149.150
}
...
service.cfg
...
define service{
use local-service
host_name 150
service_description Alive
check_command check-host-alive
}
define service{
use local-service
host_name 150
service_description Disk
check_command check_nrpe!check_disk
}
define service{
use local-service
host_name 150
service_description Load
check_command check_nrpe!check_load
}
define service{
use local-service
host_name 150
service_description Http
check_command check_http
}
define service{
use local-service
host_name 150
service_description Ftp
check_command check_ftp
}
..............
定義主機組
vi /usr/local/nagios/etc/objects/contacts.cfg
...
define hostgroup {
hostgroup_name room1servers
alias room1 servers
members 150
}
.....
//打開nagios 主配置文件.
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/commands.cfg //監控命令定義 #command definition
………
define command{
command_name check_local_disk //定義命令名,可以隨便起.
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ //命令行參數設置
}
……………
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg // 定義聯繫人 和 聯繫人組
……
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
…………
……
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
…………
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg // 定義主機、主機組、服務定義
……
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name localhost
alias localhost
address 127.0.0.1
}
…………
……
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members localhost ; Comma separated list of hosts that belong to this group
}
…………
……
define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
…………
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
…… // 定義全局通用主機模板,其他的主機定義可以用use引用它,比如linux windows unix 主機
define host{
name generic-host ; The name of this host template // 名稱很重要,用來引用此模板
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 1 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
notification_period 24x7 ; Send host notifications at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
…………
…… // 定義全局通用聯繫人模板,其他的聯繫人定義可以用use引用它
define contact{
name generic-contact ; The name of this contact template // 名稱很重要,用來引用此模板
service_notification_period 24x7 ; service notifications can be sent anytime
host_notification_period 24x7 ; host notifications can be sent anytime
service_notification_options w,u,c,r,f,s ; send notifications for all service states, flapping events, and scheduled downtime events
host_notification_options d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
service_notification_commands notify-service-by-email ; send service notifications via email
host_notification_commands notify-host-by-email ; send host notifications via email
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}
…………
…… // 定義全局通用服務模板,其他的服務定義可以用use引用它
define service{
name generic-service ; The 'name' of this service template // 名稱很重要,用來引用此模板
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems)
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
failure_prediction_enabled 1 ; Failure prediction is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
is_volatile 0 ; The service is not volatile
check_period 24x7 ; The service can be checked at any time of the day
max_check_attempts 3 ; Re-check the service up to 3 times in order to determine its final (hard) state
normal_check_interval 10 ; Check the service every 10 minutes under normal conditions
retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined
contact_groups admins ; Notifications get sent out to everyone in the 'admins' group
notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events
notification_interval 60 ; Re-notify about service problems every hour
notification_period 24x7 ; Notifications can be sent out at any time
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
}
…………
/usr/local/nagios/etc/objects/timeperiods.cfg // 定義監控時間段,
……
define timeperiod{
timeperiod_name 24x7 // 名稱很重要,用來引用此模板。
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
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
saturday 00:00-24:00
}
…………
4.2.1 相關設置
首先要將Nagios的主配置文件nagios.cfg中相關的配置修改:
process_performance_data=1
service_perfdata_command=process-service-perfdata #默認此句被註釋掉了
如果想要對某個監控對象做數據圖表,則需在所對應的host或者service定義中(一般寫在hosts.cfg或者services.cfg文件中),包含如下的定義:
process_perf_data 1
4.3 訪問圖表 //加小太陽
http://IP/nagios/pnp/
這樣訪問比較麻煩
在服務、主機中添加
action_url /nagios/pnp/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$ //加在generic通用的host定義裏,加在generic通用的service定義裏
一項項添加繁瑣的話,可以添加到服務、主機的模板中
這樣可用過太陽圖表直接訪問圖表了
define command {
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/nagios/libexec/process_perfdata.pl -d HOSTPERFDATA //繪圖host數據
}
define command {
command_name process-service-perfdata
command_line /usr/bin/perl /usr/local/nagios/libexec/process_perfdata.pl //繪圖service數據
}
默認nrpe.cfg 的配置
被監控端 //可自定義命令,供監控端cheap_nrpe 調用
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
...
command[check_abc]=.... //自定義命令
監控端
check_nrpe!check_users //調用被監控端默認的命令,可以修改其參數
check_nrpe!check_abc //調用被監控端自定義的命令
nagios 草稿
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
MySQL数据库集群-PXC方案
wy53780
2020-04-23 13:55:07
sql語法、關係建模
死瘦宅
2019-02-24 22:35:22
MySQL 事務、函數、觸發器、數據庫備份、權限管理
死瘦宅
2019-02-24 22:35:12
《從0到1學習Flink》—— Flink 讀取 Kafka 數據批量寫入到 MySQL
zhisheng
2019-02-24 21:04:11
SpringBoot 填坑 (一) | CentOS7.4 環境下,表時間字段默認值設置失效
一個優秀的廢人
2019-02-24 15:33:55
mysql-存儲過程
雙子城
2019-02-24 13:43:57
jmeter學習指南之操作 mysql 數據庫
小強測試
2019-02-24 13:34:06
20190222全天的實驗
清歡難尋
2019-02-24 13:17:21
數據庫監控:zabbix(fpmmm)
AMGYM
2019-02-24 13:05:14
數據庫監控:nagios(check_mysql_health)
AMGYM
2019-02-24 13:05:14
如何釋放已刪除的InnoDB磁盤空間
lvrenX
2019-02-24 13:04:33
MYSQL中視圖的使用
雙子城
2019-02-24 08:44:17
MySQL從刪庫到跑路
司木
2019-02-24 00:24:07
JavaBean操作
yi_sixian
2019-02-23 14:05:20
fdb2b技術博客簡介
fdb2b
2019-02-23 14:01:03