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

nagios监控初级配置。

[复制链接]

尚未签到

发表于 2019-1-15 08:31:43 | 显示全部楼层 |阅读模式
#===========================安装 Nagios    ========================================
groupadd nagios
groupadd nagios
useradd nagios -g nagios -d /usr/local/nagios
chown nagios.nagios /usr/local/nagios/
chmod 755 /usr/local/nagios
wget
http://osdn.dl.sourceforge.net/sourceforge/nagios/nagios-3.0.2.tar.gz
tar -zxvf nagios-3.0.2.tar.gz
cd nagios-3.0.2
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode

创建一个web页面登陆用户,在htppasswd.users里面可以看到用户名。
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#编辑httpd.conf配置文件
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"


#  SSLRequireSSL
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user

Alias /nagios "/usr/local/nagios/share"

#  SSLRequireSSL
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
#  Order deny,allow
#  Deny from all
#  Allow from 127.0.0.1
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /usr/local/nagios/etc/htpasswd.users
   Require valid-user

#重启apache
killall httpd


#============================安装nagios plugins=========================
wget plugins下载。

tar -zxvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-gourp=nagios --with-mysql=/usr/local/mysql5/ --enable-perl-modules
make
make install

#配置和启动nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#如果提示“Whoops!   Error: Could not read object configuration data! ”,这是因为没有启动nagios后台进程,执行以下命令
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

#=============================安装nrpe 插件==============================
#对远程一台linux主机进行监控
#监控服务器上安装nrpe
wget
http://www.mirrors.wiretapped.net/security/network-monitoring/nagios/nrpe-2.8.1.tar.gz
#监控主机上安装方法
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure
make all
make install
make install-plugin    ---监控机需要安装check_nrpe这个插件,被监控机并不需要
##########################################################################
#被监控主机上安装方法
useradd nagios -d /usr/local/nagios
chown nagios.nagios /usr/local/nagios/
tar -zxvf nagios-plugins-1.4.11.tar.gz
cd nagios-plugins-1.4.11
./configure --enable-perl-modules --with-ping-command=ping
make
make install

cd /opt
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
./configure
make all
make install
make install-plugin
make install-daemon
make install-daemon-config


vi /usr/local/nagios/etc/nrpe.conf
allowed_hosts=192.168.8.150
#为了监控swap在nrpe.cfg中添加
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda1
#sdb1可根椐实际情况更改,我这里的硬盘类型是scsi

vi /etc/services
#增加nrpe
nrpe            5666/tcp                        # nrpe
#启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

netstat -at|grep nrpe
netstat -an|grep 5666

#############################################################################
#再对监控服务器进行设置
#添加nrpe的定义
vi /usr/local/nagios/etc/objects/commands.cfg
# 'check_nrpe ' command definition
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

vi /usr/local/nagios/etc/cgi.cfg
把use_authentication=1修改为use_authentication=0如果出现页面无法显示之类的
authorized_for_system_commands=nagiosadmin,kerry    --kerry为http访问授权用户
authorized_for_all_services=nagiosadmin,kerry
authorized_for_all_hosts=nagiosadmin,kerry
authorized_for_all_service_commands=nagiosadmin,kerry
authorized_for_all_host_commands=nagiosadmin,kerry

#测试NRPE是否则正常工作
/usr/local/nagios/libexec/check_nrpe -H localhost

killall nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d"  >> /etc/rc.local
ehco "/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg" >>/etc/rc.local

#问题:notifications for this service have been disabled
#解决办法:enable notifications for this service

#问题:Status Map页面无法显示
#解决方法:ln -s /usr/local/lib/libgd.so.2 /usr/lib/libgd.so.2

vi /usr/local/nagios/etc/nagios.cfg
#添加
cfg_file=/usr/local/nagios/etc/objects/emos-mailserver.cfg
#emos-mailserver.cfg这个文件名可以自定义

#对刚定义的emos-mailserver.cfg文件进行配置
vi /usr/local/nagios/etc/objects/emos-mailserver.cfg
define host{
           use          linux-server
          host_name     emos-mailserver
          alias         emos-mailserver
          address       192.168.8.151
        }
define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     HTTP
        check_command     check_http
       }
define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     SSH
        check_command   check_ssh
       }

define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     SMTP
        check_command   check_smtp
       }

define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     POP3
        check_command   check_pop
       }
#define service{
#        use             generic-service
#        host_name       emos-mailserver
#        service_description     mysql
#        check_command   check_mysql
#       }
define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     check-swap
        check_command           check_nrpe!check_swap
        }
define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     check-load
        check_command           check_nrpe!check_load

        }
define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     check-disk
        check_command           check_nrpe!check_sda1
}

define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     zombie_procs
        check_command           check_nrpe!check_zombie_procs
        }

define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     check-users
        check_command           check_nrpe!check_users
        }

define service{
        use             generic-service
        host_name       emos-mailserver
        service_description     total_procs
        check_command           check_nrpe!check_total_procs
#配置完后,重启nagios
killall nagios
service nagios start
pstree |grep nagios

http://192.168.8.150/nagios





#=============================安装  pnp===============================================
cd /opt
tar zxvf pnp-0.4.12.tar.gz
cd pnp-0.4.12
./configure --with-nagios-user=nagios \
--with-nagios-group-nagios \
--with-rrdtool=/usr/local/rrdtool/bin/rrdtool \
--with-perfdata-dir=/usr/local/nagios/share/perfdata
make
make all
make install
make install-config
make install-init

#错误提示:RRDs Perl Modules:                *** NOT FOUND ***
#解决方法:ln -sv /usr/local/rrdtool/lib/perl/5.8.8/i386-linux-thread-multi/auto/RRDs/RRDs.so /usr/lib/perl5/5.8.8/i386-linux-thread-multi/

#要产生图形数据还需在commands.cfg中重定义命令:
define command{
command_name process-service-perfdata
command_line /usr/local/nagios/libexec/process_perfdata.pl
}

#产生图形数据还要设定nagios.cfg文件:
process_performance_data=1
service_perfdata_command=process-service-perfdata


http://192.168.8.150/nagios/pnp/




#==========================监控远程windows主机==================================
#监控windows服务器
wget
http://nchc.dl.sourceforge.net/s ... t++-Win32-0.3.5.zip
解压nsclient++0.3.3.zip到c盘根目录

解压为C:\NSClient++


#在nagios监控服务器上
vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/windows.cfg 去掉这句话的注释


#到win服务器上,打开命令窗口,cd到刚才解压的目录
#在命令行界面执行 nsclient++ /install

#然后 nsclient++  SysTray 如果出错不用管!

#此时在“服务”里面已经有了nsclient的服务
双击打开,点"登录"标签,在"允许服务与桌面交互"前打勾

#编辑NES.ini,在 [modules] 选项里,去掉所有的注释符号; 除了
CheckWMI.dll和RemoteConfiguration.dll

#the [Settings] 选项里
修改allowd_host=192.168.8.150(nagios服务器的ip)
#[NSClient] 里面,去掉port=12489的注释!他靠端口12489侦听,所以防火墙要打开这个端口!

在[Settings]部分设置'password'选项来设置密码,作用是在nagios连接过来时要求提供密码.这一步是可选的,我这里方便起见跳过它,不要密码.

#然后启动nsclient
nsclient++ /start

#接下来我们开始配置nagios服务器里面的内容
vi /usr/local/nagios/etc/objects/windows.cfg
define host{
    use windows-server
    host_name winserver alias
    My Windows Server
    address 192.168.8.151   --windows服务器的IP地址
    }
#修改hostname和address,很重要!!
#重新启动监控服务器上的nagios
killall nagios
service nagios start

#==============================安装  sengEmail ==================================
#使用sendEmail发送报警邮件
cd /opt
wget
http://caspian.dotconf.net/menu/ ... dEmail-v1.55.tar.gz
tar -zxvf sendEmail-v1.55.tar.gz
cd sendEmail-v1.55
cp sendEmail /usr/local/bin
chmod +x /usr/local/bin/sendEmail
#sendEmail使用方法
/usr/local/bin/sendEmail –f
kerry.hu@3aaa.com –t kerry.hu@3aaa.com –s mail.3aaa.com –u “from nagios” –xu kerry.hu@3aaa.com –xp 11111 –m happy
#解释:-f 表示发送者的邮箱
     -t 表示接收者的邮箱
     -s 表示SMTP服务器的域名或者ip
     -u 表示邮件的主题
     -xu 表示SMTP验证的用户名
     -xp 表示SMTP验证的密码(注意,这个密码貌似有限制,例如我用d!5neyland就不能被正确识别)
     -m 表示邮件的内容如果你不带-m参数的话,就会提示你自行输入

#编辑配置文件,nagios使用sendEmail来发警告邮件
vi /usr/local/nagios/etc/objects/commands.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" | /usr/local/bin/sendEmail –f
kerry.hu@3aaa.com –t $CONTACTEMAIL$ –s mail.3aaa.com –u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" –xukerry.hu@3aaa.com –xp 11111
}

# '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$" | /usr/local/bin/sendEmail –f
kerry.hu@3aaa.com –t $CONTACTEMAIL$ –s mail.3aaa.com –u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" –xukerry.hu@3aaa.com –xp 111111
}

#注:在使用sendEmail的过程中无法发送报警邮件,不知是什么原因,只好改用系统自带的sendmail发邮件!!





运维网声明 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-663392-1-1.html 上篇帖子: Nagios的安装配置与应用之二Nagios配置前的排错 下篇帖子: nagios监控远程windows服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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