PostgreSQL monitor - nagios server installation

1 minute read

背景

本文要介绍的是PostgreSQL数据库监控, 监控平台可以选择nagios, 实现即时的数据库监控.

如果需要图形化的监控, 例如表空间的增长趋势, 数据库的tps, 提交量, 回滚量的分时趋势图等, 则使用cacti监控平台更加方便.

本文介绍的是nagios, 首先要安装监控平台 - nagios.

环境 :

CentOS 5.x x84_64  

1. 安装nagios依赖包

[root@db-172-16-3-33 soft_bak]# yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp  

2. 下载nagios core 以及 plugins 源码包

http://www.nagios.org/download

下载最新的稳定开源版本.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.5.0.tar.gz  
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.16.tar.gz  

3. 解压

[root@db-172-16-3-33 soft_bak]# tar -zxvf nagios-3.5.0.tar.gz  
[root@db-172-16-3-33 soft_bak]# tar -zxvf nagios-plugins-1.4.16.tar.gz  

4. 新建运行nagios的操作系统用户

useradd nagios  
groupadd nagcmd  
usermod -a -G nagcmd nagios  
[root@db-172-16-3-33 soft_bak]# id nagios  
uid=513(nagios) gid=513(nagios) groups=513(nagios),514(nagcmd)  

5. 安装nagios

[root@db-172-16-3-33 soft_bak]# cd nagios  
[root@db-172-16-3-33 nagios]# ./configure --prefix=/opt/nagios-3.5.0 --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagcmd  
[root@db-172-16-3-33 nagios]# make all  
[root@db-172-16-3-33 nagios]# make install  
[root@db-172-16-3-33 nagios]# make install-init  
[root@db-172-16-3-33 nagios]# make install-config  
[root@db-172-16-3-33 nagios]# make install-commandmode  
[root@db-172-16-3-33 nagios]# make install-webconf  

解释 :

  make install-init  
     - This installs the init script in /etc/rc.d/init.d  
  make install-commandmode  
     - This installs and configures permissions on the  
       directory for holding the external command file  
  make install-config  
     - This installs sample config files in /opt/nagios-3.5.0/etc  

6. 拷贝用于被动监控的时间处理程序到程序目录 :

[root@db-172-16-3-33 nagios]# cp -R contrib/eventhandlers/ /opt/nagios-3.5.0/libexec/  
[root@db-172-16-3-33 nagios]# chown -R nagios:nagios /opt/nagios-3.5.0/libexec/eventhandlers  

检查nagios配置文件是否正确 :

[root@db-172-16-3-33 nagios]# /opt/nagios-3.5.0/bin/nagios -v /opt/nagios-3.5.0/etc/nagios.cfg  

启动nagios

[root@db-172-16-3-33 nagios]# /etc/init.d/nagios start  
Starting nagios: done.  

启动httpd服务

[root@db-172-16-3-33 nagios]# /etc/init.d/httpd start  
Starting httpd: [  OK  ]  

创建WEB接口访问用户 :

[root@db-172-16-3-33 nagios]# htpasswd -c /opt/nagios-3.5.0/etc/htpasswd.users nagiosadmin  
New password:   
Re-type new password:   
Adding password for user nagiosadmin  

7. 安装nagios plugins.

[root@db-172-16-3-33 nagios]# cd ../nagios-plugins-1.4.16  
[root@db-172-16-3-33 nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/opt/nagios-3.5.0 --with-pgsql=/opt/pgsql9.2.4  
[root@db-172-16-3-33 nagios-plugins-1.4.16]# make  
[root@db-172-16-3-33 nagios-plugins-1.4.16]# make install  

8. 将apache用户添加到nagcmd组.

[root@db-172-16-3-33 rw]# id apache  
uid=48(apache) gid=48(apache) groups=48(apache)  
[root@db-172-16-3-33 rw]# usermod -a -G nagcmd apache  
[root@db-172-16-3-33 rw]# id apache  
uid=48(apache) gid=48(apache) groups=48(apache),514(nagcmd)  
[root@db-172-16-3-33 rw]# service httpd restart  
Stopping httpd: [  OK  ]  
Starting httpd: [  OK  ]  

因为在web页面需要调用nagios cmd时, 需要对一下文件有写的权限.

[root@db-172-16-3-33 rw]# pwd  
/opt/nagios-3.5.0/var/rw  
[root@db-172-16-3-33 rw]# ll  
total 0  
prw-rw---- 1 nagios nagcmd 0 Jun  3 14:18 nagios.cmd  

9. 将nagios和httpd加入自启动

[root@db-172-16-3-33 rw]# chkconfig --add nagios  
[root@db-172-16-3-33 rw]# chkconfig --level 35 nagios on  
[root@db-172-16-3-33 rw]# chkconfig --add httpd  
[root@db-172-16-3-33 rw]# chkconfig --level 35 httpd on  

10. 连接WEB
验证时使用第5步创建的, nagiosadmin用户密码.

其他

其他重要的nagios组件 :

General Addons:  
Nagios BPI  
Exfoliation  
nagiosgraph  
Nagios V-Shell  
NRDP  
NRPE  
NSClient++  
Nageventlog  

参考

1. http://www.nagios.org/download

2. http://assets.nagios.com/downloads/nagioscore/docs/Installing_Nagios_Core_From_Source.pdf

3. http://exchange.nagios.org/

Flag Counter

digoal’s 大量PostgreSQL文章入口