zabbix使用pg_monz模板日常监控postgresql

使用pg_monz模板
下载pg_monz2.1
https://github.com/pg-monz/pg_monz/archive/2.1.tar.gz
[root@localhost ~]# tar -zxvf 2.1.tar.gz
cp usr-local-etc/* /usr/local/etc
cp usr-local-bin/* /usr/local/bin

参考以下pg_monz的quick-install.txt按照说明就可以监控postgresql
* How to install pg_monz v2

  1. requirements

    • Zabbix server version 2.0+
    • monitored PostgreSQL 9.2+
    • monitored pgpool-II 3.4.0
    • installing zabbix_agentd to PostgreSQL and pgpool-II host.
    • installing zabbix_sender to PostgreSQL and pgpool-II host.
    • ServerActive setting in zabbix_agentd.conf (zabbix_sender read this file)
    • psql command(and serch path setting) on each PostgreSQL/pgpool server
  2. Uploading Zabbix template using Zabbix frontend.

    Template_App_PostgreSQL.xml
    Template_App_PostgreSQL_SR.xml
    Template_App_PostgreSQL_SR_Cluster.xml
    Template_App_pgpool-II.xml
    Template_App_pgpool-II-36.xml
    Template_App_pgpool-II_watchdog.xml

  3. Copy usr-local-etc files (pgsql_funcs.conf and pgpool_funcs.conf) to “/usr/local/etc”

    cp usr-local-etc/* /usr/local/etc

    default variables for pgsql_funcs.conf


    PGHOST=127.0.0.1
    PGPORT=5432
    PGROLE=postgres
    PGDATABASE=postgres


    default variables for pgpool_funcs.conf


    PGPOOLHOST=127.0.0.1
    PGPOOLPORT=9999
    PGPOOLROLE=postgres
    PGPOOLDATABASE=postgres
    PGPOOLCONF=/usr/local/etc/pgpool.conf


    (*) the definition of configuration directory is in the tempalte macro.
    {PGSCRIPT_CONFDIR}  
       {
    PGSCRIPT_CONFDIR}     {
    PGPOOLSCRIPTS_CONFDIR}

  4. Copy usr-local-bin files (*.sh) to “/usr/local/bin”

    cp usr-local-bin/* /usr/local/bin

    (*) the definition of scripts directory is in the template macro.
    {PGSCRIPTDIR}  
       {
    PGSCRIPTDIR}     {
    PGPOOLSCRIPTDIR}

  5. Define groups using Zabbix frontend.

    Create “PostgreSQL” group and add PostgreSQL host to “PostgreSQL” group.
    Create “pgpool” group and add pgpool-II host to “pgpool” group.

    Each groups are referenced by Template_App_PostgreSQL_SR_Cluster.xml
    and Template_App_pgpool-II_watchdog.xml using {$HOST_GROUP} template macro.

  6. Check the filepath of zabbix_agentd.conf.

    if your installation of zabbix_agentd.conf is not /etc/zabbix/zabbix_agentd.conf,
    add {$ZABBIX_AGENTD_CONF} macro to HOST’S MACRO.

    the definition of zabbix_agentd.conf path is in the template macro.

    {$ZABBIX_AGENTD_CONF} => /etc/zabbix/zabbix_agentd.conf

  7. Link template to host.

    Link “Template App PostgreSQL SR” to PostgreSQL host.
    Link “Template App pgpool-II” to pgpool-II host.

    “Template App PostgreSQL SR Cluster”/ “Template App pgpool-II-watchdog”
    are simply counting
    -the number of running service (sr/pgpool-II),
    -the number of primary server (sr),
    -the number of standby server (sr),
    -the number of delegate_ip (pgpool-II),
    in same {$HOST_GROUP} using zabbix aggregate key.
    you want to monitor the split-brain or the number of primary server,
    Link the above templates to arbitrary host.
    ex) “PostgreSQL Cluster” as a virtual host

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
修改 pg_hba.conf 和 postgresql.conf 配置文件来连接 PostgreSQL 数据库客户端和保证生产环境的安全性,需要进行以下步骤: 1. 修改 pg_hba.conf 配置文件 在生产环境中,建议采取以下措施: - 限制客户端访问:在 pg_hba.conf 文件中,只允许特定的 IP 地址或主机名连接到 PostgreSQL 数据库。例如,可以添加以下内容: ``` # TYPE DATABASE USER ADDRESS METHOD host all all 192.168.1.0/24 md5 ``` 这样只允许在 192.168.1.0/24 网段的客户端使用密码方式(md5)连接到 PostgreSQL 数据库。 - 启用 SSL/TLS 加密:在 postgresql.conf 文件中,可以配置 SSL/TLS 参数,例如: ``` ssl = on ssl_cert_file = '/path/to/server.crt' ssl_key_file = '/path/to/server.key' ssl_ca_file = '/path/to/ca.crt' ``` 然后在 pg_hba.conf 文件中为客户端连接添加 SSL/TLS 认证方式: ``` # TYPE DATABASE USER ADDRESS METHOD hostssl all all 192.168.1.0/24 md5 ``` 这样就只允许在 192.168.1.0/24 网段的客户端使用 SSL/TLS 加密方式连接到 PostgreSQL 数据库。 2. 修改 postgresql.conf 配置文件 在生产环境中,建议采取以下措施: - 配置连接池:在 postgresql.conf 文件中,可以调整以下参数来配置连接池: ``` max_connections = 1000 shared_buffers = 8GB work_mem = 32MB ``` 这样可以提高数据库的性能和可靠性。你也可以使用连接池如 PgBouncer 和 Pgpool-II 等。 - 监控数据库性能:在 postgresql.conf 文件中,可以配置以下参数来监控数据库性能: ``` log_statement = 'all' log_min_duration_statement = 1000 ``` 这样可以记录所有 SQL 语句的执行时间和执行计划,以及超过 1000 毫秒的 SQL 语句。你也可以使用监控工具如 Zabbix、Nagios 等,或使用 PostgreSQL 内置的性能监控工具如 pg_stat_statements、pg_stat_activity 等。 3. 重启 PostgreSQL 服务 修改完以上配置后,需要重启 PostgreSQL 服务才能生效。你可以使用以下命令重启 PostgreSQL 服务: ``` sudo systemctl restart postgresql ``` 通过以上步骤,你就可以修改 pg_hba.conf 和 postgresql.conf 配置文件来连接 PostgreSQL 数据库客户端和保证生产环境的安全性。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值