將Nagios監控資訊存入MySQL

luashin發表於2016-04-11
一、NDOUtils安裝需求:
Nagios:安裝方法:
MySQL:原始碼安裝方法:

DBI和DBD-mysql安裝方法如下:
shell> perl -MCPAN -e shell 
cpan> install DBI 
cpan> install DBD::mysql

二、關聯mysql標頭檔案和庫:
不做關聯可能在config或make時出錯
ln -s /app/mysql/include/* /usr/include/
ln -s /app/mysql/lib/* /usr/lib/
echo '/usr/lib' >> /etc/ld.so.conf
ldconfig -v

三、安裝nodutils:
tar zxvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure --prefix=/usr/local/nagios --enable-mysql --disable-pgsql LDFLAGS=-L/app/mysql/lib --with-mysql-inc=/app/mysql/include/mysql --with-mysql-lib=/app/mysql/lib/mysql
make && make install

四、複製檔案:
cp ./src/ndomod-3x.o /usr/local/nagios/bin
cp ./src/ndo2db-3x /usr/local/nagios/bin
cp ./src/log2ndo /usr/local/nagios/bin
cp ./src/file2sock /usr/local/nagios/bin
chown nagios:nagios /usr/local/nagios/bin/*

五、複製配置檔案:
cp ./config/ndo* /usr/local/nagios/etc/
chown nagios:nagios /usr/local/nagios/etc/*

六、建立ndo的mysql資料庫及使用者
CREATE DATABASE `nagios` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT select,insert,update,delete ON nagios.* TO nagios@localhost identified by 'nagios';
FLUSH PRIVILEGES ;

七、匯入資料庫結構
cd ./db/
./installdb -u root -p 123456 -h localhost -d nagios
如果這裡root沒有密碼的話需要進行修改。

八、修改配置檔案
vim /usr/local/nagios/etc/ndo2db.cfg

db_user=nagios
db_pass=nagios
socket_type=tcp

vim /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg

vim /usr/local/nagios/etc/ndomod.cfg
output_type=file
output=/usr/local/nagios/var/ndo.dat
 
九、啟動ndo2db
/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg

十、重啟nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
service nagios restart

十一、檢查安裝是否正確
tail -f /usr/local/nagios/var/nagios.log

涉及的錯誤:
啟動ndo後在日誌中出現:nagios ndo2db-3x: Error: mysql_query() failed for 'INSERT INTO nagios_configfilevariables SET instance_id='1', configfile_id='3', varname='cfg_file', varvalue='/usr/local/nagios//etc/objects/localhost\.cfg 解決辦法是使用:mysql -uroot --password="canada" -h192.168.1.97 -e "alter table nagios.nagios_configfilevariables drop key instance_id;alter table nagios.nagios_configfilevariables add index (instance_id, configfile_id, varname); 需要修改表結構。 alter table nagios.nagios_configfilevariables drop key instance_id; alter table nagios.nagios_configfilevariables add index (instance_id, configfile_id, varname);

tcp連線Mysql /usr/local/nagios/bin/file2sock -s /usr/local/nagios/var/ndo.dat -d localhost -t tcp -p 5668

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9034054/viewspace-2078985/,如需轉載,請註明出處,否則將追究法律責任。

相關文章