Nagios+Apache+Nagios-nrpe-server 配置安装

版本信息


Ubuntu 16.04

 

参考文献


https://www.howtoforge.com/tutorial/ubuntu-nagios/

   

安装依赖


 sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip

 

添加group和user


 

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data

 

安装 Nagios


  • Step 1 下载源码&解压:

cd /usr/local
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
tar -xzvf nagios-4.2.0.tar.gz

  • Step 2 编译&安装

cd nagios-4.2.0
./configure --with-nagios-group=nagios --with-command-group=nagcmd
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

  • Step 3 复制文件到目录下&修改权限
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

 

  • Step 4 安装nagios补丁文件

  下载&解压

 

wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins-2.1.2.tar.gz
 
  编译&安装
cd nagios-plugin-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install

 

  • Step 5 配置nagios文件

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

  去掉原文件里面下面内容前面的"#"

cfg_dir=/usr/local/nagios/etc/servers

  # 保存退出

  # 新建文件夹

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

  # 修改contacts.cfg配置文件

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

  

  

配置Apache


 

  • Step 1 启动Apache模块

sudo a2enmod rewrite
sudo a2enmod cgi

  • Step 2  创建密码&用户名

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

  • Step 3 启用Nagios虚拟主机

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

  • Step 4 开启Apache和Nagios  

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
  • Step 5 使之可执行并开启服务

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

 

  # 若nagios开启失败,可尝试下面的方法:

/etc/init.d/nagios start

  • Step 6 开启成功后,可用网页进行查看

  输入网址:http://192.168.3.12/nagios
  弹出登录的框框

  用户名:nagiosadmin
  密    码:justdoit

  

 

将主机添加到监视器


 

  因为只有一台服务器,尝试可否在同台电脑上配置nagios服务

Nagios Server IP : 192.168.3.12
Ubuntu Host IP : 192.168.3.12

  • Step 1 在主机上安装NRPE Service

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

  • Step 2 配置 NRPE

vim /etc/nagios/nrpe.cfg

  # 在server_address添加Nagios Server IP 192.168.3.12

  

  • Step 3 开启 NRPE

sudo /etc/init.d/nagios-nrpe-server start

  # 注(NRPE之关闭和重启):      

# 不用操作

sudo /etc/init.d/nagios-nrpe-server stop

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

  • Step 4 在主机上添加Nagios Server  

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.3.12    #请注意要换为被监听计算机的id
    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
}

define service {
    host_name               ubuntu_host
    service_description     Total Process
    check_command           check_local_procs!250!400!RSZDT
    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/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

  

  • Step 6 重启各种服务

  #  NRPE Service:

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

  #  Apache and Nagios

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

  • Step 7 测试是否配置成功

  

 

总结


这个样子好像就是配置成功了吧!自己半道出家,对这些还不太了解具体是搞毛的,说不出123来。但是,看结果应该是完成了检测的功能。
应该就是可以在同台计算机上配置这个冬冬了,那么,在两台电脑上配置的话,把被检测计算机的id换上就应该没问题了。


   People people for me , me for people people!!

 

 

posted on 2018-07-20 22:15  董大志  阅读(191)  评论(0)    收藏  举报

导航