ubuntu16.04安装配置nagios
Posted 挑战者V
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ubuntu16.04安装配置nagios相关的知识,希望对你有一定的参考价值。
参考博文:https://www.howtoing.com/ubuntu-nagios/
该博文真实有效可供参考,按照步骤,基本可以成功
一.安装的先决条件
sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd libgd-dev sendmail unzip
二.用户和组配置
useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagios,nagcmd www-data
三.安装nagios
1.下载提取Nagios核心
cd ~
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.0.tar.gz
tar -xzf nagios*.tar.gz
cd nagios-4.2.0
2.编译nagios
./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
并将evenhandler目录复制到nagios目录中:
cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
3.安装Nagios插件
下载提取nagios插件:
cd ~
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugin-2.1.2/
以下命令安装nagios插件:
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install
4.配置nagios
安装阶段完成后,您可以在/ usr / local / nagios /中找到Nagios的默认配置。
我们将配置Nagios和Nagios联系人。
使用vim编辑默认的nagios配置:
vim /usr/local/nagios/etc/nagios.cfg
取消注释线路51为主机监视器配置。
cfg_dir=/usr/local/nagios/etc/servers
保存并退出。
添加名为servers的新文件夹:
mkdir -p /usr/local/nagios/etc/servers
可以在contact.cfg文件中配置Nagios联系人。 打开它使用:
vim /usr/local/nagios/etc/objects/contacts.cfg
然后用您自己的电子邮件替换默认电子邮件。
四、配置Apache
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
service apache2 restart
service nagios start
当Nagios启动时,您可能会看到以下错误:
Starting nagios (via systemctl): nagios.serviceFailed
cd /etc/init.d/
cp /etc/init.d/skeleton /etc/init.d/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
service apache2 restart
servuce nagios start
五、测试Nagios服务器
在我的情况下,请打开浏览器并访问Nagios服务器ip: http : //192.168.126.130/nagios 。
Nagios用apache htpasswd登录
用户名默认为nagiosadmin
密码就是你之前通过执行该 sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 命令输入的密码
六、添加主机监控
在我的另外IP:192.168.126.128
连接我的另外主机
1. 连接到ubuntu主机
ssh root@192.168.126.128
2.安装NRPE服务
sudo apt-get install nagios-nrpe-server nagios-plugins
3.配置NRPE
vim /etc/nagios/nrpe.cfg
并将nagios server IP 192.168.126.130添加到server_aaddress
server_address = 192.168.126.130
4.重新启动NRPE
service nagios-nrpe-server restart
5.将Ubuntu主机添加到Nagios服务器
请连接到Nagios服务器:
ssh root@192.168.126.130
然后为/ 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.10
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/etc/objects/commands.cfg文件中找到许多check_command 。 如果您想添加更多的服务,如DHCP,POP等,请参阅
现在检查配置:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
6.重新启动所有服务
在Ubuntu主机上启动NRPE服务:
service nagios-nrpe-server restart
...在Nagios服务器上,启动Apache和Nagios:
service apache2 restart
service nagios restart
7.测试Ubuntu主机
从浏览器打开Nagios服务器,并查看受监控的ubuntu_host。
Ubuntu主机在受监控的主机上可用。
以上是关于ubuntu16.04安装配置nagios的主要内容,如果未能解决你的问题,请参考以下文章