2015年(29)
分类: 系统运维
2015-11-23 17:47:54
Nagios
开始安装
安装nagios-3.2.1.tar.gz到/usr/local/src
到/usr/local/src/nagios-3.2.1/html/docs用过以下命令找到帮助文档firefox index.html
1.确认为root身份
2.建立nagios用户 并设置密码 建立 nagcmd组 并且将该组设置为nagios apache用的附加组
nagcmd------> cgi文件
/ \
nagios apache
useradd nagios
groupadd nagcmd
useradd apache
usermod -a -G nagcmd,apache nagios
usermod -a -G nagios apache
3.到nagios解压目录进行安装
./configure --with-command-group=nagcmd
make all 编译软件
make install 安装软件
make install-init 生成启动文件
make install-config 生成配置文件
make install-commandmode 设置组的执行权限
make install-webconf 安装nagios的web文件到httpd的conf.d目录下
4.设置邮件联系人
/usr/local/nagios/etc/objects/contacts.cfg
email root@localhost.localdomain
5.vim /etc/httpd/conf.d/nagios.conf文件 必须设置用户nagiosadmin密码
该文件内scriptalias 针对cgi的别名
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
6.插件的安装
nagios-plugins-1.4.14.tar 解压缩 /usr/local/src下
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检测nagios的配置文件是否正常后 启动nagios
7.配置检测对象
cp localhost.cfg 192.168.1.196.cfg
define host{
use linux-server
host_name testserver
alias host196
address 192.168.1.196
}
define service{
use local-service
host_name testserver
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service
host_name testserver
service_description HTTP
check_command check_http
# notifications_enabled 0
}
define service{
use local-service
host_name testserver
service_description NFS
check_command check_tcp!2049
# notifications_enabled 0
}
将监控配置文件localhost.cfg加入到nagios.cfg文件中
cfg_file=/usr/local/nagios/etc/objects/192.168.1.196.cfg
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg检测新的配置文件是否正确
check_tcp 连接80端口判断http是否存活
check-http 取回主页判断http是否存活
check_load 系统平均负载
check_ping 主机是否存活
check_disk 判断磁盘空间
以下文件作用
cfg_file=/usr/local/nagios/etc/objects/commands.cfg 监测命令的设定
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg 设置邮件发送人
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg 监测时间的设定
cfg_file=/usr/local/nagios/etc/objects/templates.cfg 监测规则设定
service_notification_options w,u,c,r,f,s
w:警告(warning)
u:未知(unkown)
c:严重(critical)
r:恢复(recover)
f:闪断(flapping)
s:计划内宕机(scheduled downtime events)
host_notification_options d,u,r,f,s
d:宕机(down)
u:主机不能到达(unreachable)
r:恢复(recover)
f:闪断(flapping)
s:计划内宕机(scheduled downtime events)
$USER1$=/usr/local/nagios/libexec $USER1$代表检测文件目录
/usr/local/nagios/etc/cgi.cfg文件
use_authentication=1 nagios验证 0取消 同时apache也要取消验证
authorized_for_configuration_information=nagiosadmin nagios的管理员设定如要更改一下选项都需更改
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin
#authorized_for_read_only=user1,user2 如果需要其他用只能查询不能在页面设置可将该用户添加到这一选项并且加入到apache验证用户
重启服务即可
访问