Nagios 安装

2015-11-27

目录

1.关闭防火墙

2.配置yum仓库

3.安装基础包

4.安装apache和php

5.安装nagios(主程序)

6.安装nagiosQL(nagios的web管理工具)

7.安装nagios-plugin(nagios插件)

8.安装NRPE(nagios插件)

1.关闭防火墙

service iptables stop
service iptables status
setenforce 0
getenforce

2.配置yum仓库

#!/bin/bash
### AUTHOR: Leo
### DATE: 2015/10/25
### NAME:yum.sh
### DESC:配置yum仓库
wget http://mirrors.opencas.cn/epel/epel-release-latest-6.noarch.rpm
wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
rpm -ivh epel-release-latest-6.noarch.rpm
rpm -ivh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum clean all && yum makecache
cd /etc/yum.repos.d && ls -hl

3.安装基础包

yum install -y cpp gcc-c++ gcc glibc glibc-common gd gd-devel xinetd openssl- devel fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD mailx postfix libstdc++ glib2-devel

4.安装apache和php

yum -y install httpd php php-mysql php-gd php-devel php-ldap php-xml php-mbstring
#修改apache的主配置文件/etc/httpd/conf/httpd.conf
User nagios
Group nagios
ServerName localhost:80
DocumentRoot "/var/www/html"
DirectoryIndex index.php index.html
AddHandler php5-script .php
AddType text/html .php
AddType application/x-httpd-php .php
#重启apache服务
service httpd restart
#测试访问
vim /var/www/html/index.html
this is a test !
curl 10.10.2.89
http://10.10.2.89/

vim /var/www/html/index.php
<?php
phpinfo();
?>
curl 10.10.2.89
http://10.10.2.89/

5.安装nagios(主程序)

#创建用户nagios、apache
useradd -M -s /sbin/nologin nagios
useradd apache
#创建用户组nagcmd,用于从Web 接口执行外部命令
groupadd nagcmd
#添加nagios 和apache 用户到该组
usermod -G nagcmd apache
usermod -a -G nagcmd nagios
#创建目录
mkdir /usr/local/nagios
#修改属主
chown -R nagios.nagios /usr/local/nagios
#下载nagios源码包
wget http://nchc.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.1.1/nagios-4.1.1.tar.gz
#解压nagios源码包
tar -zxf nagios-4.1.1.tar.gz -C /usr/local/src/ && cd /usr/local/src/nagios-4.1.1
#配置环境
./configure --with-group=nagios --with-user=nagios --with-command-group=nagcmd --with-gd-lib=/usr/lib --with-gd-inc=/usr/include

*** Configuration summary for nagios 4.1.1 08-19-2015 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagcmd
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /bin/traceroute

#编译安装
make all && make install
#生成init 启动脚本
make install-init
#设置相应的目录权限
make install-commandmode
#生成模板配置文件
make install-config
#生成apache 配置文件
make install-webconf
/etc/httpd/conf.d/nagios.conf
#设置启动级别,并启动服务
chkconfig --add nagios &&chkconfig --level 35 nagios on && service nagios start
#验证Nagios配置文件的正确性
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0
#添加apache访问用户nagiosadmin,密码nagiosadmin
htpasswd -bc /usr/local/nagios/etc/htpasswd.users nagiosadmin nagiosadmin
#重启apache和nagios服务
service nagios restart
service httpd restart
#使用物理机浏览器测试访问nagios:
http://10.10.2.89/nagios
用户nagiosadmin,密码nagiosadmin

6.安装nagiosQL(nagios的web管理工具)

#安装mysql
yum -y install mysql mysql-server mysql-devel
#下载nagiosql源码包
wget http://nchc.dl.sourceforge.net/project/nagiosql/nagiosql/NagiosQL%203.2.0/nagiosql_320.tar.gz
#解压nagiosql源码包到/usr/local/nagios目录下
tar -zxf nagiosql_320.tar.gz && cp -a nagiosql32 /usr/local/nagios/nagiosql
#建立nagiosQL导出nagios配置文件的目录,并修改权限,否则在浏览器进行网页上安装会报错
chown -R nagios:nagios /usr/local/nagios/nagiosql
chmod 777 /usr/local/nagios/nagiosql/config/
mkdir -p /usr/local/nagios/nagiosql/etc/{hosts,services,backup,import}
mkdir -p /usr/local/nagios/nagiosql/etc/backup/{hosts,services}
chown -R nagios:nagios /usr/local/nagios/nagiosql/
#修改/etc/httpd/conf.d/nagios.conf,添加如下内容:
Alias /nagiosQL "/usr/local/nagios/nagiosql"
<Directory "/usr/local/nagios/nagiosql">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
#修改php.ini的timezone
date.timezone = Asia/ShangHai
#修改php会话权限
chmod 777 /var/lib/php/session/
#赋予mysql的root用户远程访问和grant权限
mysql -uroot -ppro#pateo
mysql> grant all on *.* to [email protected]‘%‘ identified by ‘pro#pateo‘ with grant option;
mysql> flush privileges;
#重启apache服务
service httpd restart
#物理机浏览器测试访问nagiosql并安装
http://10.10.2.89/nagiosQL
用户admin,密码amdin

7.安装nagios-plugin(nagios插件)

#安装基础包
yum -y install perl perl-devel nagios-plugins nagios-plugins-ntp-perl perl-CPAN perl-Nagios-Plugin perl-Regexp-Common
cpan[1]> install Nagios:Plugin
cpan[1]> install Regexp:Common
#下载nagios-plugins源码包
wget http://nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz
#解压nagios-plugins源码包
tar -zxf nagios-plugins-2.1.1.tar.gz -C /usr/local/src/ && cd /usr/local/src/nagios-plugins-2.1.1
#配置环境
./configure --help
./configure --prefix=/usr/local/nagios/ --enable-perl-modules
#编译安装
make && make install
#替换插件包libexec
cd /usr/local/nagios/ && mv libexec/ libexec.bak && tar -zxf /root/libexec.tar.gz -C ./
chown -R nagios:nagios /usr/local/nagios/libexec
#检测iostat命令
/usr/local/nagios//libexec/check_iostat -w 15
IOSTAT OK - user 0.79 nice 0.00 sys 0.21 iowait 0.26 idle 0.00  | iowait=0.26%;; idle=0.00%;; user=0.79%;; nice=0.00%;; sys=0.21%;;
#检测cpu命令
/usr/local/nagios//libexec/check_cpu.sh -w 85 -c 95
CPU OK : user=0% system=0% iowait=0% idle=100% | cpu_user=0%;85;95; cpu_sys=0%;85;95; cpu_iowait=0%;85;95; cpu_idle=100%;
#检测memory命令
/usr/local/nagios//libexec/check_memory.sh -w 85 -c 90
MEMORY - OK used=50% idle=50% | ‘MEMORY Usage‘=50%;85;90;
#检测disk命令
/usr/local/nagios//libexec/check_disk -w 20 -c 15
DISK OK - free space: / 76692 MB (83% inode=97%); /dev/shm 1441 MB (100% inode=99%); /boot 110 MB (61% inode=99%);| /=14837MB;96414;96419;0;96434 /dev/shm=0MB;1421;1426;0;1441 /boot=69MB;169;174;0;189

8.安装NRPE(nagios插件)

#安装基础包
yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel
#下载NRPE源码包
wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
#解压NRPE源码包
tar -zxf nrpe-2.15.tar.gz -C /usr/local/src/ && cd /usr/local/src/nrpe-2.15
#配置环境
./configure --help
./configure --prefix=/usr/local/nagios --enable-command-args
#编译
make all
#安装
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
#配置NRPE监控IP
vim /etc/xinetd.d/nrpe
        only_from       = 127.0.0.1 10.10.2.89
#添加NRPE服务端口5666
echo ‘nrpe            5666/tcp                        #NRPE‘>>/etc/services
#重启xinetd服务
chkconfig xinetd on && service xinetd restart
#验证端口5666
netstat -an|grep 5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN
#修改命令定义文件commands.cfg,添加check_nrpe命令
vim /usr/local/nagios/etc/objects/commands.cfg
define command{
        command_name check_nrpe
        command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
#复制nrpe.cfg文件到/usr/local/nagios/etc目录
cd /usr/local/nagios/etc/ && mv nrpe.cfg nrpe.cfg.bak
cp /root/nrpe.cfg /usr/local/nagios/etc/
chown nagios:nagios nrpe.cfg
#重启nagios服务
service nagios restart
#检测NRPE命令
/usr/local/nagios/libexec/check_nrpe -H localhost或/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1
NRPE v2.15
时间: 2024-09-30 15:36:49

Nagios 安装的相关文章

Nagios安装部署

p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; line-height: 150%; font-size: 13.5pt; font-family: "Calibri", "sans-serif" } h1 { margin-top: 17.0pt; margin-right: 0cm; margin-bottom: 16.5pt; margin-left:

Nagios+Cacti+PNP4Nagios+NConf+NDOUtils+Nagvis(一)nagios安装

1.nagios安装 groupadd nagios useradd -g nagios nagios mkdir -p /usr/local/nagios/ passwd nagios tar -xvf nagios-4.0.8.tar.gz cd nagios-4.0.8 ./configure --prefix=/usr/local/nagios/ --with-command-group=nagios --with-nagios-user=nagios --with-nagios-gro

nagios安装与使用

Nagios 支持短信,邮件通知 Nagios官网 http://www.nagios.org1. Nagios安装 - 服务端(192.168.0.11)Centos6默认的yum源里没有nagios相关的rpm包,但是我们可以安装一个epel的扩展源: yum install -y epel-release然后安装nagios相关的包yum install -y httpd nagios nagios-pluginsnagios-plugins-all nrpe nagios-plugins

监控和安全运维 1.4 nagios安装

1. Nagios 简介是一个开源软件,可以监控网络设备网络流量.Linux/windows主机状态,甚至可以监控打印机它可以运行在Linux上或windows上基于浏览器的web界面方便运维人员查看监控项目的状态支持web界面配置.管理操作支持短信.邮件通知可以自定义脚本实现自定义化监控Nagios官网 http://www.nagios.org 2. Nagios安装 - 服务端(192.168.1.117)Centos6默认的yum源里没有nagios相关的rpm包,但是我们可以安装一个e

nagios 安装配置说明(一)

Nagios安装配置说明 修改YUM源为国内sohu的站点: [[email protected] ~]# cd/etc/yum.repos.d/ [[email protected] yum.repos.d]# ls CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo [[email protected] yum.repos.d]# mvCentOS-Base.repo CentOS-Bas

Nagios安装说明

*****Nagios安装思路*****详情参照55DAY***** 一.Nagios服务端安装 1.安装所需依赖关系包 2.添加Nagios所需用户及组 3.编译安装Nagios及创建登陆Nagios WEB程序用户 4.Nagios-plugin(插件) 5.配置服务自启动 二.基于NRPE配置Nagios监控Win主机 1.被监控端 安装:NSClient++-0.3.9-x64 2.监控端 1.测试与被监控端连通性 2.监控端定义命令.定义主机.定义服务 3.将定义好的模板加入到nagi

Nginx+nagios安装配置

Nginx+nagios安装配置 [[email protected] ~]# vi /etc/nginx/nginx.conf server { listen 80; server_name localhost; auth_basic "Nagios Access"; auth_basic_user_file /usr/local/nagios/passwd; location / { root /usr/local/nagios/share; index index.html in

linux上nagios安装完整版

监控server端的安装部署一.apache的安装下载httpd-2.2.15.tar.gz gunzip httpd-2.2.15.tar.gztar xvf httpd-2.2.15.tarcd httpd-2.2.15./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --enable-cgi --enable-rewrite --enable-deflate --with-mpm=wor

nagios安装配置报警监控搭建

1. Nagios 简介是一个开源软件,可以监控网络设备网络流量.Linux/windows主机状态,甚至可以监控打印机它可以运行在Linux上或windows上基于浏览器的web界面方便运维人员查看监控项目的状态支持web界面配置.管理操作支持短信.邮件通知可以自定义脚本实现自定义化监控Nagios官网 http://www.nagios.org 2. Nagios安装 - 服务端(192.168.0.11)Centos6默认的yum源里没有nagios相关的rpm包,但是我们可以安装一个ep

Linux监控和安全运维---nagios安装及部署

nagios安装 [[email protected] ~]# rpm -ivh http://www.aminglinux.com/bbs/data/attachment/forum/month_1211/epel-release-6-7.noarch.rpm [[email protected] ~]# yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe [[email