3,安装nagios主程序包
# tar xf /share/soft/soft/monitor2/nagios-3.2.3.tar.gz -C /usr/src/
# cd /usr/src/nagios-3.2.3/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
# make all
# make install
# make install-init
# make install-commandmode
# make install-config
# make install-webconf
make install
- This installs the main program, CGIs, and HTML files
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf
- This installs the Apache config file for the Nagios
web interface
# ls /usr/local/nagios/
bin etc libexec sbin share var
--libexec目录为空,需要安装插件包才会有很多命令与脚本
4,安装nagios插件包 --包含用于收集数据的程序,命令,脚本等
# tar xf /share/soft/soft/monitor2/nagios-plugins-1.4.15.tar.gz -C /usr/src/
# cd /usr/src/nagios-plugins-1.4.15/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
# make ;make install
5。创建web界面可访问的验证用户
/etc/httpd/conf.d/nagios.conf --在这个文件里已经配置了nagios的apache验证,所以我们要把用户给创建出来
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin --文件路径和用户名都不要改,被规定了就是这个
New password:
Re-type new password:
Adding password for user nagiosadmin
现在查看web界面,默认只监控了localhost,并监控了其8个服务
一些小操作:
1,如果http服务为黄色,是警告,则需要把网站家目录里加一个主页进去(家目录为空,他就会警告)。
但需要等它下一次check才会OK。如果要手动check,可以点http,再右边点Re-schedule the next check of this service去强制check,就OK了
2,默认http和ssh是关闭通知的,是因为在localhost.cfg里这两个服务有一句 notifications_enabled 0。
也可以手动打开,点进去,再右边点enabled notifications for this service.
3,关闭ssh服务,刷新web界面,还是没有critical.
点击ssh,可以看到下一次计划的check时间。如果不等的话,在右边点Re-schedule the next check of this service强制check,再刷新就critical
4,修改ssh的check时间间隔
# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service --使用的这个模版,所以要去改这个模版里的时间
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
# vim /usr/local/nagios/etc/objects/templates.cfg
define service{
name local-service
.............
normal_check_interval 1 --把这个五分钟改为1分钟
.............
}
--直接使用监控命令去手工check一下,OK的
# /usr/local/nagios/libexec/check_ftp -w 3 -c 6 -p 2121
FTP OK - 0.004 second response time on port 2121 [220-#############################
220-#]|time=0.003835s;3.000000;6.000000;0.000000;10.000000
# /etc/init.d/nagios reload
--reload后,再去web界面可以看到能监控本机的ftp这个服务了
2,监控本机的mysql
# vim /usr/local/nagios/etc/objects/localhost.cfg
define service{
use local-service
host_name localhost
service_description MYSQL
check_command check_mysql!root!123
}
2,安装plugins插件,包含了数据采集命令脚本
# tar xf nagios-plugins-1.4.15.tar.gz -C /usr/src/
# cd /usr/src/nagios-plugins-1.4.15/
# ./configure --with-nagios-user=nagios --with-nagios-group=nagiosgroup
# make && make install
3,安装nrpe
# tar xf nrpe-2.12.tar.gz -C /usr/src/
# cd /usr/src/nrpe-2.12/
# ./configure && make && make install
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
4,修改nrpe的超级守护进程的配置文件
# vim /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 172.19.1.17 --加上nagios服务器的IP,允许它来访问
}
# vim /etc/services --最后面加一行
nrpe 5666/tcp # NRPE
5,在nrpe配置文件里定义check命令,使nagios服务能调用
# vim /usr/local/nagios/etc/nrpe.cfg
-----> Need to create a new config file ?
Do you want me to build a new AWStats config/profile
file (required if first install) [y/N] ? y --输入y,产生awstat的配置文件
-----> Define config file name to create
What is the name of your web site or profile analysis ?
Example: www.mysite.com
Example: demo
Your web site, virtual server or profile name:
> www.station35.cluster.com --定义要分析的网站的网站名,随便定义
-----> Define config file path
In which directory do you plan to store your config file(s) ?
Default: /etc/awstats
Directory path to store config file(s) (Enter for default):
> --定义网站分析配置文件的路径,这里直接回车代表使用默认路径
-----> Create config file '/etc/awstats/awstats.www.station35.cluster.com.conf'
Config file /etc/awstats/awstats.www.station35.cluster.com.conf created.
--就会看这个信息,自动产生了/etc/awstats/awstats.www.station35.cluster.com.conf
配置新产生的这个配置文件
vim /etc/awstats/awstats.www.station35.cluster.com.conf