Skip to content

Latest commit

 

History

History
363 lines (292 loc) · 14.3 KB

4.pull-data-to-mysql.md

File metadata and controls

363 lines (292 loc) · 14.3 KB

https://monitoring-portal.org/index.php?thread/29283-omd-ndo2db/

Hướng dẫn đẩy dữ liệu từ OMD ra MySQL.

1. Cài đặt MariaDB và các gói hỗ trợ.

  • Cài đặt MariaDB :

    yum install -y mariadb mariadb-server mariadb-devel
  • Các gói dịch vụ đi kèm :

    yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip httpd php php-fpm curl wget -y
  • Khởi động MariaDB :

    systemctl start mariadb.service
  • Cấu hình tự khởi động cùng hệ thống :

    systemctl enable mariadb.service
  • Cấu hình mật khẩu cho MariaDB :

    /usr/bin/mysqladmin -u root password 'mypassword'

2. Tạo cơ sở dữ liệu.

  • Tạo một cơ sở dữ liệu mới với tên là nagios :

    CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
  • Tajo user monitoring :

    CREATE USER 'monitoring'@'localhost' IDENTIFIED BY 'mypass';
  • Gán quyền cho user trong CSDL đó :

    grant all privileges on nagios.* to 'monitoring'@localhost identified by "mypass" with grant option;
  • Nếu lỡ tay coppy toàn bộ dòng trên, thay đổi lại mật khẩu cho user vừa tạo như sau :

    use mysql;
    set password for 'monitoring'@localhost = PASSWORD('mypass');
    
    # mypass là password muốn đặt cho user đó.
    flush privileges;

3. Tải và cài đặt NDOutils.

  • Download bản ndo2db v1.5.2 :

    cd /tmp
    wget http://downloads.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnagios%2Ffiles%2Fndoutils-1.x%2Fndoutils-1.5.2%2F&ts=1379408959&use_mirror=heanet
  • Giải nén :

    tar xvf ndoutils-1.5.2.tar.gz
  • Tiến hành cài đặt :

    cd ndoutils-1.5.2
    ./configure --prefix=/omd/sites/monitoring/usr/local/nagios/ --enable-mysql --disable-pgsql --with-ndo2db-user=monitoring -with-ndo2db-group=monitoring --with-mysql-lib=/usr/lib/mysql
    
  • complie :

    make
    make all
    make install-config
    cd /src
    /usr/bin/install -c -m 775 -o monitoring -g monitoring -d /omd/sites/monitoring/usr/local/nagios/bin
    /usr/bin/install -c -m 755 -o monitoring -g monitoring ndo2db-3x /omd/sites/monitoring/usr/local/nagios/bin/ndo2db
    /usr/bin/install -c -m 755 -o monitoring -g monitoring ndomod-3x.o /omd/sites/monitoring/usr/local/nagios/bin/ndomod.o
    /usr/bin/install -c -m 774 -o monitoring -g monitoring file2sock /omd/sites/monitoring/usr/local/nagios/bin
    /usr/bin/install -c -m 774 -o monitoring -g monitoring log2ndo /omd/sites/monitoring/usr/local/nagios/bin
    /usr/bin/install -c -m 774 -o monitoring -g monitoring sockdebug /omd/sites/monitoring/usr/local/nagios/bin
    
  • Initialize Database :

    cd /db
    ./installdb -u monitoring -p mypass -h localhost -d nagios

4. Cấu hình.

  • Tạo các thư mục sau :

    mkdir -p /omd/sites/monitoring/usr/local/nagios/var
    mkdir -p /omd/sites/monitoring/usr/local/nagios/bin
  • Coppy những file cấu hình đến những thư mục vừa tạo như sau :

    cp /tmp/ndoutils-1.5.2/src/ndomod-3x.o /omd/sites/monitoring/usr/local/nagios/bin/ndomod.o
    cp /tmp/ndoutils-1.5.2/src/ndo2db-3x /omd/sites/monitoring/usr/local/nagios/bin/ndo2db
  • Coppy 2 file cấu hình sau :

    cp /omd/sites/monitoring/usr/local/nagios/etc/ndo2db.cfg-sample /omd/sites/monitoring/usr/local/nagios/etc/ndo2db.cfg
    cp /omd/sites/monitoring/usr/local/nagios/etc/ndomod.cfg-sample /omd/sites/monitoring/usr/local/nagios/etc/ndomod.cfg 
  • Mở file cấu hình ndo2db.cfg :

    vi /omd/sites/monitoring/usr/local/nagios/etc/ndo2db.cfg
  • Tìm và sửa lại các thông tin cấu hình như sau :

    db_user=monitoring
    db_pass=mypass
  • Install deamon-init :

    /usr/bin/install -c -m 755 -o root -g root -d /etc/rc.d/init.d
    /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/ndo2db
  • Mở file init-daemon ndo2db :

vi /etc/init.d/ndo2db
  • Tìm và sửa các dòng sau với nội dung :

    Ndo2dbUser=monitoring
    Ndo2dbGroup=monitoring
  • Enable và Start ndo2db :

    systemctl enable ndo2db.service
    systemctl start ndo2db.service
  • Thực hiện commands sau để tạo Broker Module :

    printf "\n\n# NDOUtils Broker Module\n" >> /omd/sites/monitoring/etc/nagios/nagios.cfg
    printf "broker_module=/omd/sites/monitoring/usr/local/nagios/bin/ndomod.o config_file=/omd/sites/monitoring/usr/local/nagios/etc/ndomod.cfg\n" >> /omd/sites/monitoring/etc/nagios/nagios.cfg
  • Restart service :

    omd restart
    systemctl restart ndo2db.service
  • Kiểm tra log từ /omd/sites/monitoring/var/log/nagios.log :

    Caught SIGTERM, shutting down...
    [1510494712] Successfully shutdown... (PID=11664)
    [1510494712] ndomod: Shutdown complete.
    [1510494712] Event broker module '/omd/sites/monitoring/usr/local/nagios/bin/ndomod.o' deinitialized successfully.
    [1510494712] npcdmod: If you don't like me, I will go out! Bye.
    [1510494712] Event broker module '/omd/sites/monitoring/lib/npcdmod.o' deinitialized successfully.
    [1510494712] livestatus: deinitializing
    [1510494712] livestatus: waiting for main to terminate...
    [1510494713] livestatus: waiting for client threads to terminate...
    [1510494713] livestatus: could not join thread main
    [1510494713] livestatus: main thread + 20 client threads have finished
    [1510494713] Event broker module '/omd/sites/monitoring/lib/mk-livestatus/livestatus.o' deinitialized successfully.
    [1510494715] Nagios 3.5.0 starting... (PID=12062)
    [1510494715] Local time is Sun Nov 12 20:51:55 ICT 2017
    [1510494715] LOG VERSION: 2.0
    [1510494715] ndomod: NDOMOD 1.5.2 (06-08-2012) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
    [1510494715] ndomod: Could not open data sink!  I'll keep trying, but some output may get lost...
    [1510494715] Event broker module '/omd/sites/monitoring/usr/local/nagios/bin/ndomod.o' initialized successfully.
    [1510494715] npcdmod: Copyright (c) 2008-2009 Hendrik Baecker ([email protected]) - http://www.pnp4nagios.org
    [1510494715] npcdmod: /omd/sites/monitoring/etc/pnp4nagios/npcd.cfg initialized
    [1510494715] npcdmod: spool_dir = '/omd/sites/monitoring/var/pnp4nagios/spool/'.
    [1510494715] npcdmod: perfdata file '/omd/sites/monitoring/var/pnp4nagios/perfdata.dump'.
    [1510494715] npcdmod: Ready to run to have some fun!
    [1510494715] Event broker module '/omd/sites/monitoring/lib/npcdmod.o' initialized successfully.
    [1510494715] livestatus: setting number of client threads to 20
    [1510494715] livestatus: Check_MK Inventory directory '/omd/sites/monitoring/var/check_mk/inventory/' not existing!
    [1510494715] livestatus: fl_socket_path=[/omd/sites/monitoring/tmp/run/live], fl_mkeventd_socket_path=[/omd/sites/monitoring/tmp/run/mkeventd/status]
    [1510494715] livestatus: Livestatus 1.4.0p16 by Mathias Kettner. Socket: '/omd/sites/monitoring/tmp/run/live'
    [1510494715] livestatus: Please visit us at http://mathias-kettner.de/
    [1510494715] livestatus: running on OMD site monitoring, cool.
    [1510494715] livestatus: opened UNIX socket at /omd/sites/monitoring/tmp/run/live
    [1510494715] livestatus: your event_broker_options are sufficient for livestatus..
    [1510494715] livestatus: finished initialization, further log messages go to /omd/sites/monitoring/var/nagios/livestatus.log
    [1510494715] Event broker module '/omd/sites/monitoring/lib/mk-livestatus/livestatus.o' initialized successfully.
    [1510494715] Finished daemonizing... (New PID=12063)
    [1510494715] livestatus: TIMEPERIOD TRANSITION: 24X7;-1;1
    [1510494715] livestatus: logging initial states
    [1510494715] INITIAL HOST STATE: Client1;UP;HARD;1;OK - 10.10.10.14: rta 0.391ms, lost 0%
    [1510494715] INITIAL SERVICE STATE: Client1;CPU load;OK;HARD;1;OK - 15 min load 0.05
    [1510494715] INITIAL SERVICE STATE: Client1;CPU utilization;OK;HARD;1;OK - user: 0.2%, system: 0.2%, wait: 0.0%, steal: 0.0%, guest: 0.0%, total: 0.3%
    [1510494715] INITIAL SERVICE STATE: Client1;Check_MK;OK;HARD;1;OK - Agent version 1.4.0p16, execution time 0.1 sec
    [1510494715] INITIAL SERVICE STATE: Client1;Check_MK Discovery;OK;HARD;1;OK - no unmonitored services found, no vanished services found
    [1510494715] INITIAL SERVICE STATE: Client1;Disk IO SUMMARY;OK;HARD;1;OK - Utilization: 0.0%, Read: 0.00 B/s, Write: 0.00 B/s, Average Wait: 0.00 ms, Average Read Wait: 0.00 ms, Average Write Wait: 0.00 ms, Latency: 0.00 ms, Average Queue Length: 0.00
    [1510494715] INITIAL SERVICE STATE: Client1;Filesystem /;OK;HARD;1;OK - 5.8% used (1011.25 MB of 16.99 GB), trend: -305.83 kB / 24 hours
    [1510494715] INITIAL SERVICE STATE: Client1;Filesystem /boot;OK;HARD;1;OK - 13.6% used (138.35 of 1014.00 MB), trend: 0.00 B / 24 hours
    [1510494715] INITIAL SERVICE STATE: Client1;Interface 2;OK;HARD;1;OK - [ens33] (up) MAC: 00:0C:29:A9:98:21, 1 Gbit/s, in: 0.00 B/s(0.0%), out: 0.00 B/s(0.0%)
    [1510494715] INITIAL SERVICE STATE: Client1;Interface 3;OK;HARD;1;OK - [ens37] (up) MAC: 00:0C:29:A9:98:2B, 1 Gbit/s, in: 77.36 B/s(0.0%), out: 435.25 B/s(0.0%)
    [1510494715] INITIAL SERVICE STATE: Client1;Kernel Context Switches;OK;HARD;1;OK - 18/s
    [1510494715] INITIAL SERVICE STATE: Client1;Kernel Major Page Faults;OK;HARD;1;OK - 0/s
    [1510494715] INITIAL SERVICE STATE: Client1;Kernel Process Creations;OK;HARD;1;OK - 1/s
    [1510494715] INITIAL SERVICE STATE: Client1;Memory;OK;HARD;1;OK - RAM used: 166.63 MB of 976.50 MB, Swap used: 0.00 B of 2.00 GB, Total virtual memory used: 166.63 MB of 2.95 GB (5.5%),
  • Kiểm tra thông tin dữ liệu được đẩy ra Bảng :

    echo 'select * from nagios.nagios_logentries;' | mysql -u monitoring -p'mypass'

============================================== ==================user root================== OS: centos7 ----------install check_mk------------- yum -y update yum install -y epel-release wget wget https://mathias-kettner.de/support/1.4.0p17/check-mk-raw-1.4.0p17-el7-64.x86_64.rpm yum install -y check-mk-raw-1.4.0p17-el7-64.x86_64.rpm vi /etc/sysconfig/selinux SELINUX=enforcing thành SELINUX=disabled firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload omd create hanoi 6pg37Nl3 omd start hanoi ----------install mariadb-------------- yum install -y mariadb mariadb-server mariadb-devel yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip httpd php php-fpm curl vim -y yum install net-tools -y systemctl start mariadb.service systemctl enable mariadb.service /usr/bin/mysqladmin -u root password 'tan124' vim ~/.my.cnf ==> [client] user = root password = tan124 mysql CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; CREATE USER 'monitoring'@'localhost' IDENTIFIED BY 'tan124'; grant all privileges on nagios.* to 'monitoring'@localhost identified by "tan124" with grant option; flush privileges; quit -------------install ndo2db------------------ cd /tmp wget http://downloads.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gz tar xvf ndoutils-1.5.2.tar.gz cd ndoutils-1.5.2 ./configure --prefix=/omd/sites/hanoi/usr/local/nagios/ --enable-mysql --disable-pgsql --with-ndo2db-user=hanoi -with-ndo2db-group=hanoi --with-mysql-lib=/usr/lib/mysql make make all make install-config cd /tmp/ndoutils-1.5.2/db ./installdb -u monitoring -p tan124 -h localhost -d nagios chown -R hanoi. /omd/sites/hanoi/usr/local/ chmod 766 /tmp/ndoutils-1.5.2/config/ndo2db.cfg-sample chmod 766 /tmp/ndoutils-1.5.2/config/ndomod.cfg-sample chmod 766 /tmp/ndoutils-1.5.2/daemon-init ==========user hanoi============== su hanoi mkdir -p ~/usr/local/nagios/bin mkdir -p ~/usr/local/nagios/etc mkdir -p ~/usr/local/nagios/var cp /tmp/ndoutils-1.5.2/src/ndomod-3x.o ~/usr/local/nagios/bin/ndomod.o cp /tmp/ndoutils-1.5.2/src/ndo2db-3x ~/usr/local/nagios/bin/ndo2db chmod 0744 ~/usr/local/nagios/bin/ndo* cp /tmp/ndoutils-1.5.2/config/ndo2db.cfg-sample ~/usr/local/nagios/etc/ndo2db.cfg cp /tmp/ndoutils-1.5.2/config/ndomod.cfg-sample ~/usr/local/nagios/etc/ndomod.cfg cp /tmp/ndoutils-1.5.2/daemon-init ~/etc/init.d/ndo2db chmod +x ~/etc/init.d/ndo2db vim /omd/sites/hanoi/usr/local/nagios/etc/ndo2db.cfg ==> db_user=monitoring db_pass=tan124 mkdir -p ~/var/lock/subsys vim ~/etc/init.d/ndo2db ==> Ndo2dbLockDir=var/lock/subsys Ndo2dbUser=hanoi Ndo2dbGroup=hanoi trong function start ndo2db cua file ~/etc/init.d/ndo2db ta them dong remove socket "usr/local/nagios/var/ndo.sock" nhu sau: start) status_ndo2db if [ $? -eq 0 ]; then echo "$servicename already started..." exit 1 fi echo -n "Starting $servicename:" rm -rf usr/local/nagios/var/ndo.sock touch $Ndo2dbRunFile chown $Ndo2dbUser:$Ndo2dbGroup $Ndo2dbRunFile $Ndo2dbBin -c $Ndo2dbCfgFile if [ -d $Ndo2dbLockDir ]; then touch $Ndo2dbLockDir/$Ndo2dbLockFile; fi echo " done." exit 0 ;; printf "\n\n# NDOUtils Broker Module\n" >> /omd/sites/hanoi/etc/nagios/nagios.cfg printf "broker_module=/omd/sites/hanoi/usr/local/nagios/bin/ndomod.o\n" >> /omd/sites/hanoi/etc/nagios/nagios.cfg printf "config_file=/omd/sites/hanoi/usr/local/nagios/etc/ndomod.cfg\n" >> /omd/sites/hanoi/etc/nagios/nagios.cfg cd /omd/sites/hanoi/etc/rc.d ln -s ../init.d/ndo2db 81-ndo2db =============root=========== omd restart hanoi tail -f /omd/sites/hanoi/var/log/nagios.log ==> if OK [1510629049] ndomod: Successfully reconnected to data sink! 0 items lost, 124 queued items to flush. [1510629049] ndomod: Successfully flushed 124 queued items to data sink. ==> if not OK [1510569392] ndomod: Still unable to connect to data sink. 0 items lost, 278 queued items to flush. [1510569408] ndomod: Still unable to connect to data sink. 0 items lost, 392 queued items to flush. ===========tham khao=================== https://monitoring-portal.org/index.php?thread/29283-omd-ndo2db/ https://github.com/datkk06/meditech-ghichep-omd/blob/master/prepare/5.%20pull-data-to-mysql.md