LAMP+Nagios+Ndoutils+Centreon 64位操作系统安装
LAMP安装
安装yum 源
1.rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
2.rpm -ivh epel-release-5-4.noarch.rpm
3.rpm -ivh remi-release-5-8.el5.remi.noarch.rpm
yum安装:
#yum install httpd
#yum install mysql mysql-server mysql-devel openssl-devel perl-DBD-MySQL
#yum install php php-mysql php-gd
yum install sysstat (安装iostat)
部分软件包安装
安装 PHP附属包:
#yum install php-pear php-snmp php-common php-ldap php-xml php-gd php-mbstring
安装PERl包:
#yum install perl-DBI perl-Config-IniFiles perl-Crypt-DES perl-Digest-HMAC perl-Digest-SHA1 perl-GD perl-IO-Socket-INET6 perl-Net-SNMP perl-rrdtool perl-Socket6 perl-Config-IniFiles
安装GD Modules:
#yum install gd gd-devel
安装其余软件包:
#yum install libpng-devel dmidecode lm_sensors libpng zlib freetype cairo pango libxml2 fontconfig fping graphviz gcc-c++ glib2-devel
Yum install glib
Yum install fping
Yum install graphviz.x86_64
以上软件包如果本机中未能自带,请登录http://rpm.pbone.net/ 上自行下载。
(当需要安装librrd.so.2()(64bit时,下载zenoss-2.3.3.el5.x86_64.rpm
安装RRDTOOL:
rpm -e rrdtool-1.4.7-1.el5.rf.x86_64 perl-rrdtool-1.4.7-1.el5.rf.x86_64
#rpm �Civh rrdtool-1.2.19-1.el5.kb.x86_64.rpm
#rpm �Civh rrdtool-devel-1.2.19-1.el5.kb.x86_64.rpm
#rpm �Civh rrdtool-doc-1.2.19-1.el5.kb.x86_64.rpm
#rpm �Civh rrdtool-perl-1.2.19-1.el5.kb.x86_64.rpm
#rpm �Civh rrdtool-php-1.2.19-1.el5.kb.x86_64.rpm
#rpm �Civh rrdtool-python-1.2.19-1.el5.kb.x86_64.rpm
#rpm �Civh rrdtool-tcl-1.2.19-1.el5.kb.x86_64.rpm
安装PEAR模块:
因为之前已经安装过php-pear包,pear的主目录已经产生,但是Centreon还需要加载一些pear模块才能工作。
pear upgrade --force http://pear.php.net/get/PEAR-1.9.0
#pear install Archive_Tar Auth_SASL Console_Getopt Date DB DB_DataObject DB_DataObject_FormBuilder HTML_Common HTML_QuickForm_advmultiselect HTML_QuickForm_ElementGrid HTML_Table HTML_QuickForm HTTP HTTP_Request Image_Canvas Image_Color Image_Graph Image_GraphViz Log Mail Mail_Mime Math_BigInteger MDB2 Net_DIME Net_IDNA Net_Ping Net_SMTP Net_Socket Net_Traceroute Net_URL Numbers_Roman Numbers_Words SOAP Structures_Graph Validate XML_RPC
#pear list ------ 查看安装了哪些模块
pear install channel://pear.php.net/Image_Canvas-0.3.5
pear install channel://pear.php.net/Image_Graph-0.8.0
pear install channel://pear.php.net/Numbers_Words-0.16.4
pear install channel://pear.php.net/SOAP-0.13.0
pear install channel://pear.php.net/Validate-0.8.5
pear install channel://pear.php.net/HTML_QuickForm_ElementGrid-0.1.2
pear install channel://pear.php.net/NET_IDNA-0.8.1
pear install channel://pear.php.net/Net_Traceroute-0.21.3
安装SNMP:
#yum install net-snmp net-snmp-utils net-snmp-devel net-snmp-perl
配置SNMP:
#vim /etc/snmp/snmpd.conf 将x.x.x.x换成运行nagios服务器的IP地址:
com2sec notConfigUser x.x.x.x public
access notConfigGroup”” any noauth exact all none none
view all included .1 80
安装nagios Ndoutils安装
=====================yum 安装===================
yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel nagios-nrpe
安装完的插件都在/usr/lib64/nagios/plugins下,以后centreon插件也会在这个目录下。
输入http://IP/nagios即可看到nagios监控界面
{
/usr/bin/htpasswd -c /etc/nagios/htpasswd.users nagios (如无法登陆需设置用户名密码、用户名或为nagiosadmin)
设置密码
sed -i 's/nagiosadmin/nagios/g' /etc/nagios/cgi.cfg 打开查看权限
service nagios restart
service httpd restart
service mysqld restart
#执行service nagios start操作可以看到nagios监控的本机的状态
(nagios目录:/etc/nagios/
插件目录:/usr/lib64/nagios/plugins
给nagios用户开权限,让他能够查看信息!
# vim /usr/local/nagios/etc/cgi.cfg
在所有的nagiosadmin后面添加nagios
/etc/init.d/nrpe start)
} //{}中内容可以不配置
Ndoutils安装
#tar -zxf ndoutils-1.4b9.tar.gz
#cd ndoutils-1.4b9
#./configure --prefix=/usr/local/nagios/ \
--enable-mysql \
--disable-pgsql \
--with-ndo2db-user=nagios \
--with-ndo2db-group=nagios
#make
#make install
Cd config
Copy ndo2db.cfg-sample to /etc/nagios/ndo2db.cfg
Centreon安装
#每一步都要看好要安装的东西以及目录,安装目录默认的就选默认就好了,有的需要自己指定目录:RRDs,PEAR.php,ndomod.o
#find / -name RRDs.pm
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm
#find / -name PEAR.php
/usr/share/pear/PEAR.php
/usr/lib64/nagios
/etc/nagios
/var/nagios
#find / -name ndomod.o
/usr/local/nagios/bin/ndomod.o
#tar -zxf centreon-2.1.9.tar.gz
#cd centreon-2.1.9
#./install.sh -i
###############################################################################
# #
# Centreon (www.centreon.com) #
# Thanks for using Centreon #
# #
# v2.2 #
# #
# #
# Make sure you have installed and configured #
# sudo - sed - php - apache - rrdtool - mysql #
# #
###############################################################################
------------------------------------------------------------------------
Checking all needed binaries
------------------------------------------------------------------------
rm OK
cp OK
mv OK
/bin/chmod OK
/bin/chown OK
echo OK
more OK
mkdir OK
find OK
/bin/grep OK
/bin/cat OK
/bin/sed OK
You will now read Centreon Licence.
Press enter to continue.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
........................................................................................
Do you accept GPL license ?
[y/n], default to [n]:
> y
------------------------------------------------------------------------
Please choose what you want to install
------------------------------------------------------------------------
Do you want to install : Centreon Web Front
[y/n], default to [n]:
> y
Do you want to install : Centreon CentCore
[y/n], default to [n]:
> y
Do you want to install : Centreon Nagios Plugins
[y/n], default to [n]:
> y
Do you want to install : Centreon Snmp Traps process
[y/n], default to [n]:
> y
------------------------------------------------------------------------
Start CentWeb Installation
------------------------------------------------------------------------
Where is your Centreon directory?
default to [/usr/local/centreon]
>
Do you want me to create this directory ? [/usr/local/centreon]
[y/n], default to [n]:
> y
Path /usr/local/centreon OK
Where is your Centreon log directory
default to [/usr/local/centreon/log]
>
Do you want me to create this directory ? [/usr/local/centreon/log]
[y/n], default to [n]:
> y
Path /usr/local/centreon/log OK
Where is your Centreon etc directory
default to [/etc/centreon]
>
Path /etc/centreon OK
Where is your Centreon generation_files directory?
default to [/usr/local/centreon]
>
Path /usr/local/centreon OK
Where is your Centreon variable library directory?
default to [/var/lib/centreon]
>
Path /var/lib/centreon OK
Where is your CentPlugins Traps binary
default to [/usr/local/centreon/bin]
>
Do you want me to create this directory ? [/usr/local/centreon/bin]
[y/n], default to [n]:
> y
Path /usr/local/centreon/bin OK
Where is the RRD perl module installed [RRDs.pm]
default to [/usr/lib/perl5/RRDs.pm]
> /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/RRDs.pm
Path /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-threadOKulti
/usr/bin/rrdtool OK
/bin/mail OK
Where is PEAR [PEAR.php]
default to [/usr/share/php/PEAR.php]
> /usr/share/pear/PEAR.php
Path /usr/share/pear OK
Where is installed Nagios ?
default to [/usr/local/nagios]
> /usr/lib64/nagios
Path /usr/lib64/nagios OK
Where is your nagios config directory
default to [/usr/local/nagios/etc]
> /etc/nagios
Path /etc/nagios OK
Where is your Nagios var directory ?
default to [/usr/local/nagios/var]
> /var/nagios
Path /var/nagios OK
Where is your Nagios plugins (libexec) directory ?
default to [/usr/local/nagios/libexec]
> /usr/lib64/nagios/plugins
Path /usr/lib64/nagios/plugins OK
/usr/bin/nagios OK
Where is your Nagios image directory ?
default to [/usr/local/nagios/share/images/logos]
> /usr/share/nagios/images/logos
Path /usr/share/nagios/images/logos OK
/usr/bin/nagiostats OK
p1_file : /usr/bin/p1.pl OK
/usr/bin/php OK
/usr/bin/perl OK
Finding Apache group : apache
Finding Apache user : apache
Finding Nagios user : nagios
Finding Nagios group : nagios
Where is your NDO ndomod binary ?
default to [/usr/sbin/ndomod.o]
> /usr/local/nagios/bin/ndomod.o
/usr/local/nagios/bin/ndomod.o OK
------------------------------------------------------------------------
Configure Sudo
------------------------------------------------------------------------
Where is sudo configuration file
default to [/etc/sudoers]
>
/etc/sudoers OK
Nagios init script OK
Your sudo has been configured previously
Do you want me to reconfigure your sudo ? (WARNING)
[y/n], default to [n]:
> y
Configuring Sudo OK
------------------------------------------------------------------------
Configure Apache server
------------------------------------------------------------------------
Finding Apache Centreon configuration file
'/etc/httpd/conf.d/centreon.conf' : OK
Do you want to update Centreon Apache sub configuration file ?
[y/n], default to [n]:
> y
Backup Centreon Apache configuration completed
Create '/etc/httpd/conf.d/centreon.conf' OK
Configuring Apache OK
Do you want to reload your Apache ?
[y/n], default to [n]:
> y
Reloading Apache service OK
Preparing Centreon temporary files
Change right on /usr/local/centreon/log OK
Change right on /etc/centreon OK
Change right on /usr/share/nagios/images/logos OK
Install nagios documentation OK
Change macros for insertBaseConf.sql OK
Change macros for php files OK
Change right on /etc/nagios OK
Copy CentWeb in system directory
Install CentWeb (web front of centreon) OK
Install libraries OK
Copying libinstall OK
Change macros for centreon.cron OK
Install Centreon cron.d file OK
Change macros for archiveDayLog OK
Change macros for centAcl.php OK
Install cron directory OK
------------------------------------------------------------------------
Pear Modules
------------------------------------------------------------------------
Check PEAR modules
PEAR 1.4.9 1.9.4 OK
DB 1.7.6 1.7.14 OK
DB_DataObject 1.8.4 1.9.6 OK
DB_DataObject_FormBuilder 1.0.0RC4 1.0.1 OK
MDB2 2.0.0 2.4.1 OK
Date 1.4.6 1.4.7 OK
HTML_Common 1.2.2 1.2.5 OK
HTML_QuickForm 3.2.5 3.2.13 OK
HTML_QuickForm_advmultiselect 1.1.0 1.5.1 OK
HTML_Table 1.6.1 1.8.3 OK
Archive_Tar 1.1 1.3.1 OK
Auth_SASL 1.0.1 1.0.6 OK
Console_Getopt 1.2 1.2 OK
Net_SMTP 1.2.8 1.6.1 OK
Net_Socket 1.0.1 1.0.10 OK
Net_Traceroute 0.21 0.21.3 OK
Net_Ping 2.4.1 2.4.5 OK
Validate 0.6.2 0.8.4 OK
XML_RPC 1.4.5 1.5.0 OK
SOAP 0.10.1 0.12.0 OK
Log 1.9.11 1.12.7 OK
All PEAR modules OK
------------------------------------------------------------------------
Centreon Post Install
------------------------------------------------------------------------
Create /usr/local/centreon/www/install/install.conf.php OK
Create /etc/centreon/instCentWeb.conf OK
------------------------------------------------------------------------
Start CentStorage Installation
------------------------------------------------------------------------
Where is your Centreon Run Dir directory?
default to [/var/run/centreon]
>
Path /var/run/centreon OK
Where is your CentStorage binary directory
default to [/usr/local/centreon/bin]
>
Path /usr/local/centreon/bin OK
Where is your CentStorage RRD directory
default to [/var/lib/centreon]
>
Path /var/lib/centreon OK
Finding Nagios group : nagios
Finding Nagios user : nagios
Preparing Centreon temporary files
/tmp/centreon-setup exists, it will be moved...
install www/install/createTablesCentstorage.sql OK
CentStorage status Directory already exists PASSED
CentStorage metrics Directory already exists PASSED
Change macros for centstorage binary OK
Install CentStorage binary OK
Install library for centstorage OK
Change right : /var/run/centreon OK
Change macros for centstorage init script OK
Do you want me to install CentStorage init script ?
[y/n], default to [n]:
> y
CentStorage init script installed OK
Do you want me to install CentStorage run level ?
[y/n], default to [n]:
> y
Change macros for logAnalyser OK
Install logAnalyser OK
Change macros for nagiosPerfTrace OK
Install nagiosPerfTrace OK
Change macros for purgeLogs OK
Install purgeLogs OK
Change macros for purgeCentstorage OK
Install purgeCentstorage OK
Change macros for centreonPurge.sh OK
Install centreonPurge.sh OK
Change macros for centstorage.cron OK
Install CentStorage cron OK
Create /etc/centreon/instCentStorage.conf OK
------------------------------------------------------------------------
Start CentCore Installation
------------------------------------------------------------------------
Where is your CentCore binary directory
default to [/usr/local/centreon/bin]
>
Path /usr/local/centreon/bin OK
/usr/bin/ssh OK
/usr/bin/scp OK
Finding Nagios group : nagios
Finding Nagios user : nagios
Preparing Centreon temporary files
/tmp/centreon-setup exists, it will be moved...
Change CentCore Macro OK
Copy CentCore in binary directory OK
Change right : /var/run/centreon OK
Change right : /var/lib/centreon OK
Replace CentCore init script Macro OK
Do you want me to install CentCore init script ?
[y/n], default to [n]:
> y
CentCore init script installed OK
Do you want me to install CentCore run level ?
[y/n], default to [n]:
> y
Create /etc/centreon/instCentCore.conf OK
------------------------------------------------------------------------
Start CentPlugins Installation
------------------------------------------------------------------------
Where is your CentPlugins lib directory
default to [/var/lib/centreon/centplugins]
>
Path /var/lib/centreon/centplugins OK
Finding Nagios user : nagios
Finding Nagios group : nagios
Preparing Centreon temporary files
/tmp/centreon-setup exists, it will be moved...
Change macros for CentPlugins OK
Installing the plugins OK
Change right on centreon.conf OK
CentPlugins is installed
------------------------------------------------------------------------
Start CentPlugins Traps Installation
------------------------------------------------------------------------
Where is your SNMP configuration directory
default to [/etc/snmp]
>
/etc/snmp OK
Where is your SNMPTT binaries directory
default to [/usr/local/centreon/bin/]
>
/usr/local/centreon/bin/ OK
Finding Nagios group : nagios
Finding Apache user : apache
Preparing Centreon temporary files
/tmp/centreon-setup exists, it will be moved...
Change macros for CentPluginsTraps OK
Installing the plugins Trap binaries OK
Change macros for snmptrapd.conf OK
Change macros for snmptt.ini OK
Install : snmptrapd.conf OK
Install : snmp.conf OK
Install : snmptt.ini OK
Install : snmptt OK
Install : snmpttconvertmib OK
Generate SNMPTT configuration FAIL
Create /etc/centreon/instCentPlugins.conf OK
###############################################################################
# #
# Go to the URL : http://localhost.localdomain/centreon/ #
# to finish the setup #
# #
# Report bugs at http://forge.centreon.com #
# #
# Thanks for using Centreon. #
# ----------------------- #
# Contact : [email protected] #
# http://www.centreon.com #
# #
##############################################################################
Centreon安装完成后,你可以通过http://yourServerIPAddress/centreon来访问。
#安装后在网址中输入http://IP/centreon 进入Centreon web 配置界面
#填写mysql数据库访问密码,填写ndo的用户及密码,默认数据库root密码为空
#创建centreon登录时的账号和密码
#登录后的界面
#安装完成
C、配置cgi.cfg
D、应用更改
参考:http://www.linuxidc.com/Linux/2011-04/34031p2.htm
出现问题:
1、不显示主机列表
ps aux | grep ndo2db
启动ndo2db服务
locate ndo2db
/usr/local/nagios/bin/ndo2db -c /etc/nagios/ndo2db.cfg
参考:
http://wenku.baidu.com/view/98ba2b1752d380eb62946dd0.html
2、不能显示服务和主机数量
==========
Ubuntu 客户端安装 (remote server installation and setup)
#sudo apt-get install nagios-nrpe-server nagios-nrpe-plugin
#sudo vi /etc/nagios/nrpe.cfg (in the following)
Append the Nagios server ip in the following
allowed_hosts=127.0.0.1,your-nagios-server-ip
allowed_hosts=127.0.0.1,192.168.10.247,192.168.10.201
重启nrpe
#ps aux | grep nrpe
#kill “nrpe-process-id”
And start nrpe process as
/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
============
centos客户端:
rpm -ivh rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
rpm -ivh epel-release-5-4.noarch.rpm
rpm -ivh remi-release-5-8.el5.remi.noarch.rpm
yum install nagios-plugins nagios-plugins-nrpe nagios-nrpe �Cy
cd //usr/lib64/nagios/plugins/
vim /etc/nagios/nrpe.cfg
修改host_allow字段,添加监控机ip
/etc/init.d/nrpe restart
监控工作主要由nagios完成再通过ndo2db写入数据库最后由centreon调用显示出来
启动服务:
/etc/init.d/nrpe restart
/usr/local/nagios/bin/ndo2db -c /etc/nagios/ndo2db.cfg
/etc/init.d/httpd restart
/etc/init.d/nagios restart
/etc/init.d/centcore restart
/etc/init.d/centstorage restart
Centreon汉化
1.下载语言文件 # wget http://cacti-nagios.googlecode.com/files/messages.mo
2.创建语言目录 # mkdir -p /usr/local/centreon/www/locale/zh_CN/LC_MESSAGES/
3.移劢下载的messages.mo至第2步创建的目录 # mv messages.mo /usr/local/centreon/www/locale/zh_CN/LC_MESSAGES/
4.登录centreon点击administartors再点option�入”my account”更改语言为zh_CN保存即可。
======
centreon安装失败后的卸载
# rm -rf /usr/local/centreon
# rm -rf /etc/centreon
# rm -rf /etc/httpd/conf.d/centreon.conf
# rm -rf /var/lib/centreon
/usr/lib64/nagios/plugins/check_nrpe -H 192.168.18.181
为10.201添加监控cpu命令步骤
1、下载监控脚本
cd /usr/lib64/nagios/plugins(监控端和被监控端都要有此脚本)
wget http://-------------------------------
chown nagios:nagios check_cpu.sh
chmod +x check_cpu.sh
2、 添加用户
2、添加主机
(检测命令要选中check_host_alive,否则会显示主机为down)
****4、增加服务
增加check_cpu 服务
使用check_nrpe 则不用在centreon中定义命令
定义check_nrpe命令:
配置-----命令-----增加
$USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
check_cpu_load名字随便定义
check_cpu_234则是监控端和被监控端的nrpe.cfg中command字段中定义。
5、关联主机
配置――服务――关系
6、定义command字段
在监控端和被监控端都要编辑nrpe.cfg,定义命令,添加command字段
编辑:vim /etc/nagios/nrpe.cfg,添加command字段
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_disk_home]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /home
command[check_disk_sda2]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda2
command[check_disk_sda3]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda3
command[check_disk_sdb1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sdb1
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_memory]=/usr/lib64/nagios/plugins/check_memory.pl -f -w 30 -c 20
command[check_cpu_234]=/usr/lib64/nagios/plugins/check_cpu.sh -w 60 -c 80
command[check_http]=/usr/lib64/nagios/plugins/check_http -H $HOSTADDRESS$ -u $ARG1$ -w 5 -c 10
command[check_80]=/usr/lib64/nagios/plugins/check_tcp -H $HOSTADDRESS$ -p 80 -w 1 -c 5
command[check_iostat]=/usr/lib64/nagios/plugins/check_iostat -w 10 -c 20
command[check_nrpe]=/usr/lib64/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
监控端重启nrpe
/etc/init.d/nrpe restart
被监控端重启nrpe服务
ps aux | grep nrpe
kill 32162
/usr/sbin/nrpe -c /etc/nagios/nrpe.cfg �Cd
在被监控端测试脚本
在监控机上远程测试
(注意:写command字段和测试时,参数要写正确)
7、激活配置,重启服务
配置--->nagios
8、查看监控内容
9、mysql监控举例:
监控端命令定义:
command[check_mysql_connect_time]=/usr/lib64/nagios/plugins/check_mysql_health -hostname $HOSTADDRESS$ -port $ARG1$ -username $ARG2$ -password $ARG3$ -mode connection-time -w 1 -c 5
被监控端命令定义:
command[check_mysql_connect_time]=/usr/lib64/nagios/plugins/check_mysql_health -hostname 127.0.0.1 -port 40238 -username eloancn -pas sword eloancn158 -mode connection-time -w 1 -c 5
出现问题:
1、CHECK_NRPE: Socket timeout after 10 seconds.
解决方法:
测试NRPE daemon
netstat -ln |grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
修改防火墙规则,开放tcp 5666端口
配置短信报警通知:
1、安装sendEmail
wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz
#tar -zxvf sendEmail-v1.56.tar.gz && cd sendEmail-v1.56
#cp sendEmail /usr/local/bin
#chmod 0755 /usr/local/bin/sendEmail
2. 发送邮件测试
# sendEmail -h (查看sendMail帮助)
# sendEmail -f [email protected] -t [email protected] -s 28.4.15.18 -u "nagios测试" -m "nagios test 测试
或者将一个文件的内容作为附件发出, 并且是gb2312或utf8编码的html格式文件(可以显示中文):
#sendEmail -f [email protected] -t [email protected] -s 28.4.15.18 -u "nagios测试" -m "pls see the attachement附件" -a /var/log/messages -o message-content-type=html -o message-charset=gb2312
如果测试报错:
则后面需要加上-xu �Cxp参数:
各参数含义如下:
-f 表示发送者的邮箱, 可随意设置 -t 表示接收者的邮箱
-s 表示SMTP服务器的域名或者IP -u 表示邮件的主题 -m 表示邮件的内容
-xu 表示SMTP验证的用户名, 如果SMTP服务器需要验证的话就加上该参数, 一般发给外网用户则需要
-xp 表示SMTP验证的密码, 如果SMTP服务器需要验证的话就加上该参数, 一般发给外网用户则需要
3、在联系人用户里,就可以定义。
4、定义邮件发送命令:
配置--------命令----------通知
就在下面的“通知”里,结尾是email的是邮件发送命令。host是主机的报警和恢复,service是服务的报警和恢复。
以host那条命令为例说明
/usr/bin/printf "%b" "Host: $HOSTNAME$<br>Notification:
$HOSTNOTIFICATIONNUMBER$<br>Command: $HOSTCHECKCOMMAND$<br>Datetime: $LONGDATETIME$<br><br>Info: $HOSTOUTPUT$<br>$LONGHOSTOUTPUT$"
| /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s smtp.XXXX.com -xu [email protected] -xp jk@XXXX -u "Host $HOSTSTATE$: $HOSTADDRESS$" -o message-content-type=html -o message-charset=utf8
主要是打红的地方调用发邮件的命令,路径是sendEmail命令,-f是发件人地址,-t是收件人地址,这里是个变量,已经定义了,就是之前那个联系人里填的,-s是邮件服务器地址,也可以填域名,-xu是邮箱账号,-xp是邮箱密码。其他的都是些邮件内容的定义,所以可以不用改。-o
message-content-type=html -o message-charset=utf8这段是防止中文乱码的。
下面这段是原来没做任何更改的命令行,供参考。
/usr/bin/printf "%b" "***** centreon Notification
*****\n\nType:$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState:
$HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $DATE$" | @MAILER@ -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$
下面这段是服务的。
/usr/bin/printf "%b" "Host: $HOSTALIAS$<br>NotifyTimes: $SERVICENOTIFICATIONNUMBER$<br>Command:
$SERVICECHECKCOMMAND$<br>Datetime: $LONGDATETIME$<br><br>Additional
Info:<br>$SERVICEOUTPUT$<br>$LONGSERVICEOUTPUT$" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s smtp.XXXX.com -xu [email protected] -xp jk@XXXX -u "Service $SERVICESTATE$: $HOSTADDRESS$ | $SERVICEDESC$" -o message-content-type=html -o message-charset=utf8
改完之后保存,别忘了导出文件和重启nagios,让其生效。
到这里,我们的报警邮件就可以正常发出了。
为了防止单搞nagios的因为发不出邮件而头疼,这里提一下,如果按照大众版sendmail做法,那你需要在/etc/mail里面找到个access文件,里面需要添加你要发邮件的域。
比如qq邮箱,要添加qq.com进去。
============
说明:“配置短信报警通知”这一块可以不配置,centos服务器默认有sendmail,只要在定义联系人的时候写好邮箱,主机和服务通知栏中分别选中:host-notify-by-email和service-notify-by-email即能发送邮件报警,使用139邮箱可以短信通知。
监控界面如下: