喜旎果 发表于 2019-1-15 06:58:38

nagios安装及监控

一、如何安装nagios

  


# 1 安装yum install gd-devel -y
# 2 部署lamp环境yum install httpd mysql mysql-server php php-mysql -y
# 3 安装主程序nagios
# tar fvxz nagios.tar.gz(进入目录解压)
# cd nagios-3.2.0
# ./configure --prefix=/usr/local/nagios(这一步运行如果未装gcc,先yum install gcc* 一下就可以了)
# useradd nagios
# make all
# make install
make install
   - This installs the main program, CGIs, and HTML files

  
make install-init


   - This installs the init script in /et c/rc.d/init.d

  
   make install-commandmode


   - This installs and configures permissions on the
       directory for holding the external command file

  
make install-config


   - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.Read the HTML documentation for more info
       on doing this.Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!

  



  
make install-webconf


   - This installs the Apache config file for the Nagios
       web interface

  
vim /etc/httpd/conf/httpd.conf(修改User和Group为nagios)


User nagios
Group nagios

  
重新启动apache(如果在编译nagios的时候,步骤不对,会无法启动服务。)


service httpd restart
service nagios start
生成用户
3.2.0]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios(为用户设置密码,密码随意)
New password:
Re-type new password:
Adding password for user nagios

  
修改nagios的第一个配置文件,可以看到谁的分区控制台连上来,以谁的身份连上来,看到什么,是在这个文件里控制的。


3.2.0]# vim /usr/local/nagios/etc/cgi.cfg
在所有的nagiosadmin后面添加nagios
给nagios用户开权限,让他能够查看信息!

  
root@server1 nagios-

3.2.0]#/etc/init.d/nagios reload
修改好了以后重新载入一下。
进入nagios
192.168.18.126/nagios

  
本机为什么是down的状态???




http://blog.运维网.com/attachment/201303/180636819.jpg
  监控分析控制台   ---------------主程序
                                           插件
                --------------被监控主机
如果想让nagios监控别人,需要安装一个插件才可以监控。


# pwd

/usr/local/nagios/libexec
# ls
#
进入插件目录下我们看到什么没有阿!
所以需要安装插件


安装插件

1.4.13]cd /nagios-plugins-1.4.13
1.4.13]# ./configure --prefix=/usr/local/nagios/ (编译)
可选的选项--with-gnutls --with-openssl --enable-extra-opts --enable-perl-modules


make



make install





http://blog.运维网.com/attachment/201303/180733451.jpg



  二、如何监控别人
我们先看监控时间的配置文件,默认不用改。
cd /usr/local/nagios/etc/objects
vim timeperiods.cfg
这个文件是时间段的文件,24*7监视时间段24小时每天每时。


http://blog.运维网.com/attachment/201303/180805410.jpg

这个文件默认不用改。


设置监控的是谁,修改时注意扩高成对。首先增加想要监控的对象,对象名字可随意,ip写好。

vim localhost.cfg
配置文件内的选项含义。
host_name 主机名可以随便写
alias       别名可以随便写
address    监控的主机IP地址(这里我们要监控的是192.168.18.124)
check_commandcheck-host-alive 一会通过这条命令检查监控的对象的情况,这条命令是在一个配置文件定义好的
notification_optionsd,u,r什么样的情况对给你通知,down,未知,恢复这三个状态会通知给你监控对象的信息
check_interval 1代表多长时间检查一次 (1分钟)
max_check_attempts 2检查什么样的情况发送报警,超过2次以上的情况会发送tact
contact_groups admin 代表有情况的时候找admin
notification_interval 10 第二次通知的时间为10分钟
notification_period   代表什么时间发送通知呢 24*7,只要出了问题就会通知你
ps:(大括号要成对)。


http://blog.运维网.com/attachment/201303/180841211.jpg
vim commands.cfg 定义命令的配置文件
$USR1$代表check-host-alive这条命令会执行/usr/local/libxec/check_ping -H HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
通过命令的阀值来判断是否有问题。


http://blog.运维网.com/attachment/201303/180953627.jpg




三、和谁联系
现在来定义发送信息给谁,默认的是给admin
vim contacts.cfg
admin组是事先定义好的,成员只有一个是nagiosadmin,然后我们添加一个联系人,
contact_name这个人的名字可以随便写,这里我们写source
alias 别名 随便写
host_notification_period 24*7 代表什么时间会接收信息
host_notification_option 接收报警的状态,down,未知,恢复这三个状态
host_notification_conmands


http://blog.运维网.com/attachment/201303/181017202.jpg

修改好以后先检查一下错误,用这条命令
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
他会告诉你你的配置文件是否有问题
total Errors :0 没有问题


http://blog.运维网.com/attachment/201303/181045913.jpg

说明已经添加好了。然后我们让我们监控的主机断开网络,会出现如图的结果


http://blog.运维网.com/attachment/201303/181123258.jpg
查看日志我们发现18.124这台主机已经找不到了。 并且有报错信息


http://blog.运维网.com/attachment/201303/181154930.jpg

发送报警信息是给nagiosadmin,source这两个人的,如果要不想给nagiosadmin发送可以在contacts.cfg
首先删除这几行


http://blog.运维网.com/attachment/201303/181225711.jpg

然后在组员里(members)把nagiosadmin除名就可以了。


http://blog.运维网.com/attachment/201303/181251502.jpg

修改了以后注意/etc/init.d nagios reload 重新读取一下


这样就可以监控主机了。




四、让监控的信息能发送到手机上

要求是
192.168.18.126为监控服务器
这台机器能够上网
ifconfig eth0:1 192.168.1.159
route add default gw 192.168.1.1 定义网关
ping 8.8.8.8






1 install
rpm -ivh /tmp/nagios/!msmtp-1.4.6-1.el5.scopserv.i386.rpm

http://blog.运维网.com/attachment/201303/181417582.jpg
  2 config
#cd/etc/
#vim msmtprc


account default

host smtp.163.com
port 25
from 18611383332@163.com
tls off
auth login
user 18611383332
password 123456
logfile /tmp/msmtp.log
复制信息并修改成如图,用户名和密码是自己邮箱的。




http://blog.运维网.com/attachment/201303/181640820.jpg

  3 test
#####msmtp email








4 mutt

vim /etc/Muttrc
2753 set sendmail="/usr/bin/msmtp"
2754 set from="1861183332@163.com"
2755 set realname="iori"






http://blog.运维网.com/attachment/201303/181728289.jpg
  修改好
5 mutt+msmtp
echo "hello" |mutt -s "test" hebaihan456@163.com


6         vim /etc/resolv.conf

修改DNS



http://blog.运维网.com/attachment/201303/181829798.jpg
  然后测试网络
ping www.baidu.com


echo "hello" |mutt -s "test" hebaihan456@163.com

发送信息,这时手机会收到nagios报警信息。
发送的信息为hello到hebaihan456@163.com

请大家支持原创。





页: [1]
查看完整版本: nagios安装及监控