4月 172013
 

确定将要使用的在templates.cfg已定义的主机模板

在主配置文件中取消注释以下内容

 #cfg_dir=/usr/local/nagios/etc/servers

创建目录

[root@monitor objects]# mkdir ../servers
 [root@monitor objects]# chown -R nagios.nagios ../servers/
 [root@monitor objects]# chmod -R 775 ../servers/

创建主机组配置文件szvs.cfg并添加主机

define hostgroup{
 hostgroup_name  v-servers
 alias           Virtualization Servers
 members         szvs-v01
 }

创建主机配置文件szvs-v01.cfg

定义主机部分,使用linux-server主机模板

define host{
 use                     linux-server
 host_name               szvs-v01
 alias                   app
 address                 192.168.1.90
 }

定义服务部分

引用的服务模板generic-service来自模板配置文件

define service{
 use                             generic-service
 host_name                       szvs-v01
 service_description             PING
 check_command                   check_ping!100.0,20%!500.0,60%
 notifications_enabled           0
 }
define service{
 use                             generic-service
 host_name                       szvs-v01
 service_description             HTTP
 check_command                   check_http
 notifications_enabled           0
 }

检测当前配置文件正确性

[root@monitor objects]# ../../bin/nagios -v ../nagios.cfg

Nagios Core 3.5.0
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-15-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data…
Read main config file okay…
Processing object config file ‘/usr/local/nagios/etc/objects/commands.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/contacts.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/timeperiods.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/templates.cfg’…
Processing object config file ‘/usr/local/nagios/etc/objects/localhost.cfg’…
Processing object config directory ‘/usr/local/nagios/etc/servers’…
Processing object config file ‘/usr/local/nagios/etc/servers/szvs.cfg’…
Processing object config file ‘/usr/local/nagios/etc/servers/szvs-v01.cfg’…
Read object config files okay…

Running pre-flight check on configuration data…

Checking services…
Checked 9 services.
Checking hosts…
Checked 2 hosts.
Checking host groups…
Checked 2 host groups.
Checking service groups…
Checked 0 service groups.
Checking contacts…
Checked 1 contacts.
Checking contact groups…
Checked 1 contact groups.
Checking service escalations…
Checked 0 service escalations.
Checking service dependencies…
Checked 0 service dependencies.
Checking host escalations…
Checked 0 host escalations.
Checking host dependencies…
Checked 0 host dependencies.
Checking commands…
Checked 24 commands.
Checking time periods…
Checked 5 time periods.
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…

Total Warnings: 0
Total Errors:   0

Things look okay – No serious problems were detected during the pre-flight check
[root@monitor objects]#

重启nagios服务

[root@monitor objects]# service nagios restart
 Running configuration check...done.
 Stopping nagios: .done.
 Starting nagios:This account is currently not available.
 done.
 [root@monitor objects]#

查看重启以后的nagios日志信息

nagios-config-01-01

 

查看主机地图

nagios-config-01-02

查看主机列表

nagios-config-01-03

查看服务列表

nagios-config-01-04

 

 

查看主机组列表

nagios-config-01-05

检测项目的任务队列

首次添加的任务显示为PENDING状态,等待检测

nagios-config-01-06

查看任务队列中的检测时间排列

nagios-config-01-07

成功执行新添加的HTTP服务检测nagios-config-01-08

4月 172013
 

……

nagios-monitor-01

主配置文件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/localhost.cfg

Localhost监控对象配置文件分析

定义主机

define host{
        use                     linux-server
        host_name               localhost
        alias                   localhost
        address                 127.0.0.1
        }

use 定义当前主机使用的主机模板,引用在templates.cfg中已定义的linux-server主机模板
hostname 定义显示在nagios web管理界面中的主机名称
alias 别名,主机名的完整描述
address 定义当前主机IP地址

定义主机组

 define hostgroup{
 hostgroup_name  linux-servers
 alias           Linux Servers
 members         localhost
 }

主机组用来定相似服务类型或处于同一地域的一组主机
hostgroup_name 定义当前主机组名称
alias 主机组别名,主机组名称的完整描述
members 定义当前主机组中包含的主机,使用已定义主机名称并使用逗号分隔

定义服务(定义具体的监控项目)

监控已定义主机localhost的ping响应
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             PING
check_command                   check_ping!100.0,20%!500.0,60%
}

use 引用在templates.cfg中已定义的服务模板
hostname 指定启用此监控项目的已定义的主机名
service_description 显示在nagios web界面的服务名称
check_command

配置文件中检测命令的完整工作过程

查看

[root@monitor objects]# pwd
 /usr/local/nagios/etc/objects
[root@monitor objects]# ls ../../libexec/check_ping
 ../../libexec/check_ping
[root@monitor objects]#
[root@monitor objects]# ../../libexec/check_ping
 check_ping: Could not parse arguments
 Usage:
 check_ping -H <host_address> -w <wrta>,<wpl>% -c <crta>,<cpl>%
[-p packets] [-t timeout] [-4|-6]
[root@monitor objects]#

-w 指定警告数值和百分比
-c 指定临界数值和百分比

nagios检测命令的完整格式及返回结果

[root@monitor objects]# ../../libexec/check_ping -H localhost -w 100.0,20% -c 500.0,60%
 PING OK - Packet loss = 0%, RTA = 0.05 ms|rta=0.046000ms;100.000000;500.000000;0.000000 pl=0%;20;60;0
 [root@monitor objects]#

响应时间达到或超过100毫秒进入警告状态,响应时间达到或超过500毫秒进入临界状态
检测得到的实际响应时间为0.05毫秒

监控已定义主机的localhost的根分区(/)可用磁盘容量

define service{
 use                             local-service         ; Name of service template to use
 host_name                       localhost
 service_description             Root Partition
 check_command                   check_local_disk!20%!10%!/
 }

check_command中的check_local_disk实际为引用命令定义文件commands.cfg已定义命令名称
# ‘check_local_disk’ command definition
define command{
command_name    check_local_disk
command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}

nagios检测命令的完整格式及返回结果
[root@monitor libexec]# ./check_disk
check_disk: Could not parse arguments
Usage:
check_disk -w limit -c limit [-W limit] [-K limit] {-p path | -x device}
[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]
[-t timeout] [-u unit] [-v] [-X type]
[root@monitor libexec]# ./check_disk -w 20% -c 10% -p /
DISK OK – free space: / 45970 MB (96% inode=98%);| /=1866MB;40316;45356;0;50396
[root@monitor libexec]#

监控已定义主机的localhost的当前登录用户
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             Current Users
check_command                   check_local_users!20!50
}

监控已定义主机的localhost的进程数量
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             Total Processes
check_command                   check_local_procs!250!400!RSZDT
}

监控已定义主机的localhost的负载状态
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             Current Load
check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}

监控已定义主机的localhost的磁盘交换空间使用状态
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             Swap Usage
check_command                   check_local_swap!20!10
}

监控已定义主机的localhost的ssh服务或端口开启状态
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             SSH
check_command                   check_ssh
notifications_enabled           0
}

监控已定义主机的localhost的web服务或80端口状态
define service{
use                             local-service         ; Name of service template to use
host_name                       localhost
service_description             HTTP
check_command                   check_http
notifications_enabled           0
}

4月 162013
 

……44

dsdf

[root@localhost nagios]# useradd nagios -s /sbin/nologin
[root@localhost nagios]# groupadd nagcmd
[root@localhost nagios]#
[root@localhost nagios]# usermod -a -G nagcmd nagios
[root@localhost nagios]# usermod -a -G nagcmd apache

安装编译工具

yum install gcc make

编译Nagios时缺少GD相关软件开发包

*** GD, PNG, and/or JPEG libraries could not be located... *********

安装GD及相关软件开发包

[root@localhost nagios]# yum install gd-devel libpng-devel libjpeg-devel

nagios-install-01

编译安装

[root@localhost nagios]# ./configure --prefix=/usr/local/nagios \
> --with-nagios-user=nagios --with-nagios-group=nagios \
> --with-command-user=apache --with-command-group=nagcmd
[root@localhost nagios]# make all
[root@localhost nagios]# make install
[root@localhost nagios]# make install-init
[root@localhost nagios]# make install-config
[root@localhost nagios]# make install-commandmode
[root@localhost nagios]# make install-webconf

生成登录用户及密码

[root@localhost nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
 New password:
 Re-type new password:
 Adding password for user nagiosadmin
[root@localhost nagios]#

 

service httpd restart

错误分析

make[2]: *** [check_http.o] Error 1
make[2]: Leaving directory `/root/nagios-plugins-1.4.16/plugins'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/nagios-plugins-1.4.16'
make: *** [all] Error 2

yum install openssl-devel

[root@localhost nagios-plugins-1.4.16]#
./configure –with-nagios-user=nagios –with-nagios-group=nagios
[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@monitor ~]# chkconfig –add nagios
[root@monitor ~]# service nagios start
Starting nagios:This account is currently not available.
done.
[root@monitor ~]#

nagios-install-02

nagios-install-03

 

nagios-install-04

 

nagios-install-05

 

nagios-install-06

相关下载:
(1) Nagios Core 3.5.0 (2) Nagios Plugin 1.4.16

4月 112013
 

错误截图

horde-gw504-nag-01

 

horde-gw504-nag-02

Apache日志错误信息

[Thu Apr 11 13:04:14 2013] [error] [client 192.168.1.151] File does 
not exist: /usr/local/apache/htdocs/nag/t, referer: http://192.168.1.91/
nag/task.php?actionID=add_task&tasklist_id=X5yeu93S9bFpbSOtsSw7Gw1

horde-gw504-nag-03

horde-gw504-nag-04

修改

[root@mail htdocs]# vi /usr/local/apache/conf/httpd.conf
<Directory "/usr/local/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory

相关内容:
(1) Horde Bug Tracker

4月 102013
 

安装必要条件

为Horde Groupware编译受支持的PHP5.3.22运行环境

# yum install openssl-devel libpng-devel \
libjpeg-devel libicu-devel libtidy-devel \
libc-client-devel \
autoconf ImageMagick-devel libssh2-devel

配置并编译PHP

 ./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-pdo-mysql=/usr/local/mysql \
--with-libxml-dir=/usr/local/libxml2 \

--enable-mbstring \
--with-kerberos --with-imap-ssl \
--with-imap=/usr/local/dovecot/include/dovecot/ \

--with-gettext --with-tidy \
--with-gd --with-png-dir --with-jpeg-dir \
--with-openssl --enable-intl \

--enable-ftp --with-zlib \

错误分析–enable-intl

checking for location of ICU headers and libraries... not found
configure: error: Unable to detect ICU prefix or no failed. Please verify ICU
 install prefix and make sure icu-config works.

#yum install libicu-devel

错误分析 –with-tidy

checking for TIDY support... yes
configure: error: Cannot find libtidy

# yum install libtidy-devel

 

Horde建议安装的PHP Extension Community Library

错误分析 pecl install

Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

# yum install autoconf

安装imagick

# pecl install imagick

安装成功并在配置文件中添加PHP扩展

install ok: channel://pecl.php.net/imagick-3.0.1
configuration option “php_ini” is not set to php.ini location
You should add “extension=imagick.so” to php.ini

horde-groupware-504-01

错误分析 pecl install imagick

checking ImageMagick MagickWand API configuration program... 
configure: error: not found. Please provide a path to
 MagickWand-config or Wand-config program.
ERROR: `/tmp/pear/temp/imagick/configure --with-imagick' failed

# yum install ImageMagick-devel

安装lzf

horde-groupware-504-02 horde-groupware-504-03

安装memcache

horde-groupware-504-04

horde-groupware-504-05

使用PEAR在线安装horde groupware

1

[root@localhost ~]# pear channel-discover pear.horde.org
Adding Channel "pear.horde.org" succeeded
Discovery of channel "pear.horde.org" succeeded
[root@localhost ~]#

2

[root@localhost ~]# pear install horde/horde_role
downloading Horde_Role-1.0.1.tgz ...
Starting to download Horde_Role-1.0.1.tgz (10,977 bytes)
.....done: 10,977 bytes
install ok: channel://pear.horde.org/Horde_Role-1.0.1
horde/Horde_Role has post-install scripts:
/usr/share/pear/PEAR/Installer/Role/Horde/Role.php
Horde_Role: Use "pear run-scripts horde/Horde_Role" to finish setup.
DO NOT RUN SCRIPTS FROM UNTRUSTED SOURCES
[root@localhost ~]#

3

[root@localhost ~]# pear run-scripts horde/Horde_Role
Including external post-installation script "/usr/local/php/lib/php/PEAR
/Installer/Role/Horde/Role.php" - any errors are in this script
Inclusion succeeded
running post-install script "Horde_Role_postinstall->init()"
init succeeded
Filesystem location for the base Horde application : /usr/local/apache/htdocs
Configuration successfully saved to PEAR config.
Install scripts complete
[root@localhost ~]#

4

# pear install horde/webmail

安装成功

install ok: channel://pear.horde.org/Horde_Crypt-2.1.3
install ok: channel://pear.horde.org/Horde_Notification-2.0.1
install ok: channel://pear.horde.org/Horde_Core-2.4.3
install ok: channel://pear.horde.org/content-2.0.2
install ok: channel://pear.horde.org/timeobjects-2.0.3
install ok: channel://pear.horde.org/Horde_Form-2.0.3
install ok: channel://pear.horde.org/Horde_Rpc-2.0.3
install ok: channel://pear.horde.org/horde-5.0.4
install ok: channel://pear.horde.org/imp-6.0.4
install ok: channel://pear.horde.org/ingo-3.0.3
install ok: channel://pear.horde.org/kronolith-4.0.4
install ok: channel://pear.horde.org/mnemo-4.0.3
install ok: channel://pear.horde.org/nag-4.0.2
install ok: channel://pear.horde.org/turba-4.0.3
install ok: channel://pear.horde.org/webmail-5.0.4

查看文件

horde-groupware-504-06

为HORDE GROUPWARE 5.0.4创建数据并授权

mysql> create database groupware;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on groupware.* to groupware;
Query OK, 0 rows affected (0.00 sec)

mysql> grant all on groupware.* to groupware@localhost;
Query OK, 0 rows affected (0.00 sec)

mysql> set password for groupware@localhost=password(‘gwpasswd’);
Query OK, 0 rows affected (0.00 sec)

 

[root@localhost ~]# pear config-get bin_dir
/usr/local/php/bin

horde-groupware-504-07

 

horde-groupware-504-08

horde-groupware-504-09

 

horde-groupware-504-10

修改配置文件启用测试页面

[root@localhost ~]# vi /usr/local/apache/htdocs/config/conf.php
$conf['testdisable'] = false;

horde-groupware-504-11

修改Webmail目录及文件所有者为apache用户和组

[root@localhost ~]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# chown -R apache.apache .

……

horde-groupware-504-12

[root@localhost ~]# pear install HTTP_WebDAV_Server
Failed to download pear/HTTP_WebDAV_Server within preferred state “stable”, latest release is version 1.0.0RC8, stability “beta”, use “channel://pear.php.net/HTTP_WebDAV_Server-1.0.0RC8” to install
install failed
[root@localhost ~]# pear install channel://pear.php.net/HTTP_WebDAV_Server-1.0.0RC8
downloading HTTP_WebDAV_Server-1.0.0RC8.tar …
Starting to download HTTP_WebDAV_Server-1.0.0RC8.tar (Unknown size)
…………………………….done: 159,744 bytes
install ok: channel://pear.php.net/HTTP_WebDAV_Server-1.0.0RC8
[root@localhost ~]#

horde-groupware-504-13

[root@localhost ~]# pear install Net_SMTP
WARNING: “pear/Auth_SASL” is deprecated in favor of “pear/Auth_SASL2”
downloading Net_SMTP-1.6.1.tar …
Starting to download Net_SMTP-1.6.1.tar (Unknown size)
…………….done: 65,024 bytes
install ok: channel://pear.php.net/Net_SMTP-1.6.1
[root@localhost ~]#

horde-groupware-504-14

[root@localhost ~]# pear install XML_Serializer
Failed to download pear/XML_Serializer within preferred state “stable”, latest release is version 0.20.2, stability “beta”, use “channel://pear.php.net/XML_Serializer-0.20.2” to install
install failed
[root@localhost ~]# pear install channel://pear.php.net/XML_Serializer-0.20.2
WARNING: “pear/XML_Parser” is deprecated in favor of “pear/XML_Parser2”
downloading XML_Serializer-0.20.2.tar …
Starting to download XML_Serializer-0.20.2.tar (Unknown size)
…………………………………………………done: 273,408 bytes
downloading XML_Parser-1.3.4.tar …
Starting to download XML_Parser-1.3.4.tar (Unknown size)
…done: 90,624 bytes
install ok: channel://pear.php.net/XML_Parser-1.3.4
install ok: channel://pear.php.net/XML_Serializer-0.20.2
[root@localhost ~]#

horde-groupware-504-15

配置IMP邮件服务器端参数

[root@localhost ~]# cd /usr/local/apache/htdocs/imp/config/
[root@localhost config]# cp backends.php backends.local.php
[root@localhost config]# vi backends.local.php

登录

horde-groupware-504-16

horde-groupware-504-17

 

horde-groupware-504-18

关闭测试页面

horde-groupware-504-19

错误分析

# cat /usr/local/apache/logs/error_log
[Wed Apr 10 02:16:46 2013] [error] [client 192.168.1.151] PHP Warning:  phpinfo() [<a href=’function.phpinfo’>function.phpinfo</a>]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Chongqing’ for ‘CST/8.0/no DST’ instead in /usr/local/apache/htdocs/php.php on line 1

修改php.ini时区设置

# vi /usr/local/php/lib/php.ini
date.timezone = Asia/Chongqing