第二部分:Ndoutils的安装

 

  要安装Centreon监控系统,必须首先安装NDOUtils。NDOUtils能够将Nagios搜集到的监控数据存放到Mysql后台数据库中,起到联系Nagios和Centreon两个开源软件之间的纽带作用。

一、下载软件  

cd /usr/local/src/ && wget https://nchc.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz

二、编译安装ndoutils 

  1.编译

tar xf ndoutils-2.1.3.tar.gz && cd ndoutils-2.1.3 && make all

   

  2.手动拷贝所需文件(选择dbhandlers-4x兼容版本)

cd /usr/local/src/ndoutils-2.1.3/src && cp ndomod-4x.o ndo2db-4x log2ndo file2sock /usr/local/nagios/bin/

  

  3.检查和配置mysql配置文件/etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
[client]
default-character-set=utf8
socket=/var/lib/mysql/mysql.sock
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/home/mysql/data #设置mysql数据存储路径
port=33070 #设置mysql端口为33070
skip-name-resolve #设置跳过域名检查
character-set-server=utf8
collation-server=utf8_general_ci
socket = /var/lib/mysql/mysql.sock
max_connections=1000 #设置最大连接数为1000
max_user_connections=500 #设置每用户最大连接数为500
wait_timeout=200 #设置200秒后关闭空闲(IDLE)的连接,但是对正在工作的连接不影响
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

#mater
server-id = 1
log-bin=mysqlmaster-bin
#binlog-do-db = cad #指定需要进行主从的数据库
binlog_cache_size = 4M
binlog_format=mixed
expire_logs_days=3
binlog-ignore-db=test #不记录test库的binlog
replicate-ignore-db=test #不复制test库的binlog
sync_binlog=1
#sql_mod=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

  启动mysql并设置用户名密码

#启动mysqld服务
service mysqld start
#设置mysql ndodb用户并授权、创建数据库nagios
[root@base src]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.36-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create user 'ndodb'@'%' identified by 'ndodb';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> create database nagios;
Query OK, 1 row affected (0.01 sec)

mysql> grant all on nagios.* to ndodb@'%' Identified by "ndodb";
Query OK, 0 rows affected (0.00 sec)

mysql>

  导入数据表:

cd /usr/local/src/ndoutils-2.1.3/db && ./installdb -u ndodb -p ndodb -h localhost -d nagios -P 33070
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 52.
** Creating tables for version 2.0.1
     Using mysql.sql for installation...
Warning: Using a password on the command line interface can be insecure.
** Updating table nagios_dbversion
Done!

  登录到数据库验证是否导入成功:

mysql> use nagios;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------------------------------+
| Tables_in_ndodb                        |
+----------------------------------------+
| nagios_acknowledgements                |
| nagios_commands                        |
| nagios_commenthistory                  |
| nagios_comments                        |
| nagios_configfiles                     |
| nagios_configfilevariables             |
| nagios_conninfo                        |
| nagios_contact_addresses               |
| nagios_contact_notificationcommands    |
| nagios_contactgroup_members            |
| nagios_contactgroups                   |
| nagios_contactnotificationmethods      |
| nagios_contactnotifications            |
| nagios_contacts                        |
| nagios_contactstatus                   |
| nagios_customvariables                 |
| nagios_customvariablestatus            |
| nagios_dbversion                       |
| nagios_downtimehistory                 |
| nagios_eventhandlers                   |
| nagios_externalcommands                |
| nagios_flappinghistory                 |
| nagios_host_contactgroups              |
| nagios_host_contacts                   |
| nagios_host_parenthosts                |
| nagios_hostchecks                      |
| nagios_hostdependencies                |
| nagios_hostescalation_contactgroups    |
| nagios_hostescalation_contacts         |
| nagios_hostescalations                 |
| nagios_hostgroup_members               |
| nagios_hostgroups                      |
| nagios_hosts                           |
| nagios_hoststatus                      |
| nagios_instances                       |
| nagios_logentries                      |
| nagios_notifications                   |
| nagios_objects                         |
| nagios_processevents                   |
| nagios_programstatus                   |
| nagios_runtimevariables                |
| nagios_scheduleddowntime               |
| nagios_service_contactgroups           |
| nagios_service_contacts                |
| nagios_service_parentservices          |
| nagios_servicechecks                   |
| nagios_servicedependencies             |
| nagios_serviceescalation_contactgroups |
| nagios_serviceescalation_contacts      |
| nagios_serviceescalations              |
| nagios_servicegroup_members            |
| nagios_servicegroups                   |
| nagios_services                        |
| nagios_servicestatus                   |
| nagios_statehistory                    |
| nagios_systemcommands                  |
| nagios_timedeventqueue                 |
| nagios_timedevents                     |
| nagios_timeperiod_timeranges           |
| nagios_timeperiods                     |
+----------------------------------------+
60 rows in set (0.00 sec)

  

三、配置NDOutils

  如果想使用NDOutils组件和nagios工具协作顺畅,就必须对两者做相关配置,步骤如下:

  1.拷贝配置文件

cd /usr/local/src/ndoutils-2.1.3/config && cp ndo* /usr/local/nagios/etc/

  

  2.修改配置文件

cd /usr/local/nagios/etc/ && mv ndo2db.cfg-sample ndo2db.cfg

  配置文件ndo2db.cfg修改如下:(主要修改三处地方:mysql端口、mysql用户名、mysql用户名密码)

#####################################################################
# NDO2DB DAEMON CONFIG FILE
#
# Last Modified: 01-02-2009
#####################################################################



# LOCK FILE
# This is the lockfile that NDO2DB will use to store its PID number
# in when it is running in daemon mode.

lock_file=/usr/local/nagios/var/ndo2db.pid



# USER/GROUP PRIVILEGES
# These options determine the user/group that the daemon should run as.
# You can specify a number (uid/gid) or a name for either option.

ndo2db_user=nagios
ndo2db_group=nagios



# SOCKET TYPE
# This option determines what type of socket the daemon will create
# an accept connections from.
# Value:
#   unix = Unix domain socket (default)
#   tcp  = TCP socket

socket_type=unix
#socket_type=tcp



# SOCKET NAME
# This option determines the name and path of the UNIX domain 
# socket that the daemon will create and accept connections from.
# This option is only valid if the socket type specified above
# is "unix".

socket_name=/usr/local/nagios/var/ndo.sock



# TCP PORT
# This option determines what port the daemon will listen for
# connections on.  This option is only vlaid if the socket type
# specified above is "tcp".

tcp_port=5668



# ENCRYPTION
# This option determines if the ndo2db daemon will accept SSL to encrypt the 
# network traffic between module and ndo2db daemon.
# Both sides have to enable this feature which depends on SSL Libraries
# like openssl or kerberos 
# This option is only valid if the output type
# option specified above is "tcpsocket".
#
# A value of '1' will enable this feature

use_ssl=0



# DATABASE SERVER TYPE
# This option determines what type of DB server the daemon should connect to.
# Values:
#   mysql = MySQL

db_servertype=mysql



# DATABASE HOST
# This option specifies what host the DB server is running on.

db_host=localhost



# DATABASE PORT
# This option specifies the port that the DB server is running on.
# Values:
#  3306 = Default MySQL port

db_port=33070



# DATABASE SOCKET
# This option specifies the path to the socket to use for local DB connections.
#
# MySQL's default location is /tmp/mysql.sock, but /var/lib/mysql/mysql.sock
# is common for RPM distributions, and /var/run/mysqld/mysqld.sock is seen on
# Ubuntu...
#
# You normally do not need to set this option unless you experience connection
# problems with messages in NDO2DB's log like:
#   "Can't connect to local MySQL server through socket ..."

#db_socket=/var/lib/mysql/mysql.sock



# DATABASE NAME
# This option specifies the name of the database that should be used.

db_name=nagios



# DATABASE TABLE PREFIX
# Determines the prefix (if any) that should be prepended to table names.
# If you modify the table prefix, you'll need to modify the SQL script for
# creating the database!

db_prefix=nagios_



# DATABASE USERNAME/PASSWORD
# This is the username/password that will be used to authenticate to the DB.
# The user needs at least SELECT, INSERT, UPDATE, and DELETE privileges on
# the database.

db_user=ndodb
db_pass=ndodb



## TABLE TRIMMING OPTIONS
# Several database tables containing Nagios event data can become quite large
# over time.  Most admins will want to trim these tables and keep only a
# certain amount of data in them.  The options below are used to specify the
# age (in MINUTES) that data should be allowd to remain in various tables
# before it is deleted.  Using a value of zero (0) for any value means that
# that particular table should NOT be automatically trimmed.

# Keep timed events for 24 hours
max_timedevents_age=1440

# Keep system commands for 1 week
max_systemcommands_age=10080

# Keep service checks for 1 week
max_servicechecks_age=10080

# Keep host checks for 1 week
max_hostchecks_age=10080

# Keep event handlers for 31 days
max_eventhandlers_age=44640

# Keep external commands for 31 days
max_externalcommands_age=44640

# Keep notifications for 31 days
max_notifications_age=44640

# Keep contactnotifications for 31 days
max_contactnotifications_age=44640

# Keep contactnotificationmethods for 31 days
max_contactnotificationmethods_age=44640

# Keep logentries for 90 days
max_logentries_age=129600

# Keep acknowledgements for 31 days
max_acknowledgements_age=44640



# DEBUG LEVEL
# This option determines how much (if any) debugging information will
# be written to the debug file.  OR values together to log multiple
# types of information.
# Values: -1 = Everything
#          0 = Nothing
#          1 = Process info
#	   2 = SQL queries

debug_level=0



# DEBUG VERBOSITY
# This option determines how verbose the debug log out will be.
# Values: 0 = Brief output
#         1 = More detailed
#         2 = Very detailed

debug_verbosity=1



# DEBUG FILE
# This option determines where the daemon should write debugging information.

debug_file=/usr/local/nagios/var/ndo2db.debug



# MAX DEBUG FILE SIZE
# This option determines the maximum size (in bytes) of the debug file.  If
# the file grows larger than this size, it will be renamed with a .old
# extension.  If a file already exists with a .old extension it will
# automatically be deleted.  This helps ensure your disk space usage doesn't
# get out of control when debugging.

max_debug_file_size=1000000


# MAX OUTPUT BUFFER SIZE
# This option determines the maximum size (in bytes) of the output buffer. 
# NDO2DB will start truncating characters after this value.
# If you have very large long output and you're not seeing it all in the database,
# try increasing this number.
# IMPORTANT NOTE: The 'long_output' fields in the database are set to TEXT fields, and the maximum
# size of a TEXT field is 64KB, so if you really want to make use of this field, you'll need to set
# the long_output fields to MEDIUMTEXT OR LONGTEXT.
# the long_output column exists in the following tables:
#  _eventhandlers, _hostchecks, _hoststatus, _notifications, _servicechecks, _servicestatus, _statehistory, _systemcommands
# An example sql alter statement might look like this:
# ALTER TABLE nagios_hoststatus MODIFY COLUMN long_output LONGTEXT NOT NULL DEFAULT '';
max_output_buffer_size=65536

  3.修改nagios配置文件:/usr/local/nagios/etc/nagios.conf

#注意:该配置只有一行,不可手动换行
broker_module=/usr/local/nagios/bin/ndomod-4x.o config_file=/usr/local/nagios/etc/ndomod.cfg

#复制ndomod.cfg
cp /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

  

  4.设置ndo2db启动方式:

#源码中有多种方式可以启动nd02db,这里设置成init方式管理
cp /usr/local/src/ndoutils-2.1.3/startup/default-init /etc/init.d/ndo2db
#修改/etc/init.d/ndo2db
修改
NDO2DB_BIN=/usr/local/nagios/bin/ndo2db-4x 
#设置成开机自启
chkconfig ndo2db on
#!/bin/sh
#
# Copyright (c) 2016 Nagios(R) Core(TM) Development Team
#
# chkconfig: - 80 30
# description: Starts and stops the Nagios Data Out Daemon \
#              to store data in a database

#
### BEGIN INIT INFO
# Provides:           ndo2db
# Required-Start:     $local_fs $remote_fs $time
# Required-Stop:      $local_fs $remote_fs
# Should-Start:       $syslog $network
# Should-Stop:        $syslog $network
# Default-Start:      2 3 4 5
# Default-Stop:       0 1 6
# Short-Description:  Starts and stops the Nagios Data Out Daemon
# Description:        Starts and stops the Nagios Data Out Daemon
#                     to store data in a database
### END INIT INFO

export SYSTEMCTL_SKIP_REDIRECT=1

NDO2DB_BIN=/usr/local/nagios/bin/ndo2db-4x
NDO2DB_CFG=/usr/local/nagios/etc/ndo2db.cfg
LOCK_DIR=/var/lock/subsys
LOCK_FILE=/var/lock/subsys/ndo2db
PID_FILE=/usr/local/nagios/var/ndo2db.pid

test -x $NDO2DB_BIN || exit 5

RETVAL=0

# Default these commands/functions to RedHat/CentOS etc. values
MSG_CMD="echo -n"
START_CMD="daemon --pidfile $PID_FILE"
TERM_CMD="killproc -p $PID_FILE $NDO2DB_BIN -TERM"
HUP_CMD="killproc -p $PID_FILE $NDO2DB_BIN -HUP"
PRT_STAT="echo"
STAT_MSG="echo -n Checking for ndo2db daemon... "
STAT_CMD="status ndo2db"
EXIT_CMD="exit"

_set_rc (){ return; }

# Source the function library
if [ -f /etc/rc.status ]; then

    . /etc/rc.status

    _set_rc (){ return $RETVAL; }

    # Set these commands/functions to SuSE etc. values
    START_CMD="startproc -p $PID_FILE"
    TERM_CMD="killproc -p $PID_FILE -TERM $NDO2DB_BIN"
    HUP_CMD="killproc -p $PID_FILE -HUP $NDO2DB_BIN"
    PRT_STAT="rc_status -v -r"
    STAT_CMD="checkproc -p $PID_FILE $NDO2DB_BIN"
    EXIT_CMD="rc_exit"
    rc_reset

elif [ -f /etc/rc.d/init.d/functions ]; then

    . /etc/rc.d/init.d/functions

elif [ -f /etc/init.d/functions ]; then

    . /etc/init.d/functions

elif [ -f /lib/lsb/init-functions ]; then

    . /lib/lsb/init-functions

    MSG_CMD="log_daemon_msg"
    START_CMD="start_daemon -p $PID_FILE"
    PRT_STAT="log_end_msg"
    STAT_MSG=
    STAT_CMD="status_of_proc -p $PID_FILE $NDO2DB_BIN ndo2db"

elif [ -f /etc/rc.d/functions ]; then

    . /etc/rc.d/functions

fi


# See how we were called.
case "$1" in

start)
    # Start daemons.
    $MSG_CMD "Starting ndo2db "
    $START_CMD $NDO2DB_BIN -c $NDO2DB_CFG
    RETVAL=$?
    if test "$PRT_STAT" = log_end_msg; then
        $PRT_STAT $RETVAL
    else
        _set_rc; $PRT_STAT
    fi
    if [ $RETVAL = 0 ]; then
        [ -d $LOCK_DIR ] && touch $LOCK_FILE || true
    fi
    ;;

stop)
    # Stop daemons.
    $MSG_CMD "Shutting down ndo2db "
    $TERM_CMD
    RETVAL=$?
    if test "$PRT_STAT" = log_end_msg; then
        $PRT_STAT $RETVAL
    else
        _set_rc; $PRT_STAT
    fi
    if [ $RETVAL = 0 ]; then
        [ -d $LOCK_DIR ] && rm -f $LOCK_FILE
    fi
    ;;

restart|force-reload)
    $0 stop
    $0 start
    RETVAL=$?
    ;;

try-restart|condrestart)
    $STAT_CMD || exit 0
    $0 stop
    $0 start
    RETVAL=$?
    ;;

status)
    $STAT_MSG
    $STAT_CMD
    RETVAL=$?
    if test "$PRT_STAT" != log_end_msg; then
        _set_rc; $PRT_STAT
    fi
    ;;

*)
    echo "Usage: ndo2db {start|stop|restart|try-restart|condrestart|status}"
    exit 1
esac

$EXIT_CMD $RETVAL
/etc/init.d/ndo2db

 5.增加/etc/service文件中的服务端口

ndo2db		5668/tcp		# nagios-ndo2db
ndo2db		5668/udp		# nagios-ndo2db

  启动ndo2db:service ndo2db start 

  验证是否已经启动

[root@base etc]# ps -ef |grep [n]do
nagios   32461     1  0 19:56 ?        00:00:00 /usr/local/nagios/bin/ndo2db-4x -c /usr/local/nagios/etc/ndo2db.cfg

  

 

posted @ 2017-06-10 18:48  南非波波  阅读(480)  评论(0编辑  收藏  举报