一、创建nagios用户和用户组
[root@localhost ~]#useradd -s /sbin/nologin nagios
[root@localhost ~]#mkdir /usr/local/nagios
[root@localhost ~]#chown -R nagios.nagios /usr/local/nagios
二、开启系统sendmail服务
[root@localhost ~]#service sendmail start
三、编译安装nagios
[root@localhost ~]# tar -zxvf nagios-3.2.0.tar.gz
[root@localhost ~]# cd nagios-3.2.0
[root@localhost nagios-3.2.0]#./configure --prefix=/usr/local/nagios
#指定nagios的安装目录,这里指定nagios安装到/usr/local/nagios目录
[root@localhost nagios-3.2.0]#make all
[root@localhost nagios-3.2.0]#make install
# make install用来安装nagios的主程序,CGI和HTML文件
[root@localhost nagios-3.2.0]# make install-init
#通过make install-init命令可以在/etc/rc.d/init.d目录下创建nagios启动脚本
[root@localhost nagios-3.2.0]# make install-commandmode
#通过make install-commandmode命令来配置目录权限
[root@localhost nagios-3.2.0]# make install-config
#make install-cofig命令用来安装nagios示例配置文件,这里安装的路径是/usr/local/nagios/etc
nagios安装完成后,目录对应的功能说明如下:
bin:可执行程序所在目录
etc:配置文件所在目录
sbin:cgi文件所在目录,也就是执行外部命令所需文件所在目录
share:网页文件所在目录
libexec:外部插件所在目录
var:日志文件,lock等文件所在目录
var/archives:日志自动归档目录
var/rw:用来存放外部命令文件的目录
四、安装nagios的插件
以nagios-plugins-1.4.14为例,插件版本与nagios版本关系并不大。
[root@localhost nagios]#tar -zxvf nagios-plugins-1.4.14.tar.gz
[root@localhost nagios]#cd nagios-plugins-1.4.14
[root@localhost nagios-plugins-1.4.14]#./configure --prefix=/usr/local/nagios
[root@localhost nagios-plugins-1.4.14]# make
[root@localhost nagios-plugins-1.4.14]# make install
查看/usr/local/nagios/libexec,会看到新增很多的插件。
五、安装Nagios中文化插件
下载地址:
此处切忌版本要与nagios的版本对应。
[root@localhost ~]#tar jxvf nagios-cn-3.2.0.tar.bz2
[root@localhost nagios-cn-3.2.0]#cd nagios-cn-3.2.0
[root@localhost nagios-cn-3.2.0]#./configure
[root@localhost nagios-cn-3.2.0]#make all
[root@localhost nagios-cn-3.2.0]#make install
六、配置httpd和php
修改httpd的配置文件/etc/httpd/conf/httpd.conf
找到如下两行
User apache
Group apache
#如果找不到,请通过搜索nobody寻找
修改为
User nagios
Group nagios
然后找到
DirectoryIndex index.html index.html.var
修改为
DirectoryIndex index.html index.html.var index.php
再在其下增加如下行
AddType application/x-httpd-php .php
在配置文件末尾增加如下信息:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /usr/local/nagios/etc/htpasswd
Require valid-user
</Directory>
保存配置文件
七、新增验证文件
[root@localhost]# /usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd yilei
New password: (输入密码)
Re-type new password: (再输入一次密码)
Adding password for useryilei
在/usr/local/nagios/etc下就会新增一个htpasswd验证文件。
八、验证
[root@localhost]#service httpd restart
[root@localhost]#service nagios start
通过浏览器输入
输入用户名/密码,就可以看到nagios的管理界面啦。此时看到的界面中没有任何监控机的信息。
九、配置联系人
1、修改contacts.cfg(联系人配置文件)
define contact{
contact_name yilei ; Short name of user
use generic-contact ; Inherit default values from generic-contact templ
ate (defined above)
alias yilei Admin ; Full name of user
email admin@sosme.cn ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
pager 158********
}
联系人组
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members yilei
}
十.配置主机和服务
1.添加主机
Vim hosts.cfg
define host{
use linux-server
host_name ftp
alias yilei-ftp
address 192.168.0.8
}
define host{
use linux-server
host_name ceshi
alias yilei-web2
address 192.168.0.122
}
define host{
use linux-server
host_name web
alias gonpo-web
address gp.gonpo.cn
check_interval 5
retry_interval 1
max_check_attempts 5
check_period 24x7
process_perf_data 0
retain_nonstatus_information 0
contact_groups admins
notification_interval 30
notification_period 24x7
notification_options d,u,r
}
define hostgroup{
hostgroup_name sa-servers
alias sa servers
members ftp,web1,ceshi
}
2.添加服务
Vim services.cfg
efine service{
use local-service
host_name ftp
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name web
service_description SSH
check_command check_ssh
}
define service{
use local-service
host_name web
service_description HTTP
check_command check_http
}
define service{
use local-service
host_name weibo
service_description check_load
check_command nrpe!check_load
}
2、修改cgi.cfg
default_user_name=yilei ;将用户名修改为nagios界面登录的用户名
3.修改nagios.cfg
添加
cfg_file=/usr/local/nagios//etc/objects/hosts.cfg
cfg_file=/usr/local/nagios//etc/objects/services.cfg
3、使用命令:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg检查配置是否有误
7、重启nagios:service nagios restart
详细演示: