如何在 Ubuntu 15.04 上安装 Nagios 4.0.8如何在 Ubuntu 15.04 上安装 Nagios 4.0.8如何在 Ubuntu 15.04 上安装 Nagios 4.0.8如何在 Ubuntu 15.04 上安装 Nagios 4.0.8
  • 文章
  • 正则表达式
    • 工具
  • 登录
找到的结果: {phrase} (显示: {results_count} 共: {results_count_total})
显示: {results_count} 共: {results_count_total}

加载更多搜索结果...

搜索范围
模糊匹配
搜索标题
搜索内容
发表 admin at 2025年2月28日
类别
  • 未分类
标签

如何在 Ubuntu 15.04 上安装 Nagios 4.0.8

本教程适用于这些操作系统版本

  • Ubuntu 10.04 (Lucid Lynx)

在此页

  1. 先决条件
    1. 我们将在本教程中做什么:

    1. 第 1 步 - 下载并解压
    2. 第 2 步 - 编译 Nagios
    3. 第 3 步 - 安装 Nagios 插件
    4. 第 4 步 - 配置 Nagios

    1. 第 1 步 - 启用 Apache 模块
    2. 第 2 步 - 启用 Nagios 虚拟主机
    3. 第 3 步 - 启动 Apache 和 Nagios

    1. 第 1 步 - 连接到 ubuntu 主机
    2. 第 2 步 - 安装 NRPE 服务
    3. 第 3 步 - 配置 NRPE
    4. 第 4 步 - 重启 NRPE
    5. 第 5 步 - 将 Ubuntu 主机添加到 Nagios Server
    6. 第 6 步 - 重新启动所有服务
    7. 第 7 步 - 测试 Ubuntu 主机

    Nagios 是一个用于系统和网络监控的开源软件。 Nagios 可以查看主机及其服务的活动,并在服务器发生问题时提供警告/警报。 Nagios 可以在 Linux 操作系统上运行。此时我们使用Ubuntu 15.04进行安装。

    先决条件

    • Ubuntu 15.04 - 64 位
    • 根/Sudo 权限

    我们将在本教程中做什么:

    1. 需要安装包 - LAMP 等。
    2. 用户和组配置
    3. 安装 Nagios
    4. 配置阿帕奇
    5. 测试 Nagios 服务器
    6. 添加要监控的主机

    安装包

    Nagios 需要 gcc/build-essential 用于编译,LAMP(Apache,PHP,MySQL)用于 Nagios web base 和 Sendmail 从服务器发送警报。要安装所有这些包和一些额外的包:

    apt-get install apache2 libapache2-mod-php5 build-essential libgd2-xpm-dev libssl-dev sendmail-bin sendmail heirloom-mailx wget apache2-utils curl daemon apt-file libnet-snmp-perl libpq5 libsensors4 libsnmp-base libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois mrtg libcgi-pm-perl librrds-perl libgd-gd2-perl libmysqlclient-dev libperl5.20 libmysqlclient18 libradiusclient-ng2

    用户和组配置

    要运行 Nagios,您必须为 Nagios 创建一个新用户。我们将用户命名为 \nagios\ 并另外创建一个名为 \nagcmd\ 的组。现在我们将新用户添加到组中,如下所示:

    useradd nagios
    groupadd nagcmd
    usermod -a -G nagcmd nagios

    安装 Nagios

    第 1 步 - 下载并解压

    cd ~
    wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
    tar -xzf nagios*.tar.gz
    cd nagios-4.0.8/

    第 2 步 - 编译 Nagios

    在构建 Nagios 之前,您需要使用您之前创建的用户和组对其进行配置。

    ./configure --with-nagios-group=nagios --with-command-group=nagcmd

    有关更多信息,请使用:./configure --help。

    现在安装 Nagios:

    make all
    sudo make install
    sudo make install-commandmode
    sudo make install-init
    sudo make install-config
    /usr/bin/install -c -m 644 sample-config/httpd.conf
    /etc/apache2/sites-available/nagios.conf

    第 3 步 - 安装 Nagios 插件

    下载并解压nagios插件:

    cd ~
    wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
    tar -xzf nagios-plugins*.tar.gz
    cd nagios-plugin*/

    请按上述操作:

    ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
    make && make install

    第 4 步 - 配置 Nagios

    安装阶段完成后,可以在/usr/local/nagios/中找到Nagios的默认配置。

    现在配置 nagios 与您的电子邮件联系。

    vim /usr/local/nagios/etc/nagios.cfg

    取消注释行 cfg_dir=/usr/local/nagios/etc/servers

    并添加一个名为服务器的新文件夹:

    mkdir -p /usr/local/nagios/etc/servers

    Nagios 联系人可以在 contact.cfg 文件中配置。要打开它,请使用:

    vim /usr/local/nagios/etc/objects/contacts.cfg

    然后用您自己的电子邮件替换默认电子邮件。

    配置阿帕奇

    第 1 步 - 启用 Apache 模块

    sudo a2enmod rewrite
    sudo a2enmod cgi

    您可以使用 htpasswd 为 nagios web 界面配置用户 nagiosadmin

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

    并输入您的密码。

    第 2 步 - 启用 Nagios 虚拟主机

    sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/

    第 3 步 - 启动 Apache 和 Nagios

    /etc/init.d/apache2 restart
    /etc/init.d/nagios start

    当 Nagios 启动时,您可能会看到以下错误:

    Starting nagios (via systemctl): nagios.serviceFailed

    这是解决方法:

    cd /etc/init.d/
    cp /etc/init.d/skeleton /etc/init.d/nagios

    现在编辑 Nagios 文件:

    vim /etc/init.d/nagios

    ...并添加以下代码:

    DESC="Nagios"
    NAME=nagios
    DAEMON=/usr/local/nagios/bin/$NAME
    DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
    PIDFILE=/usr/local/nagios/var/$NAME.lock

    使其可执行并启动 Nagios:

    chmod +x /etc/init.d/nagios
    /etc/init.d/apache2 restart
    /etc/init.d/nagios start

    测试 Nagios 服务器

    请打开浏览器访问已经安装的Nagios服务器ip。 http://192.168.1.101/nagios。

    添加主机监控

    在本教程中,您将添加一个 Ubuntu 主机来监控我们上面制作的 Nagios 服务器。

    Nagios Server IP : 192.168.1.101
    Ubuntu Host IP : 192.168.1.102

    第 1 步 - 连接到 ubuntu 主机

    ssh 

    第 2 步 - 安装 NRPE 服务

    sudo apt-get install nagios-nrpe-server nagios-plugins

    第 3 步 - 配置 NRPE

    安装完成后,编辑nrpe文件/etc/nagios/nrpe.cfg:

    vim /etc/nagios/nrpe.cfg

    ...并将 Nagios 服务器 IP 192.168.1.101 添加到 server_address。

    第 4 步 - 重启 NRPE

    /etc/init.d/nagios-nrpe-server restart

    第 5 步 - 将 Ubuntu 主机添加到 Nagios 服务器

    请连接到 Nagios 服务器:

    ssh 

    然后在 /usr/local/nagios/etc/servers/ 中为主机配置创建一个新文件。

    vim /usr/local/nagios/etc/servers/ubuntu_host.cfg

    添加以下行:

    # Ubuntu Host configuration file
    
    define host {
            use                          linux-server
            host_name                    ubuntu_host
            alias                        Ubuntu Host
            address                      192.168.1.102 #Ubuntu host IP
            register                     1
    }
    
    define service {
          host_name                       ubuntu_host
          service_description             PING
          check_command                   check_ping!100.0,20%!500.0,60%
          max_check_attempts              2
          check_interval                  2
          retry_interval                  2
          check_period                    24x7
          check_freshness                 1
          contact_groups                  admins
          notification_interval           2
          notification_period             24x7
          notifications_enabled           1
          register                        1
    }
    
    define service {
          host_name                       ubuntu_host
          service_description             Check Users
          check_command		      check_local_users!20!50
          max_check_attempts              2
          check_interval                  2
          retry_interval                  2
          check_period                    24x7
          check_freshness                 1
          contact_groups                  admins
          notification_interval           2
          notification_period             24x7
          notifications_enabled           1
          register                        1
    }
    
    define service {
          host_name                       ubuntu_host
          service_description             Local Disk
          check_command                   check_local_disk!20%!10%!/
          max_check_attempts              2
          check_interval                  2
          retry_interval                  2
          check_period                    24x7
          check_freshness                 1
          contact_groups                  admins
          notification_interval           2
          notification_period             24x7
          notifications_enabled           1
          register                        1
    }
    
    define service {
          host_name                       ubuntu_host
          service_description             Check SSH
          check_command                   check_ssh
          max_check_attempts              2
          check_interval                  2
          retry_interval                  2
          check_period                    24x7
          check_freshness                 1
          contact_groups                  admins
          notification_interval           2
          notification_period             24x7
          notifications_enabled           1
          register                        1
    }

    您可以在 /usr/local/nagios/etc/objects/commands.cfg 文件中找到许多 check_command。如果您想添加更多服务,如 DHCP、POP 等,请参阅此处。

    现在检查配置:

    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    ...查看配置是否正确。

    第 6 步 - 重新启动所有服务

    在 Ubuntu 主机上启动 NRPE 服务:

    /etc/init.d/nagios-nrpe-server restart

    ...在 Nagios 服务器上,启动 Apache 和 Nagios:

    /etc/init.d/apache2 restart
    /etc/init.d/nagios restart

    第 7 步 - 测试 Ubuntu 主机

    从浏览器打开Nagios服务器,可以看到被监控的ubuntu_host。

    结论

    Nagios 是一个用于监控系统的开源应用程序。 Nagios 因其易于配置而被广泛使用。 Nagios 由各种插件支持,您甚至可以创建自己的插件。在这里查看更多信息。

©2015-2025 艾丽卡 support@alaica.com