如何在Linux中设置Naemon网络监控工具
Naemon是一个开源系统和网络监视应用程序,它监视我们指定的主机和其他服务,当情况变差时提醒我们,并在情况变好时通知我们。
Naemon基于Nagios 4.0.2,旨在取代Nagios。
Naemon Suite当前大致等效于Nagios Core,这使Naemon Core等效于“ Nagios Core Core”。
Naemon是整个“ Naemon Suite”的总称,它由两个不同的部分组成,即Naemon Core和Thruk Monitoring Web界面。
我们通常将naemon Suite简称为Naemon。
在本文中,我们将把naemon安装在centos 7和ubuntu 16.04中,并通过NPRE探索它在Centos中的用法。
组件
Naemon具有四个组件,分别是Naemon核心,Livestatus,Thruk和插件。
Naemon核心:naemon核心是对系统进行实际监视的过程。
Livestatus:Livestatus是一个界面,工具可以使用该界面来查询Naemon核心(如数据库)。
Thruk:Thruk是Naemon Suite附带的Web UI。
插件:Naemon运行这些插件来确定网络上主机和服务的当前状态。
监视插件项目中提供了维护良好的插件集合。
在Ubuntu 16中安装Naemon
要在Ubuntu 16中安装naemon,我们首先需要安装其依赖项。
通过在终端中执行以下命令来安装naemon依赖项。
# sudo apt-get install bsd-mailx apache2 apache2-utils libapache2-mod-fcgid libfontconfig1 libjpeg62 libgd3 libxpm4 xvfb libmysqlclient20
将Consol Labs存储库添加到apt数据库。
# gpg --keyserver keys.gnupg.net --recv-keys F8C1CA08A57B9ED7 # gpg --armor --export F8C1CA08A57B9ED7 | apt-key add # echo "deb http://labs.consol.de/repo/stable/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/labs-consol-stable.list
现在更新apt数据库。
# sudo apt-get update
安装Naemon,Nagios插件将与naemon一起安装。
# sudo apt-get install naemon
更改Nagios插件的路径
# sudo vi /etc/naemon/resource.cfg
找到$USER1 $=/usr/lib/naemon/plugins并将其替换为$USER1 $=/usr/lib/nagios/plugins
使用以下命令更改Thruk Web UI的默认密码。
# htpasswd /etc/thruk/htpasswd thrukadmin New password: Re-type new password: Updating password for user thrukadmin
重新启动Apache和Naemon
# sudo service naemon restart # sudo service apache2 restart
现在,我们可以通过将喜欢的浏览器指向http://SERVER-IP/naemon来访问Naemon Web UI。
使用用户名作为thrukadmin和我们在先前步骤中创建的密码登录。
在CentOS 7中安装Naemon
将consol实验室存储库添加到yum数据库
# rpm -Uvh "https://labs.consol.de/repo/stable/rhel7/i386/labs-consol-stable.rhel7.noarch.rpm"
安装naemon
# yum install naemon*
禁用SELINUX并使其持久。
# setenforce 0 # vi /etc/selinux/config
现在,编辑行:“ SELINUX = enforcing”并替换为:“ SELINUX = disabled”
对于nagios插件,请安装EPEL存储库。
下一步安装nagios插件和nrpe
# yum install epel-release # yum install nagios-plugins nagios-plugins-all nagios-plugins-nrpe nrpe
启用apache和naemon
# systemctl enable httpd Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. # systemctl enable naemon Created symlink from /etc/systemd/system/multi-user.target.wants/naemon.service to /usr/lib/systemd/system/naemon.service.
启动Apache和naemon
# systemctl start httpd # systemctl start naemon
在系统启动期间启用thruk
# systemctl enable thruk thruk.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig thruk on
启动thruk
# service thruk start Starting thruk.....( 11192) OK
使用以下命令更改Thruk Web UI的默认密码。
# htpasswd /etc/thruk/htpasswd thrukadmin New password: Re-type new password: Updating password for user thrukadmin
现在,我们可以通过将喜欢的浏览器指向http://SERVER-IP/naemon来访问Naemon Web UI。
现在我们已经有一个运行在网络中的naemon服务器,我们想要添加一个远程Linux主机以通过naemon服务器进行监视。
为此,我们需要在远程系统/客户端中安装nagios插件和Nagios远程插件执行器,例如:nrpe。
Nagios插件允许naemon服务器在远程Linux/Unix主机上远程执行插件。
我们的设置如下所示
系统 | IP地址 | 主机名 |
---|---|---|
Naemon Server(CentOS 7) | 10.0.0.55 | Naemon-Server |
远程主机/客户(CentOS 7) | 10.0.0.38 | node01 |
配置远程CentOS 7主机/客户端(10.0.0.38)
首先更新远程主机/客户端
# yum update
安装EPEL存储库。
# yum install epel-release
下一步安装nagios-plugins,openssl和nrpe
# yum install nrpe nagios-plugins-all openssl
列出所有可用的nagios插件。
# ls -l /usr/lib64/nagios/plugins/
转到nagios配置目录,然后编辑nrpe.cfg。
将naemon服务器的IP添加到allowed_hosts,指定我们选择的server_port,将command_timeout设置为60,将connection_timeout设置为300。
其余配置值保持不变。
# cd /etc/nagios/ # vi nrpe.cfg log_facility=daemon pid_file=/var/run/nrpe/nrpe.pid server_port=5666 #server_address=127.0.0.1 nrpe_user=nrpe nrpe_group=nrpe allowed_hosts=127.0.0.1,10.0.0.55 dont_blame_nrpe=0 allow_bash_command_substitution=0 # command_prefix=/usr/bin/sudo debug=1 command_timeout=60 connection_timeout=300 #allow_weak_random_seed=1 #include=<somefile.cfg> command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10 command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1 command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200 #command[check_users]=/usr/lib64/nagios/plugins/check_users -w $ARG1$-c $ARG2$ #command[check_load]=/usr/lib64/nagios/plugins/check_load -w $ARG1$-c $ARG2$ #command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w $ARG1$-c $ARG2$-p $ARG3$ #command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$-c $ARG2$-s $ARG3$ include_dir=/etc/nrpe.d/
重新启动NPRE
# systemctl start nrpe
使用netstat,了解npre是否正在侦听端口5666
# netstat -pltn
允许防火墙允许流量进入端口5666
对于防火墙用户
# firewall-cmd --permanent --add-port=5666/tcp # firewall-cmd --reload
对于IPTABLE用户
# iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT # service iptables save # service iptables restart
NPRE现在将能够接受来自naemon服务器的请求以执行命令并将结果发送给它。
配置Naemon服务器(10.0.0.55)
我们已经在步骤1中安装了naemon服务器。
现在让我们定义服务器中主机,服务和命令的配置。
检查/etc/naemon/conf.d/templates目录中用于主机和服务的模板。
当监视实例的数量增加时,可以分别为主机和服务创建配置文件。
对于本教程,我们将主机和服务配置保留在同一文件中,例如:在node01.cfg中
# cd /etc/naemon/conf.d # vi /etc/naemon/conf.d/node01.cfg define host{ use linux-server host_name node01 alias node01 address 10.0.0.55 } define service{ use generic-service host_name node01 service_description PING check_command check_ping!100.0,20%!500.0,60% } define service{ use generic-service host_name node01 service_description Current Load check_command check_nrpe!check_load } define service{ use generic-service host_name node01 service_description Total Processes check_command check_nrpe!check_users }
编辑commands.cfg文件,以便nrpe可以在node01中运行命令以获取数据。
# vi /etc/naemon/conf.d/commands.cfg define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$-c $ARG1$ }
重新启动naemon和apache
# systemctl restart naemon # systemctl restart httpd
确保来自naemon服务器的NRPE插件可以与远程主机/客户端计算机中的nrpe守护程序对话。
# /usr/lib64/naemon/plugins/check_nrpe -H 10.0.0.38 NRPE v2.15
刷新浏览器,然后在thruk webUI的左侧列中单击“主机”,我们将可以在“所有主机组的主机状态详细信息”下找到远程主机(node01)。
单击主机名“ node01”,将向我们显示node01的主机状态信息的详细信息。