Centreon Nagios实战第四篇——监控端安装NDOUtils
首先我们需要安装MySql和Git,这可以通过yum来实现
代码语言:javascript复制yum -y install mysql mysql-server mysql-devel git
接下来启动MySql,对MySql进行配置 service mysqld start
检查MySql是处于运行中
代码语言:javascript复制ps x | grep mysql | grep -v grep
这条指令正常情况应该输出以下信息: 9584 pts/0 S 0:00 /bin/sh /usr/bin/mysqld_safe –datadir=/var/lib/mysql –socket=/var/lib/mysql/mysql.sock –pid-file=/var/run/mysqld/mysqld.pid –basedir=/usr –user=mysql
给Root用户添加一个密码,这里我就给root用户添加密码为’mypassword’
代码语言:javascript复制/usr/bin/mysqladmin -u root password 'mypassword'
将MySql启动添加到boot上
代码语言:javascript复制chkconfig --add mysqld
chkconfig mysqld on
接下来更新一些linux内核设置,让消息队列功能运作更加高效
代码语言:javascript复制echo "kernel.msgmnb = 131072000" >> /etc/sysctl.conf
echo "kernel.msgmax = 131072000" >> /etc/sysctl.conf
echo "kernel.shmmax = 4294967295" >> /etc/sysctl.conf
echo "kernel.shmall = 268435456" >> /etc/sysctl.conf
sysctl -e -p /etc/sysctl.conf
执行完最后一条指令时会输出下面的信息: net.ipv4.ip_forward = 0 net.ipv4.conf.default.rp_filter = 1 net.ipv4.conf.default.accept_source_route = 0 kernel.sysrq = 0 kernel.core_uses_pid = 1 net.ipv4.tcp_syncookies = 1 kernel.msgmnb = 65536 kernel.msgmax = 65536 kernel.shmmax = 68719476736 kernel.shmall = 4294967296 kernel.msgmnb = 131072000 kernel.msgmax = 131072000 kernel.shmmax = 4294967295 kernel.shmall = 268435456
接下来我们创建数据库和数据库用户,在这整篇文档中,我会使用ndoutils作为用户名,ndoutils_password作为密码,数据库名为nagios
代码语言:javascript复制mysql -u root -p'mypassword'
CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password';
GRANT USAGE ON *.* TO 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ;
q
运行下面这条指令来确认你的数据库是否被正确设置了
代码语言:javascript复制echo 'show databases;' | mysql -u ndoutils -p'ndoutils_password' -h localhost
上面这条指令正常情况下会输出下面的结果 Database information_schema nagios test
前面是一些预先步骤,接下来开始正式安装NDOUtils 首先下载安装包并解压
代码语言:javascript复制cd /tmp
wget https://sourceforge.net/projects/nagios/files/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz
tar zxf ndoutils-2.0.0.tar.gz
安装
代码语言:javascript复制cd /tmp/ndoutils-2.0.0
./configure
make
make install
make install-init
初始化数据库
代码语言:javascript复制cd /tmp/ndoutils-2.0.0/db
./installdb -u 'ndoutils' -p 'ndoutils_password' -h 'localhost' -d nagios
创建配置文件
代码语言:javascript复制cp /tmp/ndoutils-2.0.0/config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
sed -i 's/^db_user=.*/db_user=ndoutils/g' /usr/local/nagios/etc/ndo2db.cfg
sed -i 's/^db_pass=.*/db_pass=ndoutils_password/g' /usr/local/nagios/etc/ndo2db.cfg
chmod 664 /usr/local/nagios/etc/ndo2db.cfg
cp /tmp/ndoutils-2.0.0/config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chmod 664 /usr/local/nagios/etc/ndomod.cfg
配置ndo2db服务然后启动服务
代码语言:javascript复制chkconfig --add ndo2db
chkconfig ndo2db on
service ndo2db start
更新nagios,配置nagios.cfg文件指明nagios使用的是NDOUtils模块
代码语言:javascript复制echo '' >> /usr/local/nagios/etc/nagios.cfg
echo ' #NDOUtils Broker Module' >> /usr/local/nagios/etc/nagios.cfg
echo 'broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg' >> /usr/local/nagios/etc/nagios.cfg
重启Nagios
代码语言:javascript复制service nagios restart
service nagios status
最后一条指令应该显示Nagios处于运行状态,输出消息如下: nagios (pid 13169) is running… 下面这条指令显示Nagios成功的加载了NDO模块
代码语言:javascript复制grep ndo /usr/local/nagios/var/nagios.log
执行之后应该显示以下信息
下面这条指令会向您展示数据库的一些信息
代码语言:javascript复制echo 'select * from nagios.nagios_logentries;' | mysql -u ndoutils -p'ndoutils_password'
展示的信息如下
展示的信息如下
执行完以上操作后您就完成了NDOUtilts的安装,并且配置好了Nagios使用NDO broker模块