通过zabbix-agent2来监控PostgreSQL-15
操作系统环境:
[root@zabbix ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@zabbix ~]# uname -a
Linux zabbix 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Zabbix_Server:
[root@zabbix ~]# zabbix_server --version
zabbix_server (Zabbix) 5.0.1
Zabbix_agent2:
[root@postgresql15 ~]# zabbix_agent2 --version
zabbix_agent2 (Zabbix) 5.0.39
Zabbix服务端安装配置(略)
先在pg15服务器上安装Zabbix_agent2:
在postgresql主机上
zabbix客户端安装:
CentOS7.X
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
yum clean all
yum install zabbix-agent2
开机启动 zabbix-agent2
systemctl enable --now zabbix-agent2
yum -y install net-tools
查看端口
netstat -tnlp|grep zabbix
查看验证zabbix-agent2.service文件
ls /lib/systemd/system/zabbix-agent2.service
需要详细也可以cat查看
配置并修改文件
查看一下修改了那些:
[root@postgresql15 zabbix]# grep -Ev '^#|^$' /etc/zabbix/zabbix_agent2.conf
PidFile=/var/run/zabbix/zabbix_agent2.pid
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=0
Server=172.16.1.136
Hostname=node15
Include=/etc/zabbix/zabbix_agent2.d/*.conf
ControlSocket=/tmp/agent.sock
改完一定都要~重启zabbix_agent2
systemctl restart zabbix-agent2
#回到配置主机,并配置模板和宏
zabbix-server配置:
添加主机:
添加模版:
配置宏变量:
{$PG.CONFLICTS.MAX.WARN} 0
{$PG.CONN_TOTAL_PCT.MAX.WARN} 90
{$PG.DATABASE} postgres
{$PG.DEADLOCKS.MAX.WARN} 0
{$PG.LLD.FILTER.APPLICATION} (.+)
{$PG.LLD.FILTER.DBNAME} (.+)
{$PG.PASSWORD} 123456
{$PG.URI} tcp://172.16.1.15:5432
{$PG.USER} postgres
{$PG.HOST} 172.16.1.15
{$PG.PORT} 172.16.1.15
注意:这个只能修改模版的变量值,修改主机默认的变量没有用:
最后,修改pg主机的pg_hbs.conf配置:
修改pg_hba.conf配置:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host all all 172.16.1.0/24 trust
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
重新zabbix-server zabbix-agent2
在zabbix服务端:
systemctl restart zabbix-server
在pg服务器端:
systemctl restart zabbix-agent2
在zabbix服务端页面查看收集的信息: