重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
第一部分安装
创新互联公司是专业的三江侗网站建设公司,三江侗接单;提供成都网站制作、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行三江侗网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
Nagios的所有插件的地址:http://www.nagios.org/download/addons
1:安装LAMP环境
# yum -y install php httpd gcc glibc glibc-common gd gd-devel
2:建立nagios帐号,请牢记设置的密码
# /usr/sbin/useradd nagios && passwd nagios
创建一个用户组名为nagios用于从web接口执行外部命令。将nagios用户和apache用户都加入到这个组中。
# /usr/sbin/groupadd nagios
# /usr/sbin/usermod -g nagios nagios
# /usr/sbin/usermod -g nagios apache
3:编译与安装nagios
进入到nagios安装包所在的文件夹下
# tar -zxvf nagios- 3.4.1.tar.gz
# cd nagios
# ./configure --with-command-group=nagios --prefix=/usr/local/nagios
# make all
# make install
# make install-init
# make install-config
# make install-commandmode
# make install-webconf
创建一个nagiosadmin的用户,用于nagios的Web接口登录。请牢记你设置的密码。
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
验证是否正确安装,进入到安装路径(此处是/usr/local/nagios),看是否存在etc bin sbin share var这五个目录,如果存在,则说明nagios正确的安装到系统
4:编译与安装nagios-plugins
进入到nagios-plugins安装包所在的文件夹下
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure--with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
# make && make install
验证:ls /usr/local/nagios/libexec会显示安装的插件文件,即所有的插件都安装在libexec这个目录下
5:启动服务
重启apache服务让设置生效
# service httpd restart
验证nagios的样例配置文件
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有报错,启动nagios服务
# service nagios start
6:测试
登录http://IP地址/nagios/,输入用户名和密码,则nagios安装成功。
第二部分监控linux主机
一.被监控机上安装NRPE
1.安装客户端nagios插件
进入到nagios-plugins安装包所在的文件夹下
# tar -zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make && make install
# useradd nagios
# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec
2.给客户端安装NRPE
首先检查openssl是否存在,否则要安装openssl
# rpm –qa | grep openssl
openssl-devel-1.0.0-20.el6_2.5.x86_64
openssl-1.0.0-20.el6_2.5.x86_64
进入到nrpe安装包所在的文件夹下
# tar -zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure --prefix=/usr/local/nagios --enable-ssl --with-ssl-lib=/usr/lib/
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
返回当前NRPE的版本
# /usr/local/nagios/libexec/check_nrpe -H localhost
启动NRPE
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
3.配置NRPE客户端
添加nrpe服务器地址,允许监控服务器对其读取信息
# vi /usr/local/nagios/etc/nrpe.cfg
在allowed_hosts中添加允许的服务器,例如:
allowed_hosts=127.0.0.1,10.126.53.65,172.18.0.236
添加command字段来添加需要监控的服务,例如:
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 –c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 172.18.0.237 -w 3,2% -c 10,6% -p 30
重启nrpe
# killall -9 nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
二.监控机上安装NRPE
1.安装nrpe
首先检查openssl是否存在,否则要安装openssl
# rpm –qa | grep openssl
openssl-devel-1.0.0-20.el6_2.5.x86_64
openssl-1.0.0-20.el6_2.5.x86_64
进入到nrpe安装包所在的文件夹下
# tar -zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure --prefix=/usr/local/nagios --enable-ssl --with-ssl-lib=/usr/lib/
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
返回当前NRPE的版本
# /usr/local/nagios/libexec/check_nrpe -H localhost
2.commands.cfg中定义外部构件nrpe
# vi /usr/local/nagios/etc/objects/commands.cfg
添加check_nrpe
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line$USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
3.配置要监控的Linux主机
# vi /usr/local/nagios/etc/nagios.cfg
修改如下:
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
cfg_dir=/usr/local/nagios/etc/objects/servers
# mkdir /usr/local/nagios/etc/objects/servers/
#chown -R nagios.nagios /usr/local/nagios/etc/objects/servers/
4.配置cgi.cfg文件
# vi /usr/local/nagios/etc/cgi.cfg
修改如下:
use_authentication=1
注意:修改文件权限
# chmod 777 /usr/local/nagios/var/rw/
# chmod 777 / usr/local/nagios/var/rw/nagios.cmd
5.新建host_service_group.cfg,设置其内容
# vi /usr/local/nagios/etc/objects/servers/host_service_group.cfg
其文件内容如下:
define servicegroup{
servicegroup_name host_perfdata
alias host_perfdata
}
define hostgroup{
hostgroup_name host_perfdata
alias host_perfdata
}
6.新建172.18.0.237.cfg,设置监控内容
# vi /usr/local/nagios/etc/objects/servers/172.18.0.237.cfg
其文件内容如下:
define host{
uselinux-server
host_name 172.18.0.237
host_groupshost_perfdata
alias172.18.0.237
address 172.18.0.237
}
define service{
usegeneric-service
host_name 172.18.0.237
service_groupshost_perfdata
service_descriptioncheck_cpu_load
check_command check_nrpe!check_load
notifications_enabled1
}
define service{
use generic-service
host_name 172.18.0.237
service_groupshost_perfdata
service_descriptioncheck_total_process
check_command check_nrpe!check_total_procs
notifications_enabled1
}
define service {
usegeneric-service
host_name 172.18.0.237
service_groupshost_perfdata
service_descriptionPING
check_commandcheck_ping!200.0,20%!500.0,60%
notifications_enabled1
}
验证nagios的配置文件是否正确
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有报错,重新加载nagios服务
# service nagios reload
三.Nagios报警设置
3.1网页报警
1.修改cgi.cfg配置文件
# vi /usr/local/nagios/etc/cgi.cfg
去掉下面几行注释
host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
normal_sound=noproblem.wav
2.在/usr/local/nagios/share/media/下将声音文件添加进去
3.2通过sendEmail发送报警
1.安装sendEmail
进入到sendEmail安装包所在的文件夹下
# tar -zxvf sendEmail-v1.56.tar.gz
# cd sendEmail-v1.56
# cp sendEmail /usr/local/bin/
# chmod 755 /usr/local/bin/sendEmail
2.测试
使用系统自带的sendmail测试
# cd (回到根目录)
# mail -s “I am test”admin@admin< install.log
“I am test”是邮件的主题,在admin@admin中如果能收到邮件,则说明设置成功。
3.修改commands.cfg文件(其实这一步,可以省略,因为在安装nagios的时候,已经默认存在)
# /usr/local/nagios/etc/objects/commands.cfg
内容如下:
# 'notify-host-by-email' command definition
define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /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 *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
4.编辑contacts.cfg文件
# /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 admin@admin ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
service_notification_commands notify-service-by-email
host_notification_commandsnotify-host-by-email
}
5.重启nagios服务
# /etc/init.d/nagios reload
第三部分监控Windows主机
一.被监控机(Windows)上安装NSClient++客户端
下载地址:http://nsclient.org/nscp/downloads
目前最新版本:0.4.1.62,根据需要下载32位或64位机程序。
.zip格式和.msi格式大同小异,在次处我使用.msi格式,并以32位机为例。
双击下载好的程序,开始安装
选择:Typical
勾选:Allow all users to write config file
在Allowed hosts中填写监控主机的IP,NSClient password中本应该填写监控机和
被监控机之间的通信密码,为了方便,在次不进行设置,勾选Modules to load
下面的所有选项。点击Next
点击Install完成安装。
进入到服务中,找到NSClient++(Win32),双击它,选择登录,再勾选允许服务与
桌面交互,最后重启服务。
二.监控机(Linux)添加监控项
在/usr/local/nagios/etc/objects/servers/目录下添加一台Windows主机
# vi /usr/local/nagios/etc/objects/servers/10.126.53.54.cfg
其文件内容如下:
define host{
use linux-server
host_name10.126.53.54
alias10.126.53.54
host_groupshost_perfdata
address 10.126.53.54
}
define service{
use generic-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
notifications_enabled 1
}
define service{
usegeneric-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_memory_useage
check_command check_nt!MEMUSE!-w 80 -c 90
notifications_enabled 1
}
define service{
use generic-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_cpu_load
check_command check_nt!CPULOAD!-l 5,70,80
notifications_enabled 1
}
define service{
usegeneric-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_C:\_space
check_command check_nt!USEDDISKSPACE!-l C!-w 80 -c 90
notifications_enabled 1
}
define service{
use generic-service
host_name 10.126.53.54
service_groups host_perfdata
service_description check_E:\_space
check_command check_nt!USEDDISKSPACE!-l E!-w 80 -c 90
notifications_enabled 1
}
验证nagios的配置文件是否正确
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果没有报错,重新加载nagios服务
# service nagios reload
可以进行测试:
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54 -v CPULOAD -p 12489 -l 5,70,80
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54-v MEMUSE -p 12489
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54 -v USEDDISKSPACE -p 12489 -l C
#/usr/local/nagios/libexec/check_nt -H 10.126.53.54 -v USEDDISKSPACE -p 12489 -l E
第四部分nagvis插件的安装
Nagvis官方网站:http://www.nagvis.org/
Nagvis下载:http://jaist.dl.sourceforge.net/project/nagvis/NagVis 1.7/nagvis-1.7.3.tar.gz
ndoutils下载:http://sourceforge.net/projects/nagios/files/ndoutils-1.x/
一.安装ndoutils
查看是否安装MySQL-devel(它是用来编译ndoutils)
# rpm -qa | grep mysql
如果没有安装mysql-devel,则用yum安装
# yum -y install mysql-devel
为ndoutils创建数据库
#mysql -u root -p
Enter password:
mysql> create database ndodb;
mysql>grant all privileges on ndodb.* to ndouser@localhost identified by 'ndouser';
mysql>grant all privileges on ndodb.* to ndouser@'%' identified by 'ndouser';
mysql>flush privileges;
mysql>quit
关联mysql头文件和库
# ln -s /usr/local/mysql/include/* /usr/include/
# ln -s /usr/local/mysql/lib/* /usr/lib/
注意:/usr/local/mysql是MySQL的安装目录
开始安装ndoutils
# tar zxvf ndoutils-1.5.2.tar.gz
# cd ndoutils-1.5.2
#./configure --prefix=/usr/local/nagios --enable-mysql --enable-ssl --with-ssl-lib=/usr/lib --with-ndo2db-user=nagios --with-ndo2db-group=nagios --with-mysql=/usr/local/mysql --with-mysql-lib=/usr/local/mysql/lib LDFLAGS=-L/usr/lib
注意:/usr/local/mysql是MySQL的安装目录
#make
#make install//此命令可不用执行
# cd db/
# ./installdb -u ndouser -p ndouser -h localhost -d ndodb
# cd ../src/
# cp file2sock log2ndo ndo2db-2x ndo2db-3x ndomod-2x.o ndomod-3x.o/usr/local/nagios/bin/
# cd ../config
# cp ndo2db.cfg-sample ndomod.cfg-sample /usr/local/nagios/etc/
# mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# chmod 644 /usr/local/nagios/etc/ndo*
# vi /usr/local/nagios/etc/nagios.cfg
修改内容如下:
check_external_commands=1(大概在146行)
command_check_interval=-1(大概在164行)
event_broker_options=-1(大概在222行)
在249行下面添加一行:
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local /nagios/etc/ndomod.cfg
process_performance_data=1(大概在834行)
# vi /usr/local/nagios/etc/ndomod.cfg
将其修改为:
# cat /usr/local/nagios/etc/ndomod.cfg |grep -v '^#'|sed /^$/d
# vi /usr/local/nagios/etc/ndo2db.cfg
将其修改为:
# cat /usr/local/nagios/etc/ndo2db.cfg |grep -v '^#'|sed /^$/d
启动ndo2db守护进程
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
二.安装Nagvis
安装支持库graphviz
# cp /etc/yum.repos.d/rpmforge.repo /etc/yum.repos.d/rpmforge.repo.bak
# vi /etc/yum.repos.d/rpmforge.repo
将下面的内容加入到最后面:
[graphviz-stable]
name=Graphviz - RHEL $releasever - $basearch
baseurl=http://www.graphviz.org/pub/graphviz/stable/redhat/el$releasever/$basearch/os/
enabled=1
gpgcheck=0
skip_if_unavailable=1
[graphviz-stable-source]
name=Graphviz - RHEL $releasever - Source
baseurl=http://www.graphviz.org/pub/graphviz/stable/SRPMS/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-stable-debuginfo]
name=Graphviz - RHEL - Debug
baseurl=http://www.graphviz.org/pub/graphviz/stable/redhat/el$releasever/$basearch/debug/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-snapshot]
name=Graphviz - RHEL $releasever - $basearch
baseurl=http://www.graphviz.org/pub/graphviz/development/redhat/el$releasever/$basearch/os/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-snapshot-source]
name=Graphviz - RHEL $releasever - Source
baseurl=http://www.graphviz.org/pub/graphviz/development/SRPMS/
enabled=0
gpgcheck=0
skip_if_unavailable=1
[graphviz-snapshot-debuginfo]
name=Graphviz - RHEL - Debug
baseurl=http://www.graphviz.org/pub/graphviz/development/redhat/el$releasever/$basearch/debug/
enabled=0
gpgcheck=0
skip_if_unavailable=1
# yum -y install graphviz*
# tar zxvf nagvis-1.7.3.tar.gz
# cd nagvis-1.7.3
# bash install.sh
详细请参考官方文档:http://docs.nagvis.org/1.7/en_US/index.html