Nagios监控笔记上
Nagios软件介绍及服务端安装部署实战
1. Nagios服务端安装
1.1 准备3台服务器或者虚拟机器
管理IP地址 | 角色 | 备注 |
192.168.1.80 | Nagios监控服务器 | |
192.168.1.81 | Lamp服务器 | 被监控的客户端服务器 |
192.168.1.82 | Lamp服务器 | 被监控的客户端服务器 |
1.2 解决perl编译问题:
后面编译的软件有perl程序,这里要提前设置下环境变量
批量执行命令如下:
echo 'export LC_ALL=C' >> /etc/profile 去除所有本地化的设置,让命令能正确执行
tail -1 /etc/profile
source /etc/profile
echo $LC_ALL --------C表示正确
1.3 关闭nagios server 防火墙
测试环境下为了调试方便关闭防火墙
/etc/init.d/iptables stop
chkconfig iptables off
1.4 解决系统时间同步
如果不解决时间同步,会导致nagios配置异常甚至失败
crontab -e
#time sync by oldboy at 2010-2-1
*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
1.5 安装或者升级nagios所需的基础软件包
yum -y install gcc glibc glibc-common gd gd-devel httpd php php-gd
yum -y install mysql* (非必需,如果要监控mysql需要安装)
1.6 创建nagios所需的用户及组
useradd -m nagios
useradd apache
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
1.7 安装nagios软件包
tar -xf nagios-4.1.1.tar.gz
cd nagios-4.1.1
./configure --with-command-group=nagcmd
(注:如果是编译安装的httpd时,可以执行./configure --with-httpd-conf=/usr/local/apache/conf/extra增加一个编译参数即指定nagios web配置的生成路径)
make all
make install
make install-init
make install-commandmode
make install-config
1.8 安装nagios web 配置文件及创建登陆用户
make install-webconf
(注:如果通过编译安装httpd,编辑vim /usr/local/apache/conf/httpd.conf增加Include conf/extra/nagios.conf
或者mkdir -p /etc/httpd/conf && make install-webconf
cp /etc/httpd/conf.d/nagios.conf /usr/local/apache/conf/extra
vim /usr/local/apache/conf/httpd.conf增加Include conf/extra/nagios.conf
)
创建nagios web监控界面登入时需要的用户名(oldboy)及密码(redhat)
htpasswd -c /usr/local/nagios/etc/htpasswd.users oldboy
(之所以放到 /usr/local/nagios/etc/是因为这个文件中的密码是加密的)
1.9 添加监控报警的接收email地址
vim /usr/local/nagios/etc/objects/contacts.cfg +35
email nagios@localhost(改为自己的邮箱)
或者:sed -i 's#nagios@localhost#824412801@qq.com#' /usr/local/nagios/etc/objects/contacts.cfg
1.10 配置apache服务
启动apache : /etc/init.d/httpd start
1.11 安装nagios插件软件包
tar -xf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
make (如果编译遇到Error2则configure加--with-mysql=/usr/local/mysql解决)
make install
检查插件软件包的个数:
ls /usr/local/nagios/libexec/ | wc -l
1.12 配置nagios自启动
chkconfig nagios on
1.13 验证nagios配置文件(检查语法)
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
或者:/etc/init.d/nagios checkconfig
启动nagios服务
/etc/init.d/nagios start
检查nagios进程
ps -ef | grep nagios
(如果启动失败,检查selinux是否关闭)
此时打开浏览器输入ip/nagios 输入以上设置的用户名密码即可进入
1.14 安装nrpe
tar -xf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
提示:生成nrpe的配置文件/usr/local/nagios/etc/nrpe.cfg
服务端也要安装nrpe,不然会缺少相关检测配件,另外服务端也会监控自身的基本健康状态
2. Nagios客户端安装
2.1 解决perl编译问题:
后面编译的软件有perl程序,这里要提前设置下环境变量
批量执行命令如下:
echo 'export LC_ALL=C' >> /etc/profile
tail -1 /etc/profile
source /etc/profile
echo $LC_ALL --------C表示正确
2.2 关闭nagios server 防火墙
测试环境下为了调试方便关闭防火墙
/etc/init.d/iptables stop
chkconfig iptables off
2.3 解决系统时间同步
如果不解决时间同步,会导致nagios配置异常甚至失败
crontab -e
#time sync by oldboy at 2010-2-1
*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
2.4 安装nagios-plugins-2.1.1.tar.gz
useradd nagios -M -s /sbin/nologin
tar -xf nagios-plugins-2.1.1.tar.gz
cd nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules
(如果是编译安装: yum install perl-devel perl-CPAN -y
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-httpd-conf=/usr/local/apache/conf/extra --with-mysql=/application/mysql)
make
make install
检查插件软件包的个数:
ls /usr/local/nagios/libexec/ | wc -l
2.5 安装nrpe
tar -xf nrpe-2.15.tar.gz
cd nrpe-2.15
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
2.6 安装其他插件
tar -xf Params-Validate-0.91.tar.gz
cd Params-Validate-0.91
perl Makefile.PL
make
make install
----------------------------
tar -xf Class-Accessor-0.34.tar.gz
cd Class-Accessor-0.34
perl Makefile.PL
make
make install
------------------------
tar -xf Config-Tiny-2.23.gz
cd Config-Tiny-2.23
perl Makefile.PL
make && make install
-----------------------------
tar -xf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install
-----------------------------------
tar -xf Regexp-Common-2016020301.tar.gz
cd Regexp-Common-2016020301
perl Makefile.PL
make
make install
------------------------------------
yum install sysstat -y
这个命令是安装系统性能分析工具,监控系统性能时程序或脚本会调用这些工具
iostat 查看磁盘IO
2.7 配置开发的几个基础脚本插件
cp check_memory.pl /usr/local/nagios/libexec
cp check_iostat /usr/local/nagios/libexec
chmod 755 /usr/local/nagios/libexec/check_memory.pl
chmod 755 /usr/local/nagios/libexec/check_iostat
dos2unix /usr/local/nagios/libexec/check_memory.pl
dos2unix /usr/local/nagios/libexec/check_iostat
2.8 配置nrpe
cd /usr/local/nagios/etc/
vim nrpe.cfg +79
allowed_hosts=192.168.1.80 (nagios服务器的IP,配置允许哪个nagios连接)
(或者:perl -pi -e 's/allowed_hosts=127.0.0.1/allowed_hosts=192.168.1.80/g' /usr/local/nagios/etc/nrpe.cfg )
vim nrpe.cfg (291行)
#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_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
#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_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 10% -c 3%
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 7% -p /
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10
注:上面依次为对负载,内存,硬盘,虚拟内存,磁盘IO的监控,这些都是本地的服务(我们这里称之为被动监控),由nagios服务器通过nrpe插件定时去client的nrpe服务定期获取信息
启动:nagio client
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local
ps -ef|grep nagios
netstat -lnt
lsof -i tcp:5666
3. 配置server端nagios监控的服务
3.1 配置主配置文件
vim etc/nagios.cfg +34 (配置如下主机和服务的胚子文件)
#added by oldboy 20160507
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_dir=/usr/local/nagios/etc/objects/services
(作为备用增加一个service目录,使用目录的优点很多,在目录下只要符合*.cfg就可以被nagios加载,使用脚本批量部署时非常方便的随机配置命令,必须存在此目录)
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg(对本机的监控注释掉)
创建services目录mkdir /usr/local/nagios/etc/objects/services
cd /usr/local/nagios/etc/objects
生成hosts.cfg文件
head -51 localhost.cfg >hosts.cfg
对目录授权
chown -R nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg
生成services.cfg文件
touch services.cfg (暂时留空)
授权
chown -R nagios.nagios /usr/local/nagios/etc/objects/services.cfg
3.2 hosts.cfg中主机定义部分配置参数详解
define host{
use linux-server ;定义主机使用的模板
host_name Nagios-Server ; 设置主机的名字,该名字会出现在hostgroups.cfg 和services.cfg 中。注意,这个名字可以不是该服务器的主机名。
alias Nagios服务器 ; 别名
address 192.168.81.128 ; 主机的IP 地址
check_command check-host-alive ; 检查使用的命令,需要在命令定义文件定义,默认是定义好的。
check_interval 1 ; 检测的时间间隔
retry_interval 1 ; 检测失败后重试的时间间隔
max_check_attempts 3 ; 最大重试次数
check_period 24x7 ; 检测周期
process_perf_data 0
retain_nonstatus_information 0
contact_groups admins ; 报警需要通知的联系组
notification_interval 30 ; 故障后,两次报警的时间间隔,默认单位分钟
notification_period 24x7 ; 一天之内通知的周期 ,比如全天
notification_options d,u,r ; 通知的选项
#w—报警(warning),u—未知(unkown)
#c—严重(critical),r—从异常情况恢复正常
}
3.2.1 nagios 的监控模式定义及监控模式选择
按照监控的行为来看,Nagios插件的监控可以分为主动监控和被动监控
主动服务:我们把对于像URL监控这样的一般由服务端发出请求探测就可以得到数据的监控方式,定义为主动监控。当然,主动监控也可以配置成被动模式。
被动监控:我们把对负载,内存,硬盘,虚拟内存,磁盘IO等的监控,这些都是本地的资源,非系统对外提供的服务,这种资源的监控是有nagios服务器通过nrpe插件去连接client的nrpe服务定期获取信息发回服务端。这样的监控我们称为被动监控。
3.3 hosts.cfg中主机定义部分批量模板化配置
主机的配置可以只配置关键选项,多数选项课采用linux-server模板的默认值
#定义一个主机组
define host{
uselinux-server
host_name qmail #主机组名称,可以随意指定。
alias 016-qmail #主机组别名
address192.168.1.85
}
千台服务器配置
define host{
uselinux-server
host_name qmail #主机组名称,可以随意指定。
alias 016-qmail #主机组别名
address192.168.1.85
}
define host{
uselinux-server
host_name qmail #主机组名称,可以随意指定。
alias 016-qmail #主机组别名
address192.168.1.86
}
...............
3.4 services.cfg中服务定义部分参数
services.cfg文件是配置监控服务的,是nagios最重要的配置文件之一,对于服务器数量比较少(50台以内),大部分需要的监控服务配置都可以在里面添加,此文件默认不存在
vim services.cfg
define service { 意思是定义一个服务
use generic-service ;定义该服务使用的模板
host_name Nagios-Server ; 被监控的主机名,hosts.cfg 定义的主机名称
service_description check-host-alive ; 服务描述
check_command check_nrpe!check_load ;检查服务命令,这个很关键。注意被动的监控均由 check_nrpe调用 (check_load为服务端nrpe.cfg []中定义的)
check_period 24x7 ; 检测的时间段
max_check_attempts 3 ; 最大检测次数
normal_check_interval 3 ;正常状态检测间隔
retry_check_interval 2
contact_groups admins ; 发生故障通知的联系人组
notification_interval 10
notification_period 24x7 ; 通知的时间段
notification_options w,u,c,r
process_perl_data1;PNP出图相关配置
}
磁盘分区监控【被动监控】
define service {
use generic-service
host_name a,b,c,d ;这里可以指定多台机器,通过逗号隔开
service_description Disk Partition
check_command check_nrpe!check_disk
check_period 24x7
max_check_attempts 3
normal_check_interval 3
retry_check_interval 2
contact_groups mailusers ;磁盘的报警值设定的合理些,可只报邮件不报短信
notification_interval 360
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive
process_perl_data1
}
也可以定义为模板
define service {
use generic-disk-service ;这就是在templates.cfgdinginess好的模板名
host_name 072-wiki
}
对URL的监控用/usr/local/nagios/libexec/check_http 中的选项命令
服务端口的监控
define service {
use generic-service
host_name 051-ett-1-1,052-ett-2-1
service_description img_8150
check_command check_tcp!8150
check_period 24x7
max_check_attempts 3
normal_check_interval 3
retry_check_interval 2
contact_groups mailusers ;磁盘的报警值设定的合理些,可只报邮件不报短信
notification_interval 360
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive
process_perl_data1
3.5 commands.cfg生产库实战配置例子
commands.cfg这个是定义报警命令的配置文件
define contact{
contact_name maoxian ; 联系人的名字
alias maoxian ; 别名
service_notification_period 24x7 ; 服务报警的时间段
host_notification_period 24x7 ; 主机报警的时间段
service_notification_options w,u,c,r ; 就是在这四种情况下报警。
host_notification_options d,u,r ;同上。
#服务报警发消息的命令,在command.cfg 中定义。
service_notification_commands notify-service-by-email
#服务报警发消息的命令,在command.cfg 中定义。
host_notification_commands notify-host-by-email
email wangyx088@gmail.com ; 定义邮件地址,也就是接收报警邮件地址。
}
注:模板文件在/usr/local/nagios/etc/objects/templates.cfg ,可以复制模板,批量修改,便捷很多
3.6 nagios实战配置过程细节
3.6.1 监控客户端服务器磁盘分区、Load负载、Mem内存、swap、磁盘IO【被动模式】
1)首先在hosts.cfg里添加客户端主机和主机组(HOSTGROUP)
cd /usr/local/nagios/etc/objects
vim hosts.cfg
define host{
use linux-server
host_name 81-lamp-1
alias 81-lamp-1
address 192.168.1.81
}
#初学者增加上面一个HOST作为测试即可
define host{
use linux-server
host_name 82-lamp-1
alias 82-lamp-1
address 192.168.1.82
check_command check-host-alive
check_period 24x7
max_check_attempts 3
normal_check_interval 2
retry_check_interval 2
contact_groups admins
notification_interval 300
notification_period 24x7
notification_options d,u,r
process_perl_data1
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of the group
members 81-lamp-1,82-lamp-1 ; Comma separated list of hosts that belong to this group
}
2)接下来添加要监控的服务配置到services.cfg
vim services.cfg
define service {
use generic-service
host_name 81-lamp-1,82-lamp-1
service_description Current Load
check_command check_nrpe!check_load
max_check_attempts 2
normal_check_interval 4
retry_check_interval 4
check_period 24x7
notification_interval 1440
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
process_perl_data 1
}
define service {
use generic-service
host_name 81-lamp-1,82-lamp-1
service_description MEM Useage
check_command check_nrpe!check_mem
max_check_attempts 2
normal_check_interval 4
retry_check_interval 4
check_period 24x7
notification_interval 1440
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
process_perl_data 1
}
define service {
use generic-service
host_name 81-lamp-1,82-lamp-1
service_description Swap Useage
check_command check_nrpe!check_swap
max_check_attempts 2
normal_check_interval 4
retry_check_interval 4
check_period 24x7
notification_interval 480
notification_period workhours
notification_options w,u,c,r
contact_groups admins
process_perl_data 1
}
define service {
use generic-service
host_name 81-lamp-1,82-lamp-1
service_description Disk Partition
check_command check_nrpe!check_disk
max_check_attempts 8
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 360
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
process_perl_data 1
}
define service {
use generic-service
host_name 81-lamp-1,82-lamp-1
service_description Disk Iostat
check_command check_nrpe!check_iostat!5!11
max_check_attempts 2
normal_check_interval 4
retry_check_interval 4
check_period 24x7
notification_interval 1440
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
process_perl_data 1
}
3)检查配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Warning: Duplicate definition found for hostgroup 'linux-servers' (config file '/usr/local/nagios/etc/objects/localhost.cfg', starting on line 45)
Error: Could not add object property in file '/usr/local/nagios/etc/objects/localhost.cfg' on line 46.
Error processing object config files!
此错误的解决办法,将localhost.cfg中的46行的组名重改一个
hostgroup_name linux-servers1 ; The name of the hostgroup
alias Linux Servers1
Error: Service check command 'check_nrpe!check_load' specified in service 'Current Load' for host '81-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_iostat!5!11' specified in service 'Disk Iostat' for host '81-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_disk' specified in service 'Disk Partition' for host '81-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_mem' specified in service 'MEM Useage' for host '81-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_swap' specified in service 'Swap Useage' for host '81-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_load' specified in service 'Current Load' for host '82-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_iostat!5!11' specified in service 'Disk Iostat' for host '82-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_disk' specified in service 'Disk Partition' for host '82-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_mem' specified in service 'MEM Useage' for host '82-lamp-1' not defined anywhere!
Error: Service check command 'check_nrpe!check_swap' specified in service 'Swap Useage' for host '82-lamp-1' not defined anywhere!
..............................
Total Warnings: 0
Total Errors: 10
..........................
根据错误提示,我们可以知道,是check_nrpe插件没有定义导致
需要在commands.cfg中加入check_nrpe的插件配置
vim commands.cfg (在结尾添加)
#check_nrpe' command definition
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
此时再检查语法正确,全部正确
4)启动nagios
/etc/init.d/nagios start
打开浏览器访问:192.168.1.80/nagios
此时登陆进去会报如下错误:
It appears as though you do not have permission to view information for any of the hosts you requested...
If you believe this is an error, check the HTTP server authentication requirements for accessing this CGI
and check the authorization options in your CGI configuration file.
解决方法:
cd /usr/local/nagios/etc
vim cgi.cfg
将其中所有的nagiosadmin全部替换成当前的登陆用户oldboy(%s/nagiosadmin/yan/g)
/etc/init.d/nagios reload
4. 通过URL及端口方式监控客户端主机提供的服务
4.1 增加从nagios服务器端发起的监控:如url地址,端口监控
此类服务一般都是开启了对外提供业务服务。这样的业务,我们一般采取主动监控的方式
4.1.1 对域名URL地址http://www.yan.com 的监控
1)添加要监控的服务配置到services.cfg
vim etc/objects/services.cfg
define service {
use generic-service
host_name 81-lamp-1
service_description blog_url
check_command check_weburl!-H www.yan.com(81主机)
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg(检查语法)
有一个错误
Error: Service check command 'check_weburl!-H 192.168.1.80' specified in service 'blog_url' for host '81-lamp-1' not defined anywhere!
2)解决办法,需要在commands.cfg中加入check_weburl的插件配置
vim commands.cfg
#'check_weburl' command definition
define command {
command_name check_weburl
command_line $USER1$/check_http $ARG1$ -w 10 -c 30
}
3)如果是测试URL监控,注意在nagios服务端的/etc/hosts下加
192.168.1.81 www.yan.com
4.1.2 对域名URL地址http://www.yan.com/yan/test.html的监控
vim etc/objects/services.cfg
define service {
use generic-service
host_name 81-lamp-1
service_description blog_yan_url
check_command check_weburl!-H www.yan.com -u /yan/test.html
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
因为wget http://www.yan.com/yan/test.html报404错误,所以现在监控不到
需要在81主机: mkdir /var/www/html/yan
vim /var/www/html/yan/index.html
4.1.3 对特殊带传参的URL地址的监控
vim etc/objects/services.cfg
define service {
use generic-service
host_name yan_app
service_description appVIP_url
check_command check_weburl!-H www.yan.com -u “/yan/index.php?m=article&a=list&id=670”
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
4.2 监控任意端口举例如:80,110,25,8080
vim etc/objects/services.cfg
define service {
use generic-service
host_name 81-lamp-1
service_description ssh_22
check_command check_tcp!22
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
define service {
use generic-service
host_name 81-lamp-1
service_description http_80
check_command check_tcp!80
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
check_period 24x7
notification_interval 30
notification_period 24x7
notification_options w,u,c,r
contact_groups admins
}
检查语法:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg(没有错误)
(因为commands.cfg中默认已经定义了check_tcp)
重新加载配置:
/etc/init.d/nagios reload
4.3 nagios调试
4.3.1 优化配置nagios启动脚本检查nagios语法
4.3.2 通过日志排查问题
tail /usr/local/nagios/var/nagios.log
4.3.3 被动模式错误排查
NRPE: Unable to read output
1)从nagios服务端执行/usr/local/nagios/libexec/check_nrpe-H192.168.1.81 check_mem
2)从客户端本地执行命令脚本检查(就是command[check_mem]=后面对应的脚本)
/usr/local/nagios/libexec/check_memory.pl -w 10% -c 3%(这个命令最后复制nrpe.cfg里的配置,不要手巧,防止出错)
4.4 基本部署及服务监控常见问题
4.4.1 问题1.打开IE无服务,出现下面错误
It appears as though you do not have permission to view information for any services you requested......
原因:打开IE登陆的nagios用户无访问权限
解决:vi /usr/local/nagios/etc/cgi.cfg
将其中所有的nagiosadmin全部替换成当前的登陆用户oldboy(%s/nagiosadmin/yan/g)
或者:将use_authentication的值改为0.
use_authentication=0
5. nagios图形监控显示和管理【服务端】
5.1 Pnp安装图形监控曲线(服务器端)
1)yum安装pnp软件需要的基础包
yum -y install cairo pango* zlib zlib-devel freetype freetype-devel gd gd-devel
2)安装libart_lgpl-2.3.17.tar.gz
tar -xf libart_lgpl-2.3.17.tar.gz
cd libart_lgpl-2.3.17
./configure
make
make install
cp -r /usr/local/include/libart-2.0 /usr/include/
3)安装rrdtool-1.4.5.tar.gz
tar -xf rrdtool-1.4.5.tar.gz
cd rrdtool-1.4.5
./configure --prefix=/usr/local/rrdtool --disable-python --disable-tcl
configure:error:Please fix the library issues listed above and try again
解决办法:yum -y install libxml*
make && make install
ll /usr/local/rrdtool/bin/
total 500
-rwxr-xr-x. 1 root root 121433 Jun 5 23:47 rrdcached
-rwxr-xr-x. 1 root root 59970 Jun 5 23:47 rrdcgi
-rwxr-xr-x. 1 root root 61134 Jun 5 23:47 rrdtool
-rwxr-xr-x. 1 root root 264602 Jun 5 23:47 rrdupdate
4)安装pnp-0.4.13.tar.gz
tar -xf pnp-0.4.13.tar.gz
cd pnp-0.4.13
./configure --with-rrdtool=/usr/local/rrdtool/bin/rrdtool --with-perfdata-dir=/usr/local/nagios/share/perfdata
make all
make install
make install-config
make install-init
PNP提供了一个perl脚本,可以用如下命令查到
ll /usr/local/nagios/libexec/ | grep process
-rwxr-xr-x. 1 nagios nagios 30151 Jun 6 00:19 process_perfdata.pl
5.2 nagios出图相关基本配置
1)vim /usr/local/nagios/etc/nagios.cfg +835
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
2)vim /usr/local/nagios/etc/objects/commands.cfg +227
删除227-238,添加:
# 'process-host-perfdata' command definition
define command{
command_name process-host-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
# 'process-service-perfdata' command definition
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}
(注:也可以用nagios变量$USER1$替代/usr/local/nagios/libexec/路径)
3)检查语法
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4)重新加载nagios
/etc/init.d/nagios reload
5)浏览器输入192.168.1.80/nagios/pnp/index.php
出现这种情况,刷新几下就好
5.3 配置各个服务出监控状态图
1)服务出图记录数据设置
执行编辑命令vim services.cfg,在各个服务里加process_perf_data 1
2)主机出图配置
执行编辑命令hosts.cfg,在各个服务里加process_perf_data 1
3)整合pnp url超链接到nagios图形显示界面里
提示:这会在主机或对应服务前面,出现一个红太阳图标,点击就是对应的服务图形监控状态
5.3.2 给主机添加红太阳超链接图标
方法一:
vim /usr/local/nagios/etc/objects/hosts.cfg 添加如下配置
#grapbic for hosts create by yan!
define hostextinfo {
host_name 81-lamp-1
action_url /nagios/php/index.php?host=$HOSTNAME$
}
方法二:
vim /usr/local/nagios/etc/objects/hosts.cfg 各个服务中添加如下
action_url /nagios/php/index.php?host=$HOSTNAME$
5.3.3 给指定服务添加红太阳超链接图标
方法一:
vim /usr/local/nagios/etc/objects/services.cfg 结尾添加
#go sun link logo by yan
define serviceextinfo {
host_name 81-lamp-1
service_description Swap Useage
active_url /nagios/php/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}
#go sun link logo by yan
define serviceextinfo {
host_name 81-lamp-1
service_description http_80
active_url /nagios/php/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}
方法二:
vim /usr/local/nagios/etc/objects/services.cfg 各个服务中添加如下
action_url/nagios/php/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
5.3.4 出图的图像数据存放路径
ll /usr/local/nagios/share/perfdata/
6. Nagios报警方式及生产报警策略
6.1 报警的种类及报警方式使用
6.1.1 报警的种类
1)邮件报警,生产环境尽量使用公司的信箱作为报警邮箱
2)飞信:首先在win32上装个飞信客户端,把对方手机加为好友,然后就可以给对方发短信了
3)邮件转短信报警,如139、126、189信箱:信箱邮件到达后,通过手机通知收件人是邮箱提供商提供的一个功能
4)http短信网关
5)购买短信猫,类似手机终端一样的客户端硬件设备,实现报警,早期报警选用的一个方式
6)电话语音报警,在报警时直接电话给报警负责人
7)MSN,QQ及时通讯报警,模拟QQ,MSN发消息的功能,网友开发了程序,从命令行执行程序利用MSN,QQ协议,直接发给MSN和QQ好友
6.1.2 邮件报警的基本配置方法
vim /usr/local/nagios/etc/objects/contacts.cfg +35
email 824412801@qq.com
默认的报警配置在command.cfg里
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition
define command{
command_name notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" $CONTACTEMAIL$
}
templates.cfg中有关邮件报警的联系人模板配置【默认已经配置,如果配置飞信、MSN等要追加】
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!
}
6.1.3 邮件转短信报警(139邮箱为例)
配置方法和和邮件报警一样,只不过在注册信箱后要开启邮箱邮件到达短信提醒功能(设置白名单)。邮件转短信报警的稳定性一般,且信息的容量有很大限制。因此,建议作为辅助报警方式。
6.1.4 联系人分级报警生产策略
vim contacts.cfg
#手机短信用户
define contact{
contact_name shouji_wo
use generic-contact
alias Nagios Admin
email 18306847338@139.com
}
define contact{
contact_name shouji_ni
use generic-contact
alias Nagios Admin
email 18306847338@139.com
}
#邮件及MSN账号
define contact{
contact_name shouji_yan
use generic-contact
alias Nagios Admin
email 824412801@qq.com
address1ryran@hotmail.com
}
define contact{
contact_name shouji_yu
use generic-contact
alias Nagios Admin
email pynznzyjy@163.com
address1ryran@hotmail.com
}
#手机组
define contactgroup{
contactgroup_name shoujiusers
alias Nagios Administrators
members shouji_wo,shouji_ni
}
#邮件msn账号组
define contactgroup{
contactgroup_name msnusers
alias Nagios Administrators
members msn_yan,msn_yu
}
6.1.5 vim services.cfg (各个服务需要报哪些组)
例如:
define service {
use generic-service
host_name 81-lamp-1,82-lamp-1
service_description Disk Partition
check_command check_nrpe!check_disk
max_check_attempts 8
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 360
notification_period 24x7
notification_options w,u,c,r
contact_groups admins,shoujiusers
process_perf_data 1
action_url /nagios/php/index.php?host=$HOSTNAME$&srv=$SERVICEDESC$
}
6.2 手机短信报警
6.2.1 飞信软件报警
飞信报警的实现原理是:首先在个人电脑上(非报警服务器)装个飞信客户端,然后注册一个用于报警的发送人账号,需要绑定手机,然后登陆飞信客户端,把需要接收报警的所有手机加为好友(需要对方确认),然后就可以使用发送人账号给对方发短信了服务器报警使用其命令行模式的发送方式
飞信机器人下载地址:http://www.it-adv.net/
1)解压fetion到/usr/local下面
tar -xf fetion.tar.gz -C /usr/local/
2)把飞信的lib库和系统的/usr/lib/做一个软连接
ln -s /usr/local/fetion/cenos54X64_20101113/lib/lib* /usr/lib
3)下面介绍飞信命令的一些选项【必须熟悉】
--mobile=[mobile] 这里是登陆的选项,使用手机号码登陆。 --sid=[sid] 这里是使用用户名登陆、
--pwd=[pwd] 这里是登陆的密码。
--config=[config file] *format:index mobile password
--index=[index no in config file,refer to sample.conf]
--debug *debug mode on --hide *login fetion in hidden state --to=[mobile/sid] 这个是接收人的手机号码 或者飞信用户名。
--command-path=[command file path]
--robotmode
--daemon(linux only) --proxy-ip(http proxy ip)
--proxy-port(http proxy port)
--msg-gb=[gb2312/gbk message]
--msg-utf8=[utf8 message] 这个是短信的内容,以UTF8格式
--msg-type=[0/1/2 sms longsms smartmsg]
--file-gb=[gb2312/gbk file]
--file-utf8=[utf8 file]
--query-cmcc-no
--auto-retry
--exit-on-verifycode
4)开始执行fetion测试命令:
特别注意:在执行下面的发送信息命令时会返回一堆信息,然后命令处于等待用户输入验证码阶段
./fetion --mobile=18306847338 --pwd=yan5714076 --to=18306847338 --msg-type=1 --msg-utf8="fetion test"
验证码在/usr/local/fetion/ 重开一个窗口,下载验证码图片
5)配置nagios通过飞信报警格式
a:修改command.cfg
cd /usr/local/nagios/etc/objects
vim commands.cfg +37 (添加以下内容)
# 'notify-host-by-fetion' command definition
define command{
command_name notify-host-by-fetion
command_line ./fetion --mobile=18306847338 --pwd=yan5714076 --to=18306847338 --msg-type=1 --msg-utf8="** $NOTIFICATIONTYPES$ Host Alert: $HOSTNAMES$ is $HOSTSTATE$ **"
}
# 'notify-service-by-fetion' command definition
define command{
command_name notify-service-by-fetion
command_line ./fetion --mobile=18306847338 --pwd=yan5714076 --to=18306847338 --msg-type=1 --msg-utf8="**$NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$ **"
}
b:修改templates.cfg
vim templates.cfg +34
service_notification_commands notify-service-by-email,notify-service-by-fetion
host_notification_commands notify-host-by-email,notify-host-by-fetion
转载于:https://blog.51cto.com/yjy724/1842177
相关文章:
liunx查看python的site-packages路径
有时候我们在liunx上想修改查看python的包路径可以试试以下命令 from distutils.sysconfig import get_python_lib print(get_python_lib()) 如图:

【ACM】杭电OJ 2010
注意格式!!!注意格式!!! 空格的设置 \n的设置 #include <stdio.h> int main () {int i,m,n,g,s,b,flag;while(scanf("%d%d",&m,&n)!EOF){flag0;for(im;i<n;i){gi%10;bi/100…

中科院 工程硕士专业课 复试考试前的辅导安排
同学们大家好:学校定于12月6日、7日组织专业课辅导,1月初进行专业课复试及资格审查。辅导具体日程安排如下:12月6日下午13:00 数据结构(报考软件工程、计算机技术领域考生) 人文楼教一阶12月7日上午9:00 信号与系统…
TCP性能和发送接收Buffer的关系
本文希望解析清楚,当我们在代码中写下 socket.setSendBufferSize 和 sysctl 看到的rmem/wmem系统参数以及最终我们在TCP常常谈到的接收发送窗口的关系,以及他们怎样影响TCP传输的性能。 先明确一下:文章标题中所说的Buffer指的是sysctl中的 …

PHP 异常类 Exception 高洛峰 细说PHP
/** 1.自定义的异常类,必须是系统类Exception的子类* 如果继承Exception类,重写了构造方法,一定要调用一下父类的构造方法。*/class MyException extends Exception{//必须继承Exception类function __construct($mess){parent::__construct($mess);}func…
【ACM】杭电OJ 2023
注意最后又两个\n #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn 1000; int a[maxn][maxn]; double grade[maxn]; double average[maxn]; int main () {int m,n,i,j,flag,count;//n个学生,m门…

Hadoop学习笔记—7.计数器与自定义计数器
一、Hadoop中的计数器 计数器:计数器是用来记录job的执行进度和状态的。它的作用可以理解为日志。我们通常可以在程序的某个位置插入计数器,用来记录数据或者进度的变化情况,它比日志更便利进行分析。 例如,我们有一个文件&#x…
win10安装spacemacs
1、下载emacs最新版 26.1 2、解压emacs到你的安装目录,我的系统是D:/Program File/。执行/bin目录下的addpm.exe 这一步会在开始菜单创建快捷方式 3、在系统环境变量中添加新项HOME(具体环境变量设置方式请自行google),该变量的路径决定了emacs启动时.emacs.d目录…

【ACM】杭电OJ 2024
注意: 1、getchar() 2、scanf和gets的区别 3、判断条件 C语言的合法标识符 1、由字母,数字,下划线组成 2、且首字符不能是数字 #include <iostream> #include <cstdio> #include <cstring> using namespace std; in…

王振的开发板_Android
任务一: 任务内容:主界面框架的搭建 发布时间:2016-8-26 已完成 任务二: 任务内容:我的 主界面的开发 发布时间:2016-8-27 已完成 任务三: 任务内容:发布界面 动画开发 发布时间&a…

JAX-RS(基于Jersey) + Spring 4.x + MyBatis构建REST服务架构
0. 大背景 众所周知,REST架构已经成为现代服务端的趋势。 很多公司,已经采用REST作为App, H5以及其它客户端的服务端架构。 1. 什么是JAX-RS? JAX-RS是JAVA EE6 引入的一个新技术。 JAX-RS即Java API for RESTful Web Services,是一个Java 编…

c语言宏嵌套和展开规则
基本原则: 在展开当前宏函数时,如果形参有#或##则不进行宏参数的展开,否则先展开宏参数,再展开当前宏。 #是在定义两边加上双引号 #define _TOSTR(s) #sprintf(_TOSTR(test ABC)) printf(_TOSTR("test ABC")); print…

【ACM】杭电OJ 2027
注意输出格式!!!! #include <iostream> #include <cstdio> #include <cstring> using namespace std; const int maxn 10000; char s1[maxn]; int main () {int n,j,i,a,e,o,u;scanf("%d",&n)…

搜索引擎广告过滤Chrome插件
搜索广告屏蔽Chrome插件:自动过滤:百度,360,搜狗,google,bing的搜索广告,让魏则西的悲剧不再重演。珍爱生命,远离搜索广告!下载:FuckAd.zip 安装:方法自行百度…

Scala程序设计:Java虚拟机多核编程实战(国内第一本Scala图书)
Scala程序设计:Java虚拟机多核编程实战(国内第一本Scala图书) 基本信息 作者: (美)Venkat Subramaniam 译者: 郑晔 李剑 丛书名: 图灵程序设计丛书 出版社:人民邮电出版社 ISBN:9787115232953 上架时间&am…

emacs快捷键
https://blog.wozouwokan.com/%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91/2015/07/14/spacemacs/ 超全开发快捷键:https://edward852.github.io/post/%E9%80%9A%E7%94%A8%E4%BB%A3%E7%A0%81%E7%BC%96%E8%BE%91%E5%99%A8spacemacs/ spc f T快速定位当前文件在neotree中的…

python 小程序,输错三次密码锁定账户
1 [rootsun ~]# cat 7.py 2 #!/usr/bin/python3 # -*- codingUTF-8 -*-4 5 usera_name usera6 usera_passwd aresu7 usera_status on8 userb_name userb9 userb_passwd bresu 10 userb_status on 11 ng 0 12 13 14 name raw_input(请输入用户名:) 15 …
【数据结构】图的深度优先遍历 广度优先遍历
文件操作比直接输入方便许多 #include <stdio.h> #include <stdlib.h> #include <string.h> #define M 20/*邻接表的储存结构*/ typedef struct node /*表结点 或者 边表结点*/ {int adjvex;struct node *next; }edgenode;typedef struct vnode /*头结点*/ …

C++ Primer(第4版)(评注版)
《C Primer(第4版)(评注版)》基本信息原书名: C Primer (4th Edition) 原出版社: Addison-Wesley Professional; 4 edition 作者: (美)Stanley B.Lippman Josee Lajoie Barbara E.Moo 译者: 陈硕 丛书名: 传世经典书丛…

win10安装emacs+spacemacs,建议用官方安装方式
1、下载emacs最新版 26.1 官网下载地址:https://www.gnu.org/software/emacs/download.html#nonfree 2、解压emacs到你的安装目录,我的系统是D:/Program File/。执行/bin目录下的addpm.exe 这一步会在开始菜单创建快捷方式 3、在系统环境变量中添加新项HOME(具体环…
【ACM】杭电OJ 2028
int 会 WA ,注意使用 long long 先除后乘,避免超出范围,但好像本题先乘后除也AC #include <iostream> #include <cstdio> #include <cstring>long long lcm(long long a,long long b) {long long c,t,ma,nb;if(a<b) {…

IIS8 添加配置 WCF服务
今天在Windows8.1 操作系统部署了半天的WCF 一直老是在报错、在这里做个记录 防止下次忘记 在网上查了半天。终于知道原来IIS8不支持WCF服务SVC的请求。所以必须要给IIS8添加WCF服务 的Managed Handler。 添加步骤: 1打开IIS&a…

spacemacs各种问题修复方法
快捷键操作时报 tr不是内部命令 ------说明是缺少tr命令,win10可以安装coreutils for gnuwin32工具集,然后把bin目录加到系统path路径即可 没有ispell, flycheck error ------缺少ispell命令,windows下面用aspell替换,需要安装…
2016/08/27 What I Learned About Going Fast at eBay and Google
每天推荐一个英文视频 http://v.qq.com/page/i/2/d/i0...https://www.youtube.com/watch... 本日看点

【ACM】杭电OJ 2030
注意getchar()的使用,以及汉字占两个字节,因为比较特殊,可以单独记忆 #include <iostream> #include <cstdio> #include <cstring> int main () {char c;int n,i,sum;scanf("%d",&n);getchar();while(n--)…

背景图自适应屏幕居中显示,且不变形
html:<div classitem><div class container /> </div> css:.item {width: 100%;height: 100%;.container {max-width: 100%;height: auto;min-height: 600px; // 这里可监听屏幕变化,改变最小高度position: absolute;left: 50%;top:…

emacs按键绑定详解
key-binding: https://crazylxr.github.io/spacemacas-zh_CH-doc/binding-keys.html 概述:Emacs的键绑定方式看起来花样繁多,其本质上都是同一个机制 (define-key keymap key def) 这里的key是你要绑定的键。keymap是这个key所属的集合,不…

【面试】重建二叉树
一、描述 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树,假设输入的前序遍历和中序遍历的结果中都不含重复的数字,例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6},则重建出该二叉树。二叉树结…

【ACM】杭电OJ 2034
开了三个数组 #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <set> #include <algorithm> using namespace std; const int maxn 105; int a[maxn],b[maxn],c[maxn];…

Android 依赖库发布(上传 Library 到 JCenter)gradle最高支持4.4
1.注册 Bintray 注册时要注意哦,千万不要注册成组织的账户,一定要注册为个人。因为组织账户只有一个月的免费使用时间。 个人账户注册地址:bintray.com/signup/oss 有Github、Google、Twitter账号的可以直接登录哦 2.创建Maven仓库࿰…