Board logo

标题: Oracle Linux6.9安装Nagios [打印本页]

作者: admin    时间: 2020-1-12 09:09     标题: Oracle Linux6.9安装Nagios

笺注:这是在 Oracle Linux6.9安装Cacti 的基础上进行的 Nagios相关软件的下载链接:https://pan.baidu.com/s/1XjVm5A5XUpqojGAXUm_uEA 提取码:a5wp 安装相关软件依赖包: [root@oracle-linux6 ~]# yum -y install unzip openssl-devel 创建Nagios的用户、组和相关目录: adduser -s /sbin/nologin nagios mkdir /usr/local/nagios chown nagios.nagios /usr/local/nagios/ 安装Nagios: tar -zxvf nagios-4.1.1.tar.gz cd nagios-4.1.1 ./configure --prefix=/usr/local/nagios/ --with-gd-lib=/usr/lib --with-gd-inc=/usr/include/ make all make install make install-init make install-config make install-commandmode make install-config 安装nagios-plugins: tar -zxvf nagios-plugins-2.1.1.tar.gz cd nagios-plugins-2.1.1 ./configure --prefix=/usr/local/nagios/ make make install 启动Nagios: [root@oracle-linux6 ~]# service nagios start Starting nagios: done. 开机自动启动Nagios: [root@oracle-linux6 ~]# chkconfig --level 35 nagios on 检测Nagios是否在运行中: [root@oracle-linux6 ~]# ps aux |grep nagios |grep -v grep nagios 24545 0.0 0.3 20648 3072 ? Ss 06:25 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg nagios 24547 0.0 0.0 9428 668 ? S 06:25 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh nagios 24548 0.0 0.2 10080 2152 ? S 06:25 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh nagios 24549 0.0 0.2 10080 2224 ? S 06:25 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh nagios 24550 0.0 0.2 10080 2124 ? S 06:25 0:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh nagios 24551 0.0 0.0 20196 448 ? S 06:25 0:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg [root@oracle-linux6 ~]# echo $? 0 安装NRPE: tar -zxvf nrpe-3.2.1.tar.gz cd nrpe-3.2.1 ./configure --prefix=/usr/local/nagios/ make all make install 给NRPE创建配置文件: [root@oracle-linux6 ~]# find / -name 'nrpe.cfg' /root/nrpe-3.2.1/sample-config/nrpe.cfg [root@oracle-linux6 ~]# cp /root/nrpe-3.2.1/sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg 启动NRPE: /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 设置开机自动启动NRPE: echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local 查看本机NRPE的版本: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/./check_nrpe -H 127.0.0.1 NRPE v3.2.1 Web页面登录Nagios时的用户名和密码:(文件、用户名、密码都是自定义的) [root@oracle-linux6 ~]# find / -name "htpasswd" /usr/bin/htpasswd [root@oracle-linux6 ~]# /usr/bin/htpasswd -bc /usr/local/nagios/etc/my_passwd zhuohua 888 Adding password for user zhuohua 备注:以上命令也可以用于修改用户名、密码。 查看密码文件的内容: [root@oracle-linux6 ~]# cat /usr/local/nagios/etc/my_passwd zhuohua:6GsriaRE6Hsks 注释:密码是经过加密的。 修改Apache的主配置文件: [root@oracle-linux6 ~]# find / -name "httpd.conf" /etc/httpd/conf/httpd.conf /root/nagios-4.1.1/sample-config/httpd.conf [root@oracle-linux6 ~]# vi /etc/httpd/conf/httpd.conf 在文件的最后追加Nagios的代码: ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/my_passwd Require valid-user Alias /nagios /usr/local/nagios/share Options None AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/my_passwd Require valid-user 备注: Nagios的应用程序文件的存放目录 /usr/local/nagios/share 重启Apache: [root@oracle-linux6 ~]# service httpd restart 停止 httpd:[确定] 正在启动 httpd:[确定] 网页登录Nagios: http://192.168.168.135/nagios/ 图片1.png Nagios的主界面: 图片2.png 查看主机: 图片3.png 图片5.png 报错信息: 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. 解决方法: [root@oracle-linux6 ~]# sed -i 's/use_authentication=1/use_authentication=0/g' /usr/local/nagios/etc/cgi.cfg 接着刷新网页即可。 默认就监控本机(localhost): 图片6.png 本机(localhost)的服务中默认就有一个WARNING: HTTP WARNING: HTTP/1.1 403 Forbidden - 3737 bytes in 0.002 second response time 图片7.png 解决方法: [root@oracle-linux6 ~]# touch /var/www/html/index.html [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# service nagios restart Running configuration check... Stopping nagios:. done. Starting nagios: done. 命令行测试本机的HTTP服务: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_http -I 127.0.0.1 HTTP OK: HTTP/1.1 200 OK - 266 bytes in 0.001 second response time |time=0.000560s;;;0.000000 size=266B;;;0 现在都正常了: 图片8.png Nagios服务器的Linux主机文件(localhost.cfg): [root@oracle-linux6 ~]# cat /usr/local/nagios/etc/objects/localhost.cfg |grep -v "^#" |grep -v "^$" 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% } define service{ use local-service ; Name of service template to use host_name localhost service_description Root Partition check_command check_local_disk!20%!10%!/ } define service{ use local-service ; Name of service template to use host_name localhost service_description Current Users check_command check_local_users!20!50 } define service{ use local-service ; Name of service template to use host_name localhost service_description Total Processes check_command check_local_procs!250!400!RSZDT } define service{ use local-service ; Name of service template to use host_name localhost service_description Current Load check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0 } define service{ use local-service ; Name of service template to use host_name localhost service_description Swap Usage check_command check_local_swap!20!10 } define service{ use local-service ; Name of service template to use host_name localhost service_description SSH check_command check_ssh notifications_enabled 0 } define service{ use local-service ; Name of service template to use host_name localhost service_description HTTP check_command check_http notifications_enabled 0 } 备注:不同主机用主机名(host_name)进行区分,服务是跟主机名的。 也可以用命令行测试远程主机的HTTP服务: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_http -I www.baidu.com HTTP OK: HTTP/1.0 200 OK - 286558 bytes in 3.510 second response time |time=3.509989s;;;0.000000 size=286558B;;;0 命令行测试本机的TCP 端口: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_tcp -H 127.0.0.1 -p 80 TCP OK - 0.000 second response time on 127.0.0.1 port 80|time=0.000208s;;;0.000000;10.000000 命令行测试远程主机的TCP端口: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_tcp -H www.baidu.com -p 80 TCP OK - 0.019 second response time on www.baidu.com port 80|time=0.019031s;;;0.000000;10.000000 [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# echo $? 0 注释:TCP端口能通时,返回值为0 [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_tcp -H www.baidu.com -p 888 CRITICAL - Socket timeout after 10 seconds [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# echo $? 2 注释:TCP端口不能通时,返回值为非0 命令行测试远程主机的NTP服务:( 远程主机必须要在防火墙开启UDP 123端口 ) [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_ntp -H 192.168.168.130 NTP OK: Offset unknown| [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# echo $? 0 注释:UDP 123端口能通时,返回值为0 [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_ntp -H 192.168.168.130 CRITICAL: No response from NTP server [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# echo $? 2 注释:UDP 123不能通时,返回值为非0 命令行测试远程主机是否能PING通: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_icmp -H 192.168.168.130 OK - 192.168.168.130: rta 0.403ms, lost 0%|rta=0.403ms;200.000;500.000;0; pl=0%;40;80;; rtmax=0.497ms;;;; rtmin=0.322ms;;;; [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# echo $? 0 注释:能通时,返回值为0;不能通时,返回值为非0 可以不显示输出结果: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_icmp -H 192.168.168.130 > /dev/null [root@oracle-linux6 ~]# [root@oracle-linux6 ~]# echo $? 0 可以自定义输出结果: [root@oracle-linux6 ~]# /usr/local/nagios/libexec/check_icmp -H 192.168.168.130 > /dev/null && echo 'yes' yes ###### 查看Nagios的告警历史记录: 图片1.png 图片2.png 相关文章: Nagios设置告警邮件 CentOS8_lnmp1.7_LAMP_安装Nagios CentOS8_在Docker中安装Nagios

图片附件: 图片1.png (2020-8-31 20:02, 22.86 KB) / 下载次数 176
http://blog.zhuohua.store/attachment.php?aid=10795&k=28bb55b5c92aba24edaa4fbf9e5055aa&t=1714637805&sid=mm4520



图片附件: 图片2.png (2020-8-31 20:02, 66.99 KB) / 下载次数 177
http://blog.zhuohua.store/attachment.php?aid=10796&k=04448fefc68d897512b1b9fd4514a9ea&t=1714637805&sid=mm4520



图片附件: 图片3.png (2020-8-31 20:03, 18.83 KB) / 下载次数 205
http://blog.zhuohua.store/attachment.php?aid=10797&k=9c1fb7c839e2b3e213dcea2deca4b6e7&t=1714637805&sid=mm4520



图片附件: 图片5.png (2020-8-31 20:03, 62.55 KB) / 下载次数 197
http://blog.zhuohua.store/attachment.php?aid=10798&k=7899a85a4f3294404bc51a67fde5d999&t=1714637805&sid=mm4520



图片附件: 图片6.png (2020-8-31 20:04, 47.69 KB) / 下载次数 190
http://blog.zhuohua.store/attachment.php?aid=10799&k=2178a4030523b50144b90764d3d96e4c&t=1714637805&sid=mm4520



图片附件: 图片7.png (2020-8-31 20:04, 66 KB) / 下载次数 207
http://blog.zhuohua.store/attachment.php?aid=10800&k=459dd47ef1ee91d9e5abf1cea68beadc&t=1714637805&sid=mm4520



图片附件: 图片8.png (2020-8-31 20:05, 75.68 KB) / 下载次数 180
http://blog.zhuohua.store/attachment.php?aid=10801&k=9eb032f65363622ef139d4fabe353b37&t=1714637805&sid=mm4520



图片附件: 图片1.png (2021-8-28 14:35, 9.07 KB) / 下载次数 146
http://blog.zhuohua.store/attachment.php?aid=18809&k=37228b068fe7210c5f3dfa4ef397442a&t=1714637805&sid=mm4520



图片附件: 图片2.png (2021-8-28 14:35, 90.34 KB) / 下载次数 126
http://blog.zhuohua.store/attachment.php?aid=18810&k=0e85808487b269d79ba771cb2afa34d5&t=1714637805&sid=mm4520






欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) Powered by Discuz! 7.2