CentOS 7下Nagios的安装及配置(4)

查看sendmail邮件系统是否安装

[root@nagios ~]# rpm -qa|grep sendmail

如果没有安装,可以yum安装一下 

[root@nagios ~]# yum -y install sendmail

启动sendmail 

[root@nagios ~]# systemctl enable sendmail [root@nagios ~]# systemctl start sendmail

测试发送邮件:  

[root@nagios ~]# echo "test" | mail zhengxinlei@test.com.cn

CentOS 7下Nagios的安装及配置


 

发送外部邮件的时候,这种本地形式的发件人和发件地址容易被误认为垃圾邮件而拒收。
我们这里定义邮件发送smtp信息。
首先安装mailx12.5

wget tar zxf mailx-12.5.tar.gz cd mailx-12.5 make make install UCBINSTALL=/usr/bin/install mv /bin/mail /bin/mail_old ln -s /usr/local/bin/mailx /bin/mail mail -V

接下来配置外部smtp发件信息

vi /etc/nail.rc 添加如下内容: set bsdcompat set from=yunwei@yasn.com.cn set smtp=smtp.yasn.com.cn set smtp-auth-user=yunwei@yasn.com.cn set smtp-auth-password=123456 set smtp-auth=login

测试邮件发送

echo 'mail content'|mail -s test zhengxinlei@test.com.cn

发送邮件测试,可以看到发件人是我们设定的外部邮件发件人

CentOS 7下Nagios的安装及配置


 

编辑contacts.cfg,定义邮件联系人和组

[root@nagios ~]# cd /usr/local/nagios/etc/objects/ [root@nagios objects]# ls commands.cfg localhost.cfg~ services.cfg templates.cfg hosts.cfg printer.cfg switch.cfg windows.cfg contacts.cfg localhost.cfg timeperiods.cfg [root@nagios objects]# vi 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 nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** email 3166@vip.qq.com,xinlei@126.com } define contactgroup{ contactgroup_name admins alias Nagios Administrators members nagiosadmin }

编辑commands.cfg文件,定义邮件发送命令

[root@nagios objects]# vi commands.cfg // 查看下面内容是否存在,不存在则添加 # 'notify-host-by-email' command definition define command{   command_name notify-host-by-email   command_line /usr/bin/printf "%b" "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$ " | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$   } # 'notify-service-by-email' command definition define command{   command_name notify-service-by-email   command_line /usr/bin/printf "%b" "***** Nagios ***** Notification Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info: $SERVICEOUTPUT$ " | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$   }

修改一下监控的阀值,模拟报警。

CentOS 7下Nagios的安装及配置


 


重启nagios服务和sendmail服务

[root@nagios ~]# systemctl restart nagios [root@nagios ~]# systemctl stop sendmail [root@nagios ~]# ps -ef|grep sendmail [root@nagios ~]# systemctl start sendmail [root@nagios ~]# ps -ef|grep sendmail

查看报警的邮件,来几张图吧:

CentOS 7下Nagios的安装及配置


 

CentOS 7下Nagios的安装及配置


 

这是报警恢复后的邮件:

CentOS 7下Nagios的安装及配置


 

CentOS 7下Nagios的安装及配置


 

ok,搞定了。

常见邮件发送报错:

报错1

CentOS 7下Nagios的安装及配置


 


解决方法:
修改hosts为域名形式

CentOS 7下Nagios的安装及配置


 

[root@nagios objects]# cat /etc/hosts 172.16.0.18 nagios nagios.com

报错2(发送外部邮件的时候,这种本地形式的发件人和发件地址容易被误认为垃圾邮件而拒收。)


 

解决方法,见上面配置mail发件人smtp信息。

●监视物理组件的高级 Linux 命令(仅供参考)

内存:top free、vmstat、mpstat、iostat、sar
CPU:top vmstat、mpstat、iostat、sar
I/O:vmstat、mpstat、iostat、sar
进程:ipcs、ipcrm
负载:uptime

一键安装nagios命令参考

#############nagios-server-install######################## mkdir /software/ # mv nagios-4.3.1.tar.gz nagios-plugins-2.2.1.tar.gz nrpe-3.1.0.tar.gz pnp4nagios-0.6.25.tar.gz /software/ cd /software/ wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.1.0.tar.gz wget https://jaist.dl.sourceforge.net/project/pnp4nagios/PNP-0.6/pnp4nagios-0.6.25.tar.gz yum -y install httpd httpd-devel gcc glibc glibc-common gd gd-devel perl-devel perl-CPAN fcgi perl-FCGI perl-FCGI-ProcManager tar zxvf nagios-4.3.1.tar.gz cd nagios-4.3.1/ useradd nagios -s /sbin/nologin id www groupadd nagcmd usermod -a -G nagcmd nagios usermod -a -G nagcmd www id -n -G nagios id -n -G www ./configure --with-command-group=nagcmd make all make install-init make install-commandmode make install-config make install sleep 2 cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg make install-webconf echo 'nagios:$apr1$UigX6LG0$29RugFJZTSxRjnX4NIH3E0' > /usr/local/nagios/etc/htpasswd.users sed -i 's/Listen 80/Listen 8080/g' /etc/httpd/conf/httpd.conf sed -i 's/User apache/User www/g' /etc/httpd/conf/httpd.conf sed -i 's/Group apache/Group www/g' /etc/httpd/conf/httpd.conf sed -i 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' /etc/httpd/conf/httpd.conf grep 'Listen' /etc/httpd/conf/httpd.conf grep 'User' /etc/httpd/conf/httpd.conf grep 'Group' /etc/httpd/conf/httpd.conf grep 'DirectoryIndex' /etc/httpd/conf/httpd.conf cd /software/php-7.1.4/ ./configure --prefix=/usr/local/php --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-zlib --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-openssl --enable-mbstring --enable-xml --enable-session --enable-ftp --enable-pdo -enable-tokenizer --enable-zip --with-apxs2 make && make install sleep 1 cd /etc/httpd/ ll /etc/httpd/modules/libphp7.so systemctl start httpd systemctl enable httpd chkconfig nagios on /etc/init.d/nagios start cd /software/ tar zxvf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1/ ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd --enable-perl-modules make && make install cd /software/ tar zxvf nrpe-3.1.0.tar.gz cd nrpe-3.1.0/ ./configure make all make install-plugin make install-daemon make install-daemon-config cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg ls /usr/local/nagios/libexec/ /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local chmod +x /etc/rc.d/rc.local netstat -lnput|grep 5666 /usr/local/nagios/libexec/check_nrpe -H localhost #######################nagios-client-install########################### mkdir /software/ # mv nagios-plugins-2.2.1.tar.gz nrpe-3.1.0.tar.gz /software/ cd /software/ wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz wget https://sourceforge.net/projects/nagios/files/nrpe-3.x/nrpe-3.1.0.tar.gz yum install perl-devel perl-CPAN -y useradd nagios -M -s /sbin/nologin tar zxvf nagios-plugins-2.2.1.tar.gz cd nagios-plugins-2.2.1/ ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules make && make install sleep 1 cd .. tar zxvf nrpe-3.1.0.tar.gz cd nrpe-3.1.0/ ./configure make all make install-plugin make install-daemon make install-daemon-config mkdir /usr/local/nagios/etc/ cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg ls /usr/local/nagios/libexec/ /usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local chmod +x /etc/rc.d/rc.local netstat -lnput|grep 5666 sed -i 's/allowed_hosts=127.0.0.1,::1/allowed_hosts=127.0.0.1,::1,172.16.0.1/g' /usr/local/nagios/etc/nrpe.cfg sed -i 's/^command\[check/\#command\[check/g' /usr/local/nagios/etc/nrpe.cfg cat >> /usr/local/nagios/etc/nrpe.cfg << EOF # my custom monitor items command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20 command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / command[check_mem]=/usr/local/nagios/libexec/check_mem.pl -w 90% -c 95% command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10% EOF /usr/local/nagios/libexec/check_nrpe -H localhost -c check_disk

总结:
多多查看nagios日志和mail日志,进行排错��

CentOS 7下安装配置Nagios监控图文详解 

Nagios邮件报警配置简述 

Nagios本机及其他主机监控安装部署详解 

Nagios 系统监控基本安装配置过程详解 

Linux下Nagios+PNP4Nagios的安装与配置 

CentOS7安装Nagios并配置出图详解 

Linux下Nagios安装配置详解 

Nagios 的详细介绍请点这里
Nagios 的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/32dc9c353a354c8fb4e0582b1d4b5ecf.html