ubuntu 16.04 + zabbix 3.4 + postgresql libzbxpgsql

os: ubuntu 16.04
zabbix: 3.4

ip 规划
192.168.56.101 node1 pgsql 9.6 master
192.168.56.102 node2 pgsql 9.6 slave
192.168.56.103 node3 zabbix proxy
192.168.56.104 node4 zabbix server

本篇blog介绍在 node1、node2 节点上安装 libzbxpgsql 的具体过程。
在安装 libzbxpgsql 之前,请确保已经安装了 zabbix agent。

安装 libzbxpgsql

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:    16.04
Codename:   xenial

# cd /tmp
# wget http://cdn.cavaliercoder.com/libzbxpgsql/apt/zabbix32/ubuntu/trusty/amd64/libzbxpgsql_1.1.0-1%2Btrusty_amd64.deb

# apt-get install libc6 libconfig9
# dpkg -i libzbxpgsql_1.1.0-1+trusty_amd64.deb
# dpkg -l libzbxpgsql
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                   Version          Architecture     Description
+++-======================-================-================-==================================================
ii  libzbxpgsql            1.1.0-1          amd64            PostgreSQL monitoring module for Zabbix

# apt-cache show libzbxpgsql
Package: libzbxpgsql
Status: install ok installed
Priority: optional
Section: misc
Installed-Size: 110
Maintainer: Ryan Armstrong <ryan@cavaliercoder.com>
Architecture: amd64
Version: 1.1.0-1
Depends: libc6 (>= 2.4), libconfig9, libpq5, zabbix-agent (>= 3.0.0)
Conffiles:
 /etc/zabbix/libzbxpgsql.conf d48c8fa8793959c126188077ba0a67ce
 /etc/zabbix/zabbix_agentd.d/libzbxpgsql.conf 2c585e4bbad405769345396b93016ce8
Description: PostgreSQL monitoring module for Zabbix
 This package provides comprehensive monitoring of PostgreSQL servers using a
 natively compiled Zabbix agent module, written in C, with highly configurable
 item keys and a complimentary Template.
Description-md5: 06b8597209d0b98bbf13239d763debc7

# find / -name libzbxpgsql.so
/usr/lib/zabbix/modules/libzbxpgsql.so

配置 zabbix_agentd.conf

# vi /etc/zabbix/zabbix_agentd.conf

LoadModulePath=/usr/lib/zabbix/modules
LoadModule=libzbxpgsql.so

# zabbix_agentd -t pg.modver
zabbix_agentd [25945]: starting agent module libzbxpgsql 1.1.0
zabbix_agentd [25945]: using module configuration file: /etc/zabbix/libzbxpgsql.conf
pg.modver                                     [s|libzbxpgsql 1.1.0, compiled for Zabbix 3.2.3]

# service zabbix-agent restart

postgresql 创建 zabbix 监控用户

# vi /etc/postgresql/9.6/main/postgresql.conf
listen_addresses = '0.0.0.0'
# /etc/init.d/postgresql restart
# su - postgres
postgres@node1:~$ psql
psql (9.6.10)
Type "help" for help.

postgres=# create user zabbix with superuser password 'zabbix';
CREATE ROLE

$ vi /etc/postgresql/9.6/main/pg_hba.conf

local   all             zabbix                                  trust

host    all             zabbix          127.0.0.1/32            trust
host    all             zabbix          192.168.56.101/32       trust

host    all             zabbix          ::1/128                 trust
$ psql -c "select pg_reload_conf();"

可以配置下 .gppass 文件。

下载监控模板

# cd /tmp
# git clone https://github.com/cavaliercoder/libzbxpgsql.git

找到里边的 templates/Template_PostgreSQL_Server_3.0.xml

导入监控模版

zabbix web 页面操作

Configuration -> Templates -> Import

可以看到模版 Template App PostgreSQL 手动归属到 Templates/Databases 下

主机配置postgresql libzbxpgsql 模板

zabbix web 页面操作

Configuration -> Hosts

点击某台机器,进去选择 Templates,
点击Select,选中Template App PostgreSQL libzbxpgsql,点击页下面的 Select
点击 Add
点击 Update

配置 postgresql 宏
点击某台机器,进去选择 Macros
点击 Inherited and host macros
设置 {$PG_CONN} 的值为 host=127.0.0.1 port=5432 user=zabbix connect_timeout=10
点击 Update

稍等一会,就能看到采集到postgresql的数据了。

参考:
http://cavaliercoder.com/libzbxpgsql/
http://cavaliercoder.com/libzbxpgsql/download/
http://cavaliercoder.com/libzbxpgsql/documentation/

https://github.com/cavaliercoder/libzbxpgsql

https://www.zabbix.com/documentation/3.4/manual/config/items/loadablemodules

posted @ 2018-09-05 11:36  peiybpeiyb  阅读(679)  评论(0编辑  收藏  举报