centos6.8配置Nagios全套
2018-01-25 10:09
162 查看
系统版本:
[root@tomcat-01 ~]# cat /etc/redhat-release CentOS release 6.8 (Final)
环境:
nagios服务端:192.168.93.7被监控客户端:192.168.93.5
nagios服务端
一、下载并安装所需软件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
此处我将三个包下载到/root目录下
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)
安装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。 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.93.7/nagios/ 这个是nagios地址,要输入用户名和密码的nagiosadmin nagios
*无法开题notifications报错[b]*******************************[/b]
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。
被监控客户端
准备初始环境yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
安装nagios插件nagios-plugin
useradd nagios passwd nagios wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz 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
wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz tar –xvzf nrpe-2.14.tar.gz cd nrpe-2.14 ./configure make all
安装check_nrpe 这个插件
make install-plugin 监控机需要安装check_nrpe 这个插件,被监控机并不需要,我们在这里安装它只是为了测试目的。
安装deamon
make install-daemon
安装配置文件
make install-daemon-config 现在再查看/usr/local/nagios/目录就会发现有5个目录了 按照安装文档的说明,是将NRPE deamon作为xinetd下的一个服务运行的。在这样的情况下xinetd就必须要先安装好,不过一般系统已经默认安装了。 yum install xinetd chkconfig --add xinetd chkconfig xinetd on
安装xinted 脚本
make install-xinetd
可以看到创建了这个文件/etc/xinetd.d/nrpe , 编辑该文件
在only_from 后增加监控主机的IP地址,如
only_from = 127.0.0.1 192.168.93.7
编辑/etc/services 文件,增加NRPE服务 ,在文件最后 增加一行
nrpe 5666/tcp #nrpe
重启xinted 服务
service xinetd restart
查看NRPE 是否已经启动
netstat -an | grep 5666
如果发现5666 端口号被监控,则是起来了。
本地测试
/usr/local/nagios/libexec/check_nrpe -H localhost
成功启动 ,会返回版本号
增加nagios服务端的访问IP
默认只允许本地的访问,需要配置文件,以便服务端也可以访问。
vi /usr/local/nagios/etc/nrpe.cfg allowed_hosts=127.0.0.1,192.168.93.7(192.168.93.7位nagios服务端ip)
如果NRPE是手动方式启动的,这里需要重启NRPE ,如果是以xinet服务启动的,则不用重启。
手工重启一下 NRPE方法,以xinet服务启动时 ,不用做这一步。
pkill nrpe /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
现在去nagios服务端测试一下 ,192.168.93.5 为被监控机IP
/usr/local/nagios/libexec/check_nrpe -H 192.168.93.5
成功启动 ,会返回版本号
被监控机就配好了。
nagios服务端添加被监控主机
1、 添加HOSTvi /usr/local/nagios/etc/objects/localhost.cfg define host{ use linux-server ; 引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。 host_name tomcat01 ;主机名 alias tomcat01-1 ;主机别名 address 192.168.93.5 ;被监控的主机地址,这个地址可以是ip,也可以是域名。 }
2、 增加服务
vi /usr/local/nagios/etc/objects/localhost.cfg
可以新建服务,或者 如果服务相同的话, 直接将 新加入的 host那么 用逗号隔开,跟在host_name 的后面就可以。 如
#---blfb-login start----------------------------------------------------------- define service{ use local-service ;引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。 host_name blfb-login,blfb-gamesr01 ;这个服务写了两个主机名,说明这两个主机都会检测这个check-host-alive 服务 service_description check-host-alive ;对监控服务内容的描述,以供维护人员参考。 check_command check-host-alive ;指定检查的命令。 } define service{ use local-service host_name blfb-login service_description Current Load check_command check_nrpe!check_load } define service{ use local-service host_name blfb-login service_description Check Disk vdc1 check_command check_nrpe!check_vdc1 contact_groups admins,blfb_cp_group } define service{ use local-service host_name blfb-login service_description Check Zombie Procs check_command check_nrpe!check_zombie_procs } #---blfb-login- end--------------------------------------------------------------
3、重启前 检查 配置文件
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
4、 如果没有错误 ,也没有警告, 就可以重启。
service nagios restart
5、 在浏览器查看添加情况
完。
注意:可能check_vdc1 这个命令会提示不存在, 或者 硬盘名不对。 那就需要去 被监控机改一个配置 ,该成自己想要监控的 设备名 如我的是 /dev/vdv1
vi /usr/local/nagios/etc/nrpe.cfg command[check_vdc1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/vdc1
以下是监控的一台私有云控制节点的配置(供大家参考)
define host{ use linux-server host_name controller alias controller address 192.168.96.61 check_command check-host-alive max_check_attempts 2 notification_period 24x7 notification_interval 3600 notification_options d,u,r } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description PING check_command check_ping!100.0,20%!500.0,60% } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description SSH check_command check_ssh } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description Horizon check_command check_http! -H 192.168.96.61 -u /horizon/ } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description cinder-api check_command check_tcp!8776 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description glance-api check_command check_tcp!9292 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description heat-api check_command check_tcp!8004 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description keystone-public check_command check_tcp!5000 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description keystone-admin check_command check_tcp!35357 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description neutron-api check_command check_tcp!9696 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description nova-api check_command check_tcp!8774 } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description ceilometer-api check_command check_tcp!8777 } #define service{ # use generic-service # host_name controller # max_check_attempts 2 # normal_check_interval 300 # retry_check_interval 15 # notification_interval 3600 # notification_period 24x7 # notification_options w,u,c,r # service_description murano # check_command check_tcp!8082 # } define service{ use generic-service host_name controller max_check_attempts 2 normal_check_interval 300 retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r service_description cloudkitty-api check_command check_tcp!8889 }
其他
1、增加验证用户也就是通过web访问nagios的时候,必须要用这个用户登陆.在这里我们增加用户test:密码为123456
[root@localhost nagios-plugins-1.4.13]# htpasswd -c /usr/local/nagios/etc/htpasswd test
可以用 which命令查看 htpasswd命令的位置,如果是源码安装的apache这里就写htpasswd的全路径。用户是test,命令结束会提示你输入密码,这里输入123456即可。
查看认证文件的内容
[root@localhost nagios-plugins-1.4.13]# less /usr/local/nagios/etc/htpasswd
到这里nagios的安装也就基本完成了,你可以通过web来访问了.
2、检测定义快捷命令
问题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/
问题解决。
3、添加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 "jinwanchiji" | sendmail fanht@longtel.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用户,如fenggong
[root@service3F-38 ~]# htpasswd /usr/local/nagios/etc/htpasswd.users fenggong
(2)更改cgi.cfg配置
[root@service3F-38 ~]# vi /usr/local/nagios/etc/cgi.cfg use_authentication=1
如果只允许查看,不允许管理,加上下面配置
authorized_for_read_only=fenggong authorized_for_all_services=fenggong authorized_for_all_hosts=fenggong
(3)将userA设为联系人
[root@service3F-38 ~]# vi /usr/local/nagios/etc/objects/contacts.cfg #添加如下配置 define contact{ contact_name fenggong use generic-contact alias fg }
(4)在属于userA的主机、服务配置文件的联系人中加入fenggong
[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 fg contact_groups sys_admins check_command check-host-alive max_check_attempts 5 notification_interval 3 notification_period 24x7 notification_options d,u,r }
(5)重启nagios后生效
[root@service3F-38 ~]# /etc/init.d/nagios restart
相关文章推荐
- centos6.8 下redis的简单配置
- Centos6.5-----nagios快速安装编译配置文档-全部虚拟环境
- centos6.5监控平台nagios搭建与配置
- 于CentOS6.8配置ISCSI-tgtd---Linux
- Linux基本操作系列(二):在CentOS 6.8系统上安装Tomcat并配置自动启动
- vmware10配置安装centos6.8
- centos6.8 mysql5.7 安装、配置、关闭密码策略、远程登录
- centos 6.8配置qq smtp邮件发送
- Centos6.8 httpd-2.2版本的虚拟主机配置
- CentOS 6.8 服务器系统安装配置图解教程
- centos6.8安装配置nginx
- Centos6.8:vsftpd安装与配置
- Centos 下面安装nagios安装和配置笔记
- Centos6.8 JDK配置
- CentOS 6.8 ftp服务安装配置 基于本地用户和虚拟用户
- centos 6.8 ssh安装及配置
- Linux基本操作系列(二):在CentOS 6.8系统上安装Tomcat并配置自动启动
- centos6.7下nagios的简单配置
- CentOS6.8配置GO语言开发环境
- Centos 5 配置nagios监控系统