如何在Ubuntu 20.04上安装Nagios
Nagios是用于监视Windows和Linux操作系统上运行的服务和应用程序的最广泛使用的开源监视工具之一。
在Nagios的帮助下,您可以监视HTTP,FTP,SSH,SMTP等基本服务,以及CPU负载,内存,磁盘使用率,登录用户,正在运行的进程等属性。
Nagios还可以监视路由器和其他网络设备。
在这里,我们将看到如何在Ubuntu 20.04上安装Nagios。
先决条件
Nagios不采用.deb软件包格式。 因此,我们需要从源代码进行编译。 安装以下用于编译Nagios的软件包。
sudo apt update
sudo apt install -y build-essential apache2 php openssl perl make php-gd libgd-dev libapache2-mod-php libperl-dev libssl-dev daemon wget apache2-utils unzip
为Nagios创建用户和组。 然后将nagios和apache用户(www-data)添加到nagcmd组的那部分中,该部分允许通过Nagios Web界面执行外部命令。
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd www-data
安装Nagios Core
下载Nagios
使用带有wget命令的终端下载Nagios核心(v4.4.5)压缩包。 另外,您可以访问官方网站以下载最新版本的Nagios core。
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz
tar -zxvf /tmp/nagios-4.4.5.tar.gz
cd /tmp/nagios-4.4.5/
编译Nagios
执行以下命令,从源代码编译Nagios。
sudo ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
sudo make all
sudo make install
sudo make install-init
sudo make install-config
sudo make install-commandmode
配置Nagios
Nagios将配置文件放在/ usr / local / nagios / etc目录中。 这些默认配置文件应该可以正常工作。
编辑/usr/local/nagios/etc/objects/contacts.cfg文件,并将与nagiosadmin联系人定义关联的电子邮件地址更改为您要用于接收警报通知的电子邮件地址。
sudo nano /usr/local/nagios/etc/objects/contacts.cfg
更改电子邮件地址字段以接收警报。
define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email [email protected] ;Install Nagios Web Interface
Install the Nagios web interface with the below command
sudo make install-webconf
创建一个用户帐户(nagiosadmin)以访问Nagios Web界面。 记住您分配给该帐户的密码-以后将需要它。
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
运行以下命令。
sudo a2enmod cgi
重新启动Apache Web服务器。
sudo systemctl restart apache2
安装Nagios插件
下载Nagios插件以监视系统服务。 将其放入/ tmp目录。
cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz tar -zxvf /tmp/nagios-plugins-2.3.3.tar.gz cd /tmp/nagios-plugins-2.3.3/
编译并安装插件。
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios sudo make sudo make install
启动Nagios
在启动之前,请先验证样本Nagios配置文件。
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output: Nagios Core 4.4.5 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 2019-08-20 License: GPL Website: https://www.nagios.org Reading configuration data... Read main config file okay... Read object config files okay... Running pre-flight check on configuration data... Checking objects... Checked 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 24 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 hosts Checked 0 service dependencies Checked 0 host dependencies Checked 5 timeperiods Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check启用Nagios服务以在系统启动时自动启动。
sudo systemctl enable nagios
现在,启动Nagios服务。
sudo systemctl start nagios
访问Nagios Web界面
现在,通过在Web浏览器中跟踪URL来访问Nagios Web界面。
http:// ip-add-re-ss / nagios /
输入您先前指定的用户名(nagiosadmin)和密码。
Nagios登录成功登录后,您将获得Nagios的主页。
Nagios工具主页单击主机以查看正在监视的服务器。
默认情况下,Nagios只能监视本地主机,即Nagios服务器。 因此,如果要监视远程计算机,则需要在远程主机上使用NRPE插件。
读:如何使用Nagios监视远程Linux主机
Nagios监视的主机单击左窗格中的“服务”以查看Nagios正在监视的服务。
Nagios监控的服务结论
就这样。 我希望到现在为止,您已经在您的Ubuntu 20.04上启动并运行了Nagios。 您可能想阅读如何使用NRPE插件监视远程Linux机器。 请在评论部分分享您的反馈。