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

Nagios监控安装之二

[复制链接]

尚未签到

发表于 2019-1-12 11:27:38 | 显示全部楼层 |阅读模式
监控80端口 3306端口 passwd文件变化
  实验说明 :环境就是一台主机Linux  CentOS release 6.5 (Final) 192.168.0.22 开启httpd 80端口 3306端口
  一,开始安装前准备:
1,安装nagios服务端软件
a,nagios-3.5.1.tar.gz
b,nagios-plugins-1.4.16.tar.gz
c,nrpe-2.12.tar.gz
2,配置环境变量:

[root@Nagios-Server ]# echo 'export LC_ALL=C'>>/etc/profile
[root@Nagios-Server ]# tail -1 /etc/profile
export LC_ALL=C
[root@Nagios-Server ]# source /etc/profile
  3,关闭防火墙和selinux

[root@Nagios-Server ]# /etc/init.d/iptables stop
[root@Nagios-Server ]# /etc/init.d/iptables status
iptables: Firewall is not running.
[root@Nagios-Server ]# chkconfig iptables off
[root@Nagios-Server ]# chkconfig --list iptables
iptables        0:off   1:off   2:off   3:off   4:off   5:off   6:off
[root@Nagios-Server]#sed –i ‘s/SELINUX=enforce/SELINUX=disabled/g’ /etc/sysconfig/selinux
  4,解决系统时间同步问题

[root@Nagios-Server ~]# yum -y install ntpdate
[root@Nagios-Server ~]# crontab -e         
#time sync by tony at 2018-01-29
*/5 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1
  二、正式安装Ngios
需要一个LAMP环境

[root@Nagios-Server ~]# yum -y install gcc glibc glibc-common
[root@Nagios-Server ~]# yum -y install gd gd-devel
[root@Nagios-Server ~]# yum -y install mysql-server
[root@Nagios-Server ~]# yum -y install httpd php php-gd
  创建Nagios服务器端需要的用户及组

[root@Nagios-Server ~]# /usr/sbin/useradd nagios
[root@Nagios-Server ~]# /usr/sbin/useradd apache -M -s /sbin/nologin
[root@Nagios-Server ~]# /usr/sbin/groupadd nagcmd
[root@Nagios-Server ~]# /usr/sbin/usermod -a -G nagcmd nagios
[root@Nagios-Server ~]# /usr/sbin/usermod -a -G nagcmd apache
  检查用户创建是否成功

[root@Nagios-Server ~]# id -n -G nagios
[root@Nagios-Server ~]# id -n -G apache
[root@Nagios-Server ~]# groups nagios
[root@Nagios-Server ~]# groups apache
  启动服务查看通讯端口

[root@Nagios-Server ~]# /etc/init.d/httpd start
[root@Nagios-Server ~]# lsof -i:80
[root@Nagios-Server ~]# /etc/init.d/mysqld start
[root@Nagios-Server ~]# lsof -i:3306
  配置hosts文件解析 :

[root@Nagios-Server ~]# cat /etc/hosts   
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.22   Nagios-Server
  三、安装Nagios-Server服务端

[root@Nagios-Server ~]# cd /soft/nagios
[root@Nagios-Server nagios]# tar xf nagios-3.5.1.tar.gz
[root@Nagios-Server nagios]# cd nagios
[root@Nagios-Server nagios]# ./configure --with-command-group=nagcmd
[root@Nagios-Server nagios]# make all
[root@Nagios-Server nagios]# make install
[root@Nagios-Server nagios]# make install-init
[root@Nagios-Server nagios]# make install-commandmode
  创建NagiosWeb监控界面后,登录时会需要输入用户名及密码,这里分别为tony和hwg123

[root@Nagios-Server nagios]# htpasswd -bc /usr/local/nagios/etc/htpasswd.users tony hwg123
[root@Nagios-Server nagios]# cat /usr/local/nagios/etc/htpasswd.users
tony:fr58UrsZgK.Tc
  查看一下授权文件

[root@Nagios-Server nagios]# grep AuthUserFile /etc/httpd/conf.d/nagios.conf
  重载一下httpd服务

[root@Nagios-Server nagios]# /etc/init.d/httpd reload
  修改联系人邮箱:

[root@Nagios-Server ~]# cd  /usr/local/nagios/etc/objects/
[root@Nagios-Server objects]# vim contacts.cfg
修改35行:
email                           2077489243@qq.com
[root@Nagios-Server objects]# /etc/init.d/postfix start
[root@Nagios-Server objects]# lsof -i:25
[root@Nagios-Server objects]# chkconfig postfix on
[root@Nagios-Server objects]# chkconfig --list postfix
  在浏览器上输入http://IP/nagios ,然后输入tony,hwg123
进入web浏览器界面配置
安装Nagios-server服务器端插件包:

[root@Nagios-Server objects]# yum -y install perl-devel openssl-devel
[root@Nagios-Server objects]# cd /soft/nagios/
[root@Nagios-Server nagios]# tar xf nagios-plugins-1.4.16.tar.gz
[root@Nagios-Server nagios]# cd nagios-plugins-1.4.16
[root@Nagios-Server nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql  
[root@Nagios-Server nagios-plugins-1.4.16]# make
[root@Nagios-Server nagios-plugins-1.4.16]# make install   
[root@Nagios-Server nagios-plugins-1.4.16]# ls /usr/local/nagios/libexec/ |wc -l
  安装NRPE插件:

[root@Nagios-Server ]# cd /soft/nagios/
[root@Nagios-Server ]# tar xf nrpe-2.12.tar.gz
[root@Nagios-Server ]# cd  nrpe-2.12
[root@Nagios-Server nrpe-2.12]# ./configure
[root@Nagios-Server nrpe-2.12]# make all
[root@Nagios-Server nrpe-2.12]# make install-plugin
[root@Nagios-Server nrpe-2.12]# make install-daemon
[root@Nagios-Server nrpe-2.12]# make install-daemon-config
[root@Nagios-Server libexec]# ls /usr/local/nagios/libexec/ |wc -l
[root@Nagios-Server libexec]# chkconfig nagios on
[root@Nagios-Server libexec]# chkconfig --list nagios
[root@Nagios-Server libexec]# echo "/etc/init.d/nagios start">>/etc/rc.local
[root@Nagios-Server libexec]# tail -1 /etc/rc.local
[root@Nagios-Server libexec]# /etc/init.d/nagios checkconfig
[root@Nagios-Server libexec]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@Nagios-Server libexec]# /etc/init.d/nagios checkconfig
  四、配置服务(我此处就是本机监控自己)

[root@Nagios-Server etc]# vim nagios.cfg +32
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
添加cfg_file=/usr/local/nagios/etc/objects/hosts.cfg和cfg_file=/usr/local/nagios/etc/objects/services.cfg
注释该行cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
[root@centos6 Nagios-Server]# cat  /usr/local/nagios/etc/objects/hosts.cfg
define host{
use                     linux-server
host_name         22-Nagios-Server
alias                   22-Nagios
address             192.168.0.22
}
define hostgroup{
hostgroup_name   linux-servers
alias                      Linux Servers
members              22-Nagios-Server
}
[root@centos6 Nagios-Server]# cat /usr/local/nagios/etc/objects/services.cfg
define service{
use                                          generic-service
host_name                              22-Nagios-Server
service_description                 HTTP
check_command                     check_http
notifications_enabled              0
}
define service{
use                                       generic-service
host_name                           22-Nagios-Server
service_description              bolg_port_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
}
define service{
use                                       generic-service
host_name                           22-Nagios-Server
service_description              bolg_port_3306
check_command                 check_tcp!3306
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                         22-Nagios-Server
service_description            Passwd
check_command                check_passwd
notifications_enabled         0
}   
[root@centos6 Nagios-Server]# cat  /usr/local/nagios/etc/objects/ commands.cfg
#'check_passwd 'command definintion
define command{
command_name     check_passwd
command_line        $USER1$/check_passwd -H $HOSTADDRESS$ -c $ARG1$
}
[root@centos6 Nagios-Server]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@centos6 Nagios-Server]#/etc/init.d/nagios reload
  具体操作是这样先添加主机、再添加服务、然后添加命令;检查配置最后重载Nagios服务。
  备注:可能会出现的故障(有些是关于NRPE错误)
1,登录web界面的时候提示错误:
解决:

vim  /usr/local/nagios/etc/cgi.cfg  
把所有关于nagiosadmin改成你自己添加的用户名,重启服务即可。
  2,command  'check_Passwd' not define
解决:

cd /usr/local/nagios/etc/objects/ commands.cfg 把它定义好就可以了。
  3,Connction refurse host
解决:

cd /usr/local/nagios/libexec 下,使用 ./check_nrpe -H 192.168.0.150 -c check_ping 或者./check_nrpe -H 127.0.0.1 -c check_ping
如果还是提示Connction refurse host;接下来查看NRPE有没有启动:netstat -lntup |grep nrpe 如果没有启动执行
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d 然后再执行./check_nrpe -H 192.168.0.150 -c check_ping
  4,NRPE command  'check_disk' not define
解决:

      先ps -ef |grep nrpe
pkill nrpe  
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
ps -ef |grep nrpe
然后再获取./check_nrpe -H 192.168.0.150 -c check_disk
  5,CHECK_NRPE: Error - Could not complete SSL handshake.
解决:

vi /usr/local/nagios/etc/nrpe.cfg +79
allowed_hosts=127.0.0.1,192.168.0.22
ps -ef |grep nrpe
pkill nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
ps -ef |grep nrpe
  6,NRPE: Unable to read output
解决:

./check_nrpe -H 192.168.0.150 -c check_emm  如果还提示NRPE: Unable to read output然后
直接到里面/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3% 如果提示Permission denied
说明 /usr/local/nagios/libexec/check_memory.pl -w 6% -c 3% 没有执行的权限
chmod  +x  /usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%
  7,Whoops!Error: Could not read host and service status information!错误

解决:

先检查配置文件,检查nagios进程,检查httpd进程;结果是开启nagios服务后即可
[root@Nagios-Server ~]# /etc/init.d/nagios start



运维网声明 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-662325-1-1.html 上篇帖子: nagios安装及监控window主机 下篇帖子: nagios报 check_oracle_rman_backup_problems告警处理思路
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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