分类: LINUX
2011-11-01 13:34:09
下载:
wget
wget
安装:
安装主程序
tar -zxvf nagios-3.3.1.tar.gz
cd nagios
./configure -prefix=/usr/local/nagios
make all
useradd -m nagios
make install
make install-init
make install-config
make install-commandmode
安装插件:
tar -zxvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --prefix=/usr/local/nagios
make
make install
为nagios配置一个apache,架设安装到了/usr/local/apache
修改httpd.conf里面的参数:
修改启动apache 的用户和组,都修改为nagios
并在末尾加入如下
#setting for nagios
ScriptAlias /nagios/cgi-bin /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
Alias /nagios /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
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd louyg
以上命令建立一个合法有权限用户louyg
修改/usr/local/nagios/etc/nagios.cfg注释如下行:
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
command_check_interval=-1 参数改为15s
并加入以下行:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
修改/usr/local/nagios/etc/cgi.cfg:
default_user_name=louyg 设置默认用户名
authorized_for_system_information=nagiosadmin,louyg
authorized_for_configuration_information=nagiosadmin,louyg
authorized_for_system_commands=louyg
authorized_for_all_services=nagiosadmin,louyg
authorized_for_all_hosts=nagiosadmin,louyg
authorized_for_all_service_commands=nagiosadmin,louyg
authorized_for_all_host_commands=nagiosadmin,louyg
注意上面的louyg看自己刚才创建的用户改
修改commands.cfg加入:
define command{
command_name check_http_index
command_line $USER1$/check_http -H $HOSTADDRESS$
}
修改objects/contacts.cfg
define contact{
contact_name louyg
alias system administrator
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email xxxxxxx@qq.com
}
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members louyg
}
新增文件hosts.cfg:
define host {
host_name mp-server1
alias mp-server1
address 75.125.161.146
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 3
notification_period 24x7
notification_options d,u,r
}
define host {
host_name mp-server2
alias mp-server2
address 74.55.14.218
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 3
notification_period 24x7
notification_options d,u,r
}
define host {
host_name mp-server4
alias mp-server4
address 146.185.19.74
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 3
notification_period 24x7
notification_options d,u,r
}
define host {
host_name site5-free
alias site5-free
address
contact_groups admins
max_check_attempts 5
notification_interval 3
notification_period 24x7
notification_options d,u,r
}
新增services.cfg:
define service {
hostgroup_name mp-servers
service_description check_http 80
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups admins
notification_interval 3
notification_period 24x7
notification_options w,u,c,r
check_command check_http!80
}
define service {
hostgroup_name Virtual-host
service_description check_http index
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups admins
notification_interval 3
notification_period 24x7
notification_options w,u,c,r
check_command check_http_index
}
新增hostgroups.cfg:
define hostgroup {
hostgroup_name mp-servers
alias mp-servers
members mp-server1,mp-server2,mp-server4
}
define hostgroup {
hostgroup_name Virtual-host
alias Virtual-host
members site5-free
}
配置完成,使用/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
检查
没有错误的情况下运行服务:
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
在/etc/mail/sendmail.cf的
#Dj$w.Foo.COM行下面加入:
Dj$w.sysMonitor.com
Service sendmail restart
安装nrpe
wget
tar -zxvf nrpe-2.13.tar.gz
./configure --prefix=/usr/local/nrpe
在这一步骤遇到找不到/usr/local/ssl/bin/openssl的错误,所以就从/usr/bin/openssl连接过来一个
mkdir /usr/local/ssl/bin
ln -s /usr/bin/openssl /usr/local/ssl/bin/openssl
重新./configure
make&&make install
安装好以后发现/usr/local/nrpe/libexec下面只有一个check_nrpe,需要和nagios下的libexec互相复制满足使用的要求
cp /usr/local/nrpe/libexec/check_nrpe /usr/local/nagios/libexec/
cp /usr/local/nagios/libexec/check_disk /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_load /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_ping /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_procs /usr/local/nrpe/libexec
cp /usr/local/nagios/libexec/check_users /usr/local/nrpe/libexec
安装完后没有配置文件需要从安装目录复制过来一个
mkdir /usr/local/nrpe/etc
cp ~/nagios/nrpe-2.13/sample-config/nrpe.cfg /usr/local/nrpe/etc/
修改配置文件nrpe.cfg
server_address=192.168.2.78
allowed_hosts=127.0.0.1,192.168.2.78
command[check_users]=/usr/local/nrpe/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nrpe/libexec/check_load -w 15,10,5 -c 30,25,20
#command[check_hda1]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_df]=/usr/local/nrpe/libexec/check_disk -w 20% -c 10%
command[check_zombie_procs]=/usr/local/nrpe/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nrpe/libexec/check_procs -w 150 -c 200
启动nrpe:
bin/nrpe -c etc/nrpe.cfg -d
修改nagios的commands.cfg
添加:
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
在nagios的services.cfg添加:
define service {
hostgroup_name localhost
service_description check-disk
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups admins
notification_interval 3
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_df
}
define service {
hostgroup_name localhost
service_description check-load
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups admins
notification_interval 3
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_load
}
监控mysql:
如果libexec下面没有check_mysql,就需要安装mysql-devel的安装包。然后重新安装nagios_plusin的插件
在被监控机器上面创建一个空库
create database nagdb;
创建一个有select权限的用户nagdb
grant select on nagdb.* to nagdb@'%';
在nagios服务器上面测试:
./check_mysql -H 192.168.2.219 -u nagdb -d nagdb;
在nagios服务器上添加services.cfg:
define service {
hostgroup_name centos_192
service_description check-mysql
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_mysql
}
添加hosts.cfg:
define host {
host_name centos5-219
alias centos219
address 192.168.2.219
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 3
notification_period 24x7
notification_options d,u,r
}
添加hostgroups.cfg
define hostgroup {
hostgroup_name centos_192
alias localhost-78
members centos5-219
}
添加commands.cfg:
# 'check_mysql' command definition
define command{
command_name check_mysql
command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagdb -d nagdb
}
监控mysql主从同步(基于监控从服务器的状态):
在从服务器创建一个用于查询状态的用户:
mysql>grant Replication client on *.* to 'slave_monitor'@'localhost' identified by 'wsxqazedc@';
mysql>flush privileges;
在nrpe.cfg(/usr/local/nrpe/etc/nrpe.cfg)中添加:
command[check_mysql_slave]=/usr/local/nrpe/libexec/check_mysql_slave
在/usr/local/nrpe/libexec/下创建一个check_mysql_slave的文件。内容如下:
#!/bin/sh
declare -a slave_is
slave_is=($(/usr/local/mysql/bin/mysql -unagios -pnagios -e "show slave status\G" | grep Running | awk '{print $2}'))
if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]
then
echo "OK -slave is running"
exit 0
else
echo "Critical -slave is error"
exit 2
fi
然后重启nrpe的服务, bin/nrpe -c etc/nrpe.cfg -d
./check_nrpe -c check_mysql_slave -H 192.168.2.78
查看输出结果。
然后将这个服务添加到nagios里面
添加web管理功能
wget
tar -zxvf nagiosql_311.tar.gz
mv nagiosql /usr/local/nagios/
mkdir -p /etc/nagiosql/{hosts,services,backup/{,hosts,services},import}
chown -R apache:nagios /etc/nagiosql/
chmod -R 755 /etc/nagiosql
chmod 777 /usr/local/nagios/nagiosql/config
chmod -R 664 /usr/local/nagios/etc/*.cfg
chown -R apache:nagios /usr/local/nagios/etc/*.cfg
chown apache:nagios /usr/local/nagios/bin/nagios
chown -R apache:nagios /usr/local/nagios/var/spool/
chown -R apache:nagios /usr/local/nagios/var/rw/nagios.cmd
vi /etc/httpd/conf/httpd.conf 添加:
Alias /nagiosQL "/usr/local/nagios/nagiosql"
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
重启apache
touch /usr/local/nagios/nagiosql/install/ENABLE_INSTALLER
访问 开始安装.
报错:
需要添加php-gettext支持。
在php源码安装包内的config.nice中添加--with-gettext重新编译安装
安装完成后进入管理界面,管理——域——localhost——修改,如下
修改完成后点击保存
工具-导入数据 右边会列出一些配置文件,选择导入即可。
导入只是把配置文件内容导入到Mysql数据库,而使用其配置文件时,是一个个cfg文件,所以下面要进行写入过程
工具-nagios控制-写入检测数据-写入其他数据
重启nagios
注释所有/usr/local/nagios/etc/nagios内调用*.cfg的行:
#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
#cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
#cfg_file=/usr/local/nagios/etc/objects/services.cfg
#cfg_file=/usr/local/nagios/etc/objects/hostgroups.cfg
添加新的行:
cfg_dir=/etc/nagiosql/hosts/
cfg_dir=/etc/nagiosql/services/
cfg_file=/etc/nagiosql/commands.cfg
cfg_file=/etc/nagiosql/contactgroups.cfg
cfg_file=/etc/nagiosql/contacts.cfg
cfg_file=/etc/nagiosql/contacttemplates.cfg
cfg_file=/etc/nagiosql/hostdependencies.cfg
cfg_file=/etc/nagiosql/hostescalations.cfg
cfg_file=/etc/nagiosql/hostextinfo.cfg
cfg_file=/etc/nagiosql/hostgroups.cfg
cfg_file=/etc/nagiosql/hosttemplates.cfg
cfg_file=/etc/nagiosql/servicedependencies.cfg
cfg_file=/etc/nagiosql/serviceescalations.cfg
cfg_file=/etc/nagiosql/serviceextinfo.cfg
cfg_file=/etc/nagiosql/servicegroups.cfg
cfg_file=/etc/nagiosql/servicetemplates.cfg
cfg_file=/etc/nagiosql/timeperiods.cfg