linux环境中nagios(nagios core)安装?nagios安装?

需求描述:

  最近准备给线上生产环境部署监控平台,对各个系统的资源使用情况,服务进行监控,采用nagios core版本进行部署,

  nagios core是开源版本的软件,是免费的nagios XI是上夜班.

环境信息:

  操作系统版本:RedHat 6.6 x64

安装过程:

1.将SElinx设置为disabled或者permissive

[root@testvm02 ~]# sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
[root@testvm02 ~]# getenforce
Permissive

2.安装依赖的软件包

yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix

3.下载,上传nagios-core的软件包

下载地址:

https://www.nagios.org/downloads/nagios-core/thanks/?skip=1&product_download=nagioscore-source

本例安装的版本:

nagios-4.4.1.tar.gz
上传软件到指定的目录中:

[root@testvm02 ~]# cd /opt/softwares/;ls -l                     #实际情况中可以上传软件到自己指定的目录中.
total 11032
-rw-r--r--. 1 root root 11296403 Jul 31 11:24 nagios-4.4.1.tar.gz

4.解压,编译,安装

[root@testvm02 nagios-4.4.1]# tar zxf nagios-4.4.1.tar.gz
[root@testvm02 nagios-4.4.1]# cd nagios-4.4.1
[root@testvm02 nagios-4.4.1]# ./configure
[root@testvm02 nagios-4.4.1]# make all

5.创建用户,用户组

[root@testvm02 nagios-4.4.1]# make install-groups-users
groupadd -r nagios
useradd -g nagios nagios
[root@testvm02 nagios-4.4.1]# usermod -a -G nagios apache
[root@testvm02 nagios-4.4.1]# id nagios
uid=500(nagios) gid=499(nagios) groups=499(nagios)
[root@testvm02 nagios-4.4.1]# id apache
uid=48(apache) gid=48(apache) groups=48(apache),499(nagios

6.创建二进制命令,CGI,html文件

[root@testvm02 nagios-4.4.1]# make install

7.安装相关的进程文件(安装启动脚本),增加httpd开机启动,nagios开机启动

[root@testvm02 nagios-4.4.1]# make install-daemoninit
/usr/bin/install -c -m 755 -d -o root -g root /etc/init.d
/usr/bin/install -c -m 755 -o root -g root startup/default-init /etc/init.d/nagios

*** Init script installed ***

[root@testvm02 nagios-4.4.1]# chkconfig --level 2345 httpd on
[root@testvm02 nagios-4.4.1]# chkconfig --list | grep httpd
httpd              0:off    1:off    2:on    3:on    4:on    5:on    6:off
[root@testvm02 nagios-4.4.1]# chkconfig --list | grep nagios
nagios             0:off    1:off    2:on    3:on    4:on    5:on    6:off

8.安装外部命令文件

[root@testvm02 nagios-4.4.1]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw

*** External command directory configured ***

9.安装配置文件

[root@testvm02 nagios-4.4.1]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

*** Config files installed ***

Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

备注:这些都是一些示例配置文件,同时比如nagios.cfg在启动nagios的时候需要使用到.

10.安装apache配置文件即httpd配置文件

[root@testvm02 nagios-4.4.1]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
if [ 0 -eq 1 ]; then \
        ln -s /etc/httpd/conf.d/nagios.conf /etc/apache2/sites-enabled/nagios.conf; \
    fi

*** Nagios/Apache conf file installed ***

11.配置防火墙或者关闭防火墙

配置允许8端口进入:
iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT service iptables save
关闭防火墙,关闭开机启动:

service iptables stop
[root@testvm02 nagios-4.4.1]# chkconfig --level 2345 iptables off
[root@testvm02 nagios-4.4.1]# chkconfig --list | grep iptables
iptables           0:off    1:off    2:off    3:off    4:off    5:off    6:of

12.创建nagios管理账号

[root@testvm02 nagios-4.4.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:                           #输入新密码
Re-type new password:                   #再次输入密码,进行确认
Adding password for user nagiosadmin

13.启动apache服务,nagios core服务

[root@testvm02 nagios-4.4.1]# service httpd start
[root@testvm02 nagios-4.4.1]# service nagios start

14.通过页面进行访问测试

访问地址:http://192.168.53.25/nagios    输入nagios管理账号,密码进行登录.

 登录成功之后,页面如下:

查看Hosts,Services有如下的报错:

备注:以上错误提示,表示没有某些命令,即在/usrlocal/nagios/libexex中灭有命令,需要安装nagios-plugins来安装相应的命令

15.下载,上传nagios-plugins压缩包

下载地址:

https://www.nagios.org/downloads/nagios-plugins/

 软件包:nagios-plugins-2.2.1.tar.gz

[root@testvm02 softwares]# cd /opt/softwares/;ls -l nagios-plugins*
-rw-r--r--. 1 root root 2728818 Jul 31 12:25 nagios-plugins-2.2.1.tar.gz

16.安装依赖的软件包,解压,编译,安装

yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils
[root@testvm02 softwares]# tar zxf nagios-plugins-2.2.1.tar.gz 
[root@testvm02 softwares]# cd nagios-plugins-2.2.1
[root@testvm02 nagios-plugins-2.2.1]# ./configure 
[root@testvm02 nagios-plugins-2.2.1]# make
[root@testvm02 nagios-plugins-2.2.1]# make install

备注:插件安装完成

17.重新在nagios页面进行测试,在HOSTS中的localhost的命令菜单中点击."Re-schedule the next check",查看hosts状态

备注:说明命令已经成功,对于services中的检查,也会在一定时间之后,达到调度时间进行状态的修改.

Servies的状态:

18.针对HTTP的检查,在本地的/var/www/html中创建index.html文件就可以解决这个警告

[root@testvm02 libexec]# cd /var/www/html/
[root@testvm02 html]# touch index.html

 配置完成之后,http服务的状态:

到此,所有的nagios-core,nagios-plugins已经安装完成!

文档创建时间:2018年7月31日12:58:55

猜你喜欢

转载自www.cnblogs.com/chuanzhang053/p/9395306.html