阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.5下快速安装编译配置Nagios文档

124次阅读
没有评论

共计 12504 个字符,预计需要花费 32 分钟才能阅读完成。

CentOS 6.5 下快速安装编译配置 Nagios 文档 - 全部虚拟环境。

写这个文档的目的,就是为了方便 快捷的部署 Nagios, 涉及到个人喜好的配置,大家自行修改,可以套用。

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统 (使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

一、下载并安装所需软件

1,yum install gcc mysql httpd php gd openssl openssl-devel mysql-server vim wget

Wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz

Wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

Wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

Ls 可以看到 nagios-4.0.7.tar.gz nagios-plugins-2.0.3.tar.gz nrpe-2.14.tar.gz

yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

useradd nagios

passwd nagios

groupadd nagcmd

usermod –a –G nagcmd nagios

(nagcmd:x:504:nagios)

tar –xvzf nagios-4.0.7.tar.gz

cd nagios-4.0.7

./configure –with-command-group=nagcmd

可以先./configure –help 先看看帮助,应为默认为主是用 nagios 用户,不需要指定—with-nagios-user 或其它什么的。

make all

make install

make install-init

这个安装 /etc/rc.d/init.d 中的 init 脚本

make install-commandmode

这个安装和配置权限

目录的外部命令文件

make install-config

这个安装 * * /usr/local/nagios/etc 配置文件示例

你必须修改这些示例文件之前

使用 Nagios。阅读 HTML 文档

make install-webconf

这个安装 Nagios 的 Apache 配置文件

Web 界面

Cp –R contrib/eventhandlers/ /usr/local/nagios/libexec/

(-R: 递归复制目录,即连同目录下的子目录和文件一起复制。)

Chown –R nagios:nagios /usr/local/nagios/libexec/eventhandlers

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (检测配置文件是否有错误)

{[root@Nagios libexec]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/

[root@Nagios libexec]# ll

total 4

drwxr-xr-x. 4 nagios nagios 4096 Oct 21 01:16 eventhandlers}

/etc/init.d/nagios start 或者 service nagios start

Chkconfig –add nagios

Chkconfig nagios on

Chkconfig httpd on

Service httpd start

二、创建 web 用户

切换到 ngios 用户

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

输入密码 nagios

三、安装 nagios-plugins

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins-2.0.3

./configure {–with-nagios-user=nagios –with-nagios-group=nagios}

Make

Make install

前面这步做了可以略过,反正要做一次。

Chkconfig nagios on 或者 chkconfig –level 35 nagios on

Chkconfig httpd on 或者 chkconfig –level 35 httpd on

四、关闭防火墙和 selinux

service iptables stop

Vim /etc/sysconfig/selinux 把 selinux 改成 disabled 这个需重启生效。

http://192.168.1.202/nagios/ 这个是 nagios 地址,要输入用户名和密码的 nagiosadmin nagios

****** 无法开题 notifications 报错 ****************************************

Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

这个主要是 apache 用户 没有执行权限 /usr/local/nagios/var/rw/nagios.cmd 造成,

解决方法:

usermod -a -G nagcmd apache

将 apache 用户添加到 nagios 用户组,就 OK 了。

date -s 调整日期时间  clock -w 保存

五、安装 NRPE 插件。

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make && make install

make install-plugin

把 check_nrpe 放到 /usr/local/nagios/libex 下。才能使用 check_nrpe。

***********************************************************************************

*********************************2***************************************************

在被监控机器上安装。

Nagios-plugins 安装.

Useradd nagios

Passwd nagios

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins

./configure

Make

Make install

Chown –R nagios:nagios /usr/local/nagios

安装 nrpe-2.14

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

yum install xinetd

chkconfig –add xinetd

chkconfig xinetd on

make install-xinetd

vim /etc/xinetd.d/nrpe

在该文件的 only_from  = 127.0.0.1 192.168.1.107  // 在后面增加监控主机的地址, 以空格间隔

vim /usr/local/nagios/etc/nrpe.cfg 这里也是充许访问里添加 192.168.107

vim /etc/services

启动 nrpe 就好了。

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

service xinetd restart

netstat -at |grep nrpe

Netstat –an | grep 5666

Vim /etc/sysconfig/iptables

-A INPUT -m state –state NEW -m tcp -p tcp –dport 5666 -j ACCEPT (该语句有待,不过我另一台也是这样配的)

好像不添加上面这个不得行,会报 check_nrpe:Error – Could not complete SSL handshake

运行 ipables –F 清空一下规则,然后保存。

然后 iptables –L –n 查看确认后。

Service iptables save

Service iptables restart

2、配置文件方面:

(1)/usr/local/nagios/etc/nrpe.cfg 此配置文件是配置正确,多个 IP 地址逗号隔开,且要注意空格:allowed_host=127.0.0.1,  192.168.0.1 这是不对的,必须是 allowed_host=127.0.0.1,192.168.1.202  逗号之后不能有空格;

(2)检查是否配置里限制了,在 /etc/xinetd.d/nrpe 文件中要添加允许访问的服务器的 IP 地址,在“only_from =”这一行添加,多个 IP 地址用空格隔开,例如:only_from      = 192.168.0.8 192.168.1.202

被控端:

vi /etc/xinetd.d/nrpe

only_from 增加主控 IP

vi /usr/local/nagios/etc/nrpe.cfg

allowed_hosts 增加主控 IP

service xinetd restart

主控端:

/usr/local/nagios/libexec/check_nrpe -H 被监控端 IP 地址      测试是否连接成功

修改 nrpe.cfg 后一定要重启 nrpe, 大侠我是这样做的:

pkill nrpe;

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg  -d

二、添加监控节点及 service

三】增加验证用户

也就是通过 web 访问 nagios 的时候, 必须要用这个用户登陆. 在这里我们增加用户 test: 密码为 12345

64.  [root@localhost nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test

可以用 which 命令查看 htpasswd 命令的位置,如果是源码安装的 apache 这里就写 htpasswd 的全路径。用户是 test,命令结束会提示你输入密码,这里输入 123456 即可。

65.  查看认证文件的内容

66.  [root@localhost nagios-plugins-1.4.13]# less /usr/local/nagios/etc/htpasswd

67.  到这里 nagios 的安装也就基本完成了, 你可以通过 web 来访问了.

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-11/109653p2.htm

三、检测定义快捷命令

问题 1:新建立文件夹及节点无法生效

解决:修改 nagios 目录文件,使其目录被检测

vi /usr/local/nagios/etc/nagios.cfg

添加 要检测的目录。

cfg_dir=/usr/local/nagios/etc/cfgs

问题 2:《《apache 启动失败》》默认安装在 /usr/sbin/ 下,执行 apachectl start 时候,提示如下错误:

httpd: apr_sockaddr_info_get() failed for shiwei

httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName

于是上网查了一下,根据前人的经验,问题终于解决了。总结一下,方便以后使用。

原因:这个问题应该是没有在 /etc/httpd/conf/httpd.conf 中设定 ServerName。所以 apache 会用主机上的名称来取代,首先会去找 /etc/hosts 中有没有主机的定义。

解决办法:

(1)可以设定 httpd.conf 文件中的 ServerName,如下:ServerName localhost:80

(2)在 /etc/hosts 中填入自己的主机名称 bogon,如下:127.0.0.1 shiwei (用户名称)

问题 3 NRPE: Unable to read output

我的解决办法是:修改 nagios 目录的权限

#chown -R nagios:nagios nagios/

#chmod -R 775 nagios/

问题解决。linux

四、添加 command

command[check_cpu]=/usr/local/nagios/libexec/check_cpu_pct -w $ARG1$ -c $ARG2$

command[check_memory]=/usr/local/nagios/libexec/check_mem -w $ARG1$ -c $ARG2$

将配置文件拷贝到指定目录后,修改所属及访问权限。

command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$

command[check_swap]=/usr/local/nagios/libexec/check_swap -w $ARG1$ -c $ARG2$228

command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$

command[check_io]=/usr/local/nagios/libexec/check_iostat -d $ARG3$ -w $ARG1$ -c $ARG2$

五、安装 sendmail

首先要确保 sendmail 相关组件的完整安装,我们可以使用如下的命令来完成 sendmail 的安装:

# yum install -y sendmail*

然后重新启动 sendmail 服务:

# service sendmail restart

然后发送测试邮件,验证 sendmail 的可用性:

# echo “Hello World” | mail abc@abc.com

Root@Nagios objects]# service sendmail restart

Shutting down sendmail:                                    [FAILED]

Starting sendmail:                                        [OK]

Starting sm-client:                                        [OK]

chkconfig sendmail off

chkconfig sendmail off  加速开机时间

重启服务器注意 1,开机 nrpe 二启动 sendmail 三 iptables 设置

Nagios 多用户的一些配置

刚开始我想到在搭 nagios 的时候,用户验证是用 apache 来做的,接到这个需求后的第一反应是这个东西可能做不了。但接着一想,不应该啊,nagios 本身至少会有一些用户配置的吧,于是乎开始寻找相关资料,基本配置如下:

(1)新增一个 apache 用户,如 qiuyuetao

[root@service3F-38 ~]# htpasswd /usr/local/nagios/etc/htpasswd.users  qiuyuetao

(2)更改 cgi.cfg 配置

[root@service3F-38 ~]# vi /usr/local/nagios/etc/cgi.cfg

use_authentication=1

如果只允许查看,不允许管理,加上下面配置

authorized_for_read_only=qiuyuetao

authorized_for_all_services=qiuyuetao

authorized_for_all_hosts=qiuyuetao

(3)将 userA 设为联系人

[root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/contacts.cfg  #添加如下配置

define contact{

contact_name                  qiuyuetao

use                                      generic-contact

alias                                    qyt

}

(4)在属于 userA 的主机、服务配置文件的联系人中加入 qiuyuetao

[root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/hosts.cfg

define host {

host_name web02-1.22@sh

alias web02-1.22@sh

address 10.1.1.22

contacs qyt

contact_groups sys_admins

check_command check-host-alive

max_check_attempts 5

notification_interval  3

notification_period 24×7

notification_options d,u,r

}

(5)重启 nagios 后生效

[root@service3F-38 ~]#  /etc/init.d/nagios restart

Nagios 的详细介绍 :请点这里
Nagios 的下载地址 :请点这里

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

CentOS 6.5 下快速安装编译配置 Nagios 文档 - 全部虚拟环境。

写这个文档的目的,就是为了方便 快捷的部署 Nagios, 涉及到个人喜好的配置,大家自行修改,可以套用。

网络监控器 Nagios 全攻略 http://www.linuxidc.com/Linux/2013-07/87067.htm

Nagios 搭建与配置详解 http://www.linuxidc.com/Linux/2013-05/84848.htm

Nginx 环境下构建 Nagios 监控平台 http://www.linuxidc.com/Linux/2011-07/38112.htm

在 RHEL5.3 上配置基本的 Nagios 系统 (使用 Nagios-3.1.2) http://www.linuxidc.com/Linux/2011-07/38129.htm

CentOS 5.5+Nginx+Nagios 监控端和被控端安装配置指南 http://www.linuxidc.com/Linux/2011-09/44018.htm

Ubuntu 13.10 Server 安装 Nagios Core 网络监控运用 http://www.linuxidc.com/Linux/2013-11/93047.htm

一、下载并安装所需软件

1,yum install gcc mysql httpd php gd openssl openssl-devel mysql-server vim wget

Wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.7.tar.gz

Wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz

Wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz

Ls 可以看到 nagios-4.0.7.tar.gz nagios-plugins-2.0.3.tar.gz nrpe-2.14.tar.gz

yum install wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

useradd nagios

passwd nagios

groupadd nagcmd

usermod –a –G nagcmd nagios

(nagcmd:x:504:nagios)

tar –xvzf nagios-4.0.7.tar.gz

cd nagios-4.0.7

./configure –with-command-group=nagcmd

可以先./configure –help 先看看帮助,应为默认为主是用 nagios 用户,不需要指定—with-nagios-user 或其它什么的。

make all

make install

make install-init

这个安装 /etc/rc.d/init.d 中的 init 脚本

make install-commandmode

这个安装和配置权限

目录的外部命令文件

make install-config

这个安装 * * /usr/local/nagios/etc 配置文件示例

你必须修改这些示例文件之前

使用 Nagios。阅读 HTML 文档

make install-webconf

这个安装 Nagios 的 Apache 配置文件

Web 界面

Cp –R contrib/eventhandlers/ /usr/local/nagios/libexec/

(-R: 递归复制目录,即连同目录下的子目录和文件一起复制。)

Chown –R nagios:nagios /usr/local/nagios/libexec/eventhandlers

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (检测配置文件是否有错误)

{[root@Nagios libexec]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers/

[root@Nagios libexec]# ll

total 4

drwxr-xr-x. 4 nagios nagios 4096 Oct 21 01:16 eventhandlers}

/etc/init.d/nagios start 或者 service nagios start

Chkconfig –add nagios

Chkconfig nagios on

Chkconfig httpd on

Service httpd start

二、创建 web 用户

切换到 ngios 用户

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

输入密码 nagios

三、安装 nagios-plugins

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins-2.0.3

./configure {–with-nagios-user=nagios –with-nagios-group=nagios}

Make

Make install

前面这步做了可以略过,反正要做一次。

Chkconfig nagios on 或者 chkconfig –level 35 nagios on

Chkconfig httpd on 或者 chkconfig –level 35 httpd on

四、关闭防火墙和 selinux

service iptables stop

Vim /etc/sysconfig/selinux 把 selinux 改成 disabled 这个需重启生效。

http://192.168.1.202/nagios/ 这个是 nagios 地址,要输入用户名和密码的 nagiosadmin nagios

****** 无法开题 notifications 报错 ****************************************

Error: Could not open command file ‘/usr/local/nagios/var/rw/nagios.cmd’ for update!

这个主要是 apache 用户 没有执行权限 /usr/local/nagios/var/rw/nagios.cmd 造成,

解决方法:

usermod -a -G nagcmd apache

将 apache 用户添加到 nagios 用户组,就 OK 了。

date -s 调整日期时间  clock -w 保存

五、安装 NRPE 插件。

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make && make install

make install-plugin

把 check_nrpe 放到 /usr/local/nagios/libex 下。才能使用 check_nrpe。

***********************************************************************************

*********************************2***************************************************

在被监控机器上安装。

Nagios-plugins 安装.

Useradd nagios

Passwd nagios

Tar –xvzf nagios-plugins-2.0.3.tar.gz

Cd nagios-plugins

./configure

Make

Make install

Chown –R nagios:nagios /usr/local/nagios

安装 nrpe-2.14

Tar –xvzf nrpe-2.14.tar.gz

Cd nrpe-2.14

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

yum install xinetd

chkconfig –add xinetd

chkconfig xinetd on

make install-xinetd

vim /etc/xinetd.d/nrpe

在该文件的 only_from  = 127.0.0.1 192.168.1.107  // 在后面增加监控主机的地址, 以空格间隔

vim /usr/local/nagios/etc/nrpe.cfg 这里也是充许访问里添加 192.168.107

vim /etc/services

启动 nrpe 就好了。

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

service xinetd restart

netstat -at |grep nrpe

Netstat –an | grep 5666

Vim /etc/sysconfig/iptables

-A INPUT -m state –state NEW -m tcp -p tcp –dport 5666 -j ACCEPT (该语句有待,不过我另一台也是这样配的)

好像不添加上面这个不得行,会报 check_nrpe:Error – Could not complete SSL handshake

运行 ipables –F 清空一下规则,然后保存。

然后 iptables –L –n 查看确认后。

Service iptables save

Service iptables restart

2、配置文件方面:

(1)/usr/local/nagios/etc/nrpe.cfg 此配置文件是配置正确,多个 IP 地址逗号隔开,且要注意空格:allowed_host=127.0.0.1,  192.168.0.1 这是不对的,必须是 allowed_host=127.0.0.1,192.168.1.202  逗号之后不能有空格;

(2)检查是否配置里限制了,在 /etc/xinetd.d/nrpe 文件中要添加允许访问的服务器的 IP 地址,在“only_from =”这一行添加,多个 IP 地址用空格隔开,例如:only_from      = 192.168.0.8 192.168.1.202

被控端:

vi /etc/xinetd.d/nrpe

only_from 增加主控 IP

vi /usr/local/nagios/etc/nrpe.cfg

allowed_hosts 增加主控 IP

service xinetd restart

主控端:

/usr/local/nagios/libexec/check_nrpe -H 被监控端 IP 地址      测试是否连接成功

修改 nrpe.cfg 后一定要重启 nrpe, 大侠我是这样做的:

pkill nrpe;

/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg  -d

二、添加监控节点及 service

三】增加验证用户

也就是通过 web 访问 nagios 的时候, 必须要用这个用户登陆. 在这里我们增加用户 test: 密码为 12345

64.  [root@localhost nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test

可以用 which 命令查看 htpasswd 命令的位置,如果是源码安装的 apache 这里就写 htpasswd 的全路径。用户是 test,命令结束会提示你输入密码,这里输入 123456 即可。

65.  查看认证文件的内容

66.  [root@localhost nagios-plugins-1.4.13]# less /usr/local/nagios/etc/htpasswd

67.  到这里 nagios 的安装也就基本完成了, 你可以通过 web 来访问了.

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-11/109653p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计12504字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中