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

Nagios 安装笔记

[复制链接]

尚未签到

发表于 2015-11-23 09:07:00 | 显示全部楼层 |阅读模式
一、前提:系统、PHPApacheMySQLMail都工作正常,在这不做介绍;
二、需要安装:gccglibcgdgd-developenssl-develhttpd-develper-GDnet-snmp-develphp-pdophp-gdperl-Crypt-DES,为了方便避开烦人的包依赖问题,我直接
yum install httpd*php*net-snmpmysql*glibc*;
需要下载的源码包:
nagioshttp://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.2.tar.gz
nagios-pluginshttp://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
nrpehttp://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
nagios-snmp-pluginshttp://nagios.manubulon.com/nagios-snmp-plugins.1.1.1.tgz
###############################################  开始安装、配置  #####################################################
1、安装Nagios;
groupadd nagios
useradd -g nagios nagios
  
mkdir /usr/local/nagios

chown -R nagios:nagios /usr/local/nagios
chmod 755 /usr/local/nagios/
usermod -G nagios apache
    //apachenagios用户加入到nagios组里;
usermod -G nagios nagios

tar zxf nagios-3.2.2.tar.gz

cd nagios-3.2.2
./configure
(nagios默认安装目录即为/usr/local/nagios,可不用加--prefix参数)
  
根据如下提示:
the main program and CGIs compiled without any errors, you can continue with installing Nagios as follows (type 'make' without any arguments for a list of all possible options):  依次执行如下操作:

make all------编译

make install
  - This installs the main program, CGIs, and HTML files
安装主要的程序、CGI及HTML文件


make install-init
  - This installs the init script in /etc/rc.d/init.d
把nagios做成一个运行脚本,使nagios随系统开机启动,这是一个很方便的措施。


make install-commandmode
  - This installs and configures permissions on the directory for holding the external command file
给外部命令访问nagios配置文件的权限


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!
把配置文件的例子复制到nagios的安装目录
  
make install-webconf(如果apache用的是自己另外安装的,可以不执行此安装,直接在apache的配置文件httpd.conf中加入6所示内容)
- This installs the Apache config file for the Nagios web interface
把虚拟目录配置文件写入/etc/httpd/conf.d/nagios.conf,不需再往apache配置文件中另加nagios的目录.

2、安装nagios-plugins;
tar zxf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure  --with-nagios-user=nagios --with-nagios-group=nagios(默认安装路径为/usr/local/nagios)  
make
make install

6Apache里的配置文件自动加了nagios.conf,路径为/etc/httpd/conf.d 内容如下:
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

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

Alias /nagios &quot;/usr/local/nagios/share&quot;

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


重启apache
service httpd restart

3、为web访问加入认证的用户名和密码;
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin(新增用户必须和cgi.cfg中authorized_for_后面验证的用户一致)
  最好能运行 chmod 755 /usr/local/nagios/etc/htpasswd.users ,允许其他用户可以读取.
  
4、配置nagios
A、修改nagios中收取报警消息的联系人
#vi /usr/local/nagios/etc/objects/contacts.cfg
此处我只修改了email 加入了自己的邮箱地址;

Bvi /usr/local/nagios/etc/cgi.cfg
use_authentication=1 改成
use_authentication=0,
即不用验证.不然有一些页面不会显示。    //在网上看到这个,不知道这点是什么意思 ,我也做了此修改;

C、检查配置文件是否正确:
[iyunv@host etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 3.2.1
Copyright (c) 2009-2010 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-09-2010
License: GPL
....................................

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

D、修改日志文件的属主,以后有问题可以查看此文件;
chown -R nagios:nagios  /usr/local/nagios/var/nagios.log
E、以上各步配置均没有错误,此时可以启动nagios了,
service nagios start
到此nagios配置完成,可以通过下面web访问访问了;
http://ip/nagios/
  
5、配置被监控端;(监控linux服务器)
下载如下安装包:
Anagios-plugins:wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
Bnrpe:wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
安装如下;
(1)在系统中添加nagios用户;
useradd nagios
passwd nagios
(2)安装nagios-plugins;
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure
make
make install
(3)改变nagios下的属主;
chown nagios.nagios /usr/local/nagios -Rf
(4)安装nrpe-2.12
tar -zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
(5)修改nrpe.cfg,允许主机为对应公司网关;
vi  /usr/local/nagios/etc/nrpe.cfg allowed_hosts=127.0.0.1改成:X.X.X.X127.0.0.1
添加相应要监控的对象,如下所示:
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 500 -c 600
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
(6)  启动nrpe
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
可以查看nrpe是否启动;
netstat -an|grep 5666

察看是否能返回nrpv版本号;
/usr/local/nagios/libexec/check_nrpe -H localhost
  
6、配置command.cfgnagios.cfg……
vi /usr/local/nagios/etc/objects/commands.cfg

添加如下内容;

#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
添加被监控端的配置文件;
vi /usr/local/nagios/etc/nagios.cfg

在此处中间添加;
cfg_file=/usr/local/nagios/etc/objects/Test.cfg
编辑该文件;
define host{
use                                                         linux-server
host_name                                             Test
alias                                                        linux-server
address                                                  192.168.0.110
}

define service{
use                                                         generic-service
host_name                                             Test
service_description                                HTTP
check_command                                    check_http
}

define service{
use                                                         generic-service
host_name                                             Test
service_description                                 FTP
check_command                                     check_ftp
}

define service{
use                                                         generic-service
host_name                                             Test
service_description                                 SSH
check_command                                     check_ssh
}

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

define service{
use                                                        generic-service
host_name                                            Test
service_description                               POP3
check_command                                   check_pop
}

define service{
use                                                       generic-service
host_name                                           Test
service_description                              check-swap
check_command                                  check_nrpe!check_swap
}

define service{
use                                                       generic-service
host_name                                           Test
service_description                               check-load
check_command                                   check_nrpe!check_load
}

define service{
use                                                      generic-service
host_name                                           Test
service_description                              check-disk
check_command                                   check_nrpe!check_disk
}

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

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

define service{
use                                                     generic-service
host_name                                          Test
service_description                             total_procs
check_command                                 check_nrpe!check_total_procs
}

define service {
use                                                  generic-service
host_name                                      Test
service_description                          check_mysql
check_command                             check_mysql!192.168.0.110!3306!nagios!nagios!nagdb!60!600
}
这里面定义的是监控的对象,修改完成后保存退出,就可以了。
  
7、检查配置文件,重启nagios服务;
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart

8、此时可以访问该页面,相关的被监控的对象也将出现。

**************************************   M ySQL监控配置  *************************************
1、在要监控的MYSQL数据库里新建库和相应的用户;
CREATE DATABASE nagdb DEFAULT CHARSET=utf8;
GRANT SELECT ON nagdb.* TO 'nagios'@'%';
UPDATE mysql.user SET 'Password' = PASSWORD('********') WHERE 'User' = 'nagios'
FLUSH PRIVILEGES;
2、修改command.cfg,添加对mysql和主从同步的定义;
vi /usr/local/nagios/etc/objects/command.cfg;
define command{
command_name check_mysql
command_line    $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$
}

define command{
command_name check_mysql_slave
command_line    $USER1$/check_mysql -H $ARG1$ -P $ARG2$ -u $ARG3$ -p $ARG4$ -d $ARG5$ -S -w $ARG6$ -c $ARG7$
}
3、在被监控的主数据库和从数据库的cfg文件中分别添加;
define service {
use                                                          generic-service
host_name                                              Master-Mysql
service_description                                 check_mysql
check_command                                     check_mysql!192.168.0.111!3306!nagios!******!nagdb
}
define service {
use                                                          generic-service
host_name                                              Slave-Mysql
service_description                                 check_mysql_slave
check_command                                         check_mysql_slave!192.168.0.112!3306!nagios!******!nagdb!60!600
}
4、检查配置文件,重启nagios服务;
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
service nagios restart

5、到此MySQL的监控配置完成。

运维网声明 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-142396-1-1.html 上篇帖子: Nagios, NRPE, SNMP | 完全手动配置 下篇帖子: 基于CentOS下Nagios的安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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