nagios安装配置(四):nagios配置
1. 配置nagios.cfg[*]vi /usr/local/nagios/etc/nagios.cfg
# 目录名称自己定义,等下需要建立这个目录
[*]cfg_dir=/usr/local/nagios/etc/linuxjcq
将以上添加在cfg_dir段落,注释所有的cfg_file
[*]# cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
[*]......
2. 创建以上配置文件制定的目录
[*]cp -a /usr/local/nagios/etc/ojbects /usr/local/nagios/etc/linuxjcq
[*]cd /usr/local/nagios/etc/linuxjcq
[*]rm -rf localhost.cfg printer.cfg switch.cfg windows.cfg
3. 编辑目录下得commands.cfg文件,添加nrpe支持
[*]define command{
[*] command_name check_nrpe
[*] command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
[*] }
可以添加到文件的末尾
4. 在目录下添加hosts.cfg、hostgroups.cfg、services.cfg
我习惯将内容分成这个三个文件,合并成一个文件也可以
a. 主机
[*]vi hosts.cfg
[*]define host{
[*] use linux-server
[*] host_name linuxjcq01
[*] address 192.168.2.11
[*] }
[*]......
有多少台服务器需要监控,就需要添加多个host段落
说明:
use 制定使用的模板
host 主机名
address 主机的ip地址
b. 主机组
可以将服务器分成各种类型的组
[*]define hostgroup{
[*] hostgroup_namelinuxjcq_servers
[*] members linuxjcq01,......
[*] }
[*]
[*]......
说明:
hostgroup_name 组名
members 组的成员,名字为刚在在host设置的名字
c. 服务
[*]define service{
[*] use local-service
[*] hostgroup_name linuxjcq_servers
[*] service_description 01. System Load
[*] check_command check_nrpe!check_load
[*] }
[*]
[*]define service{
[*] use local-service
[*] hostgroup_name linuxjcq_servers
[*] service_description 02. System Users
[*] check_command check_nrpe!check_users
[*] }
[*]
[*]define service{
[*] use local-service
[*] hostgroup_name linuxjcq_servers
[*] service_description 03. Check Zombie Procs
[*] check_command check_nrpe!check_zombie_procs
[*] }
[*]define service{
[*] use local-service
[*] hostgroup_name linuxjcq_servers
[*] service_description 04. The Disk Usage
[*] check_command check_nrpe!check_disk
[*] }
[*]
[*]define service{
[*] use local-service
[*] host_name linuxjcq01
[*] service_description 05. The Nginx Status
[*] check_command check_nrpe!check_nginx
[*] }
[*]
[*]define service{
[*] use local-service
[*] host_name linuxjcq01
[*] service_description 06. The Mysql Status
[*] check_command check_nrpe!check_mysql
[*] }
说明:
use 使用的模板名称
host_name 主机名
hostgroup_name 组名
service_description服务的描述
check_command 检查服务时制定的命令,这里的命令和nrpe配置文件中得command对应
每台主机都需要监控的服务,比如负载监控,用户监控,磁盘监控,僵死进程监控,使用主机组hostgroupt_name就好了,可以添加多个组,使用逗号分隔
如果不是所有主机都有的服务,比如监控nginx,监控mysql,使用host_name,后面添加需要的主机名(在hosts.cfg文件中的名字),可以添加多个主机,以逗号作为分隔
5. 检测配置文件是否正确
[*]/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果有报错,根据错误进行调整
6. 启动nagios
[*]service nagios start
7. 配置nginx
[*]vi /usr/local/nginx/etc/conf/vhosts/nagios.cfg
[*]server
[*]{
[*]listen port;
[*]server_namex.x.x.x;
[*]index index.html index.htm index.php;
[*]root/usr/local/nagios/share;
[*]
[*]location ~ ^(.*)\/\.svn\/
[*]{
[*] deny all;
[*]}
[*]
[*]location ~ ^(.*)\/phpinfo.php
[*]{
[*] deny all;
[*]}
[*]
[*]location ~ .*\.(php|php5)?$
[*]{
[*] # fastcgi_passunix:/tmp/php-cgi.sock;
[*] fastcgi_pass192.168.2.11:9000;
[*] fastcgi_index index.php;
[*] include fcgi.conf;
[*] auth_basic "Nagios Access";
[*] auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
[*]}
[*]
[*]location ~ .*\.cgi$
[*]{
[*] root /usr/local/nagios/sbin;
[*] rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
[*] fastcgi_pass 192.168.2.11:10000;
[*] fastcgi_param REMOTE_USER $remote_user;
[*] fastcgi_index index.cgi;
[*] include fcgi.conf;
[*] auth_basic "Nagios Access";
[*] auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
[*]}
[*]
[*]location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
[*]{
[*] root /usr/local/nagios/share/images;
[*] rewrite ^(/nagios)?/images/(.*)$ /$2 break;
[*] expires 30d;
[*] access_log off;
[*]}
[*]
[*]location ~ .*\.(js|css)?$
[*]{
[*] root /usr/local/nagios/share/stylesheets;
[*] rewrite ^(/nagios)?/stylesheets/(.*)$ /$2 break;
[*] expires 1h;
[*] access_log off;
[*]}
[*]
[*]log_formatnagios'$remote_addr - $remote_user [$time_local] [$request_time] "$request"'
[*] '$status $body_bytes_sent "$http_referer"'
[*] '"$http_user_agent" $http_x_forwarded_for';
[*]access_logoff;
[*]}
10000端口的fcgiwrap配置见:http://linuxjcq.blog.运维网.com/3042600/718002
因为nagios为C语言编写的,要运行fastcgi,需要进行以上配置
htpasswd.users为第一节安装nagios时生成的文件,用于Web的认证
重写规则:见上文件
重载nginx使其生效:
[*]nginx -t
[*]nginx -s reload
9. 登录http://x.x.x.x/,输入用户名密码可以看到界面
页:
[1]