暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

pgwatch2(pg)部署文档

IT那活儿 2022-04-01
1046

点击上方“IT那活儿”,关注后了解更多内容,不管IT什么活儿,干就完了!!!

1

使用postgresql11.9版本操作

1.1 下载rpm安装包并安装
wget https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
rpm -ivh pgdg-redhat-repo-latest.noarch.rpm
复制
1.2 使用yum 安装相关安装包
yum install –y postgresql11.x86_64 postgresql11-contrib.x86_64 postgresql11-plpython.x86_64  postgresql11-plpython3.x86_64 postgresql11-server.x86_64
复制
1.3 使用postgres用户初始化数据库
su - postgres/usr/pgsql-11/bin/initdb -D /var/lib/pgsql/11/data/
复制
1.4 初始化完成,启动数据库
/usr/pgsql-11/bin/pg_ctl -D /var/lib/pgsql/11/data/ -l logfile start
复制
1.5 下载github上面的pgwatch2源码包
wget https://github.com/cybertec-postgresql/pgwatch2/releases/download/v1.8.0/pgwatch2_v1.8.0-SNAPSHOT-064fdaf_linux_64-bit.tar.gz
复制
1.6 创建数据库和用户并执行sql文件
vi create.shpsql -c "create user pgwatch2_grafana password 'jkl'";psql -c "create database pgwatch2_grafana owner pgwatch2_grafana";psql -c "create user pgwatch2 password 'jkl'";psql -c "create database pgwatch2 owner pgwatch2";psql -f /var/lib/pgsql/pgwatch2/pgwatch2/sql/config_store/config_store.sql pgwatch2psql -f /var/lib/pgsql/pgwatch2/pgwatch2/sql/config_store/metric_definitions.sql pgwatch2
复制
1.7 修改postgresql.conf和pg_hba.conf验证登录
vi /var/lib/pgsql/11/data/postgresql.confshared_preload_libraries = 'pg_stat_statements'track_io_timing = onvi /var/lib/pgsql/11/data/pg_hba.conf
复制
1.8 安装extension

2

安装influxdb

2.1 获取rpm安装包
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.2.x86_64.rpm
2.2 使用yum安装
yum localinstall influxdb-1.8.2.x86_64.rpm
复制
2.3 配置参数文件
vi /etc/influxdb/influxdb.conf[http]enabled = truebind-address = "127.0.0.1:8086"
复制
2.4 创建influxdb目录并赋权
mkdir -p /var/lib/influxdb/datamkdir -p /var/lib/influxdb/metamkdir -p /var/lib/influxdb/walchown -R influxdb:influxdb /var/lib/influxdb
复制
2.5 添创建pgwatch2用户以及同名的数据库,并且授权。
influxCREATE USER pgwatch2 WITH PASSWORD 'jkl'CREATE DATABASE pgwatch2use pgwatch2GRANT ALL ON pgwatch2 to "pgwatch2"show users;show databases
复制
2.6 查看运行状态
systemctl status influxdb

3

安装grafana

3.1 获取rpm安装包
wget https://dl.grafana.com/oss/release/grafana-6.3.7-1.x86_64.rpm
3.2 使用yum 安装
yum localinstall grafana-6.3.7-1.x86_64.rpm
复制
3.3 配置参数文件
vi /etc/grafana/grafana.initype = postgreshost = 127.0.0.1:5432name = pgwatch2_grafanauser = pgwatch2_grafanapassword = jkl
复制
3.4 启动并查看grafana状态
systemctl start grafana-server.servicesystemctl status grafana-server.service
复制
3.5 登录web页面添加数据源http://xxx.xxx.xxx.xxx:3000用户名admin密码admin
3.6 添加influx数据源
3.7 导入仪表盘

4

安装Python

4.1 使用yum安装Python3
yum install -y python3.x86_64yum install -y python3-devel.x86_64
复制
4.2 执行pgwatch2源码包下面的检查文件验证python完整性
pip3 install -U -r webpy/requirements.txt
复制
4.3 执行python程序
python3 web.py
复制
4.4 访问python程序web页面添加监控数据库源
4.5 添加需要监控的数据库参数
4.6 执行pgwatch2中的监控指标
psql -f pgwatch2/metrics/00_helpers/get_psutil_disk/9.1/metric.sql pgwatch2psql -f pgwatch2/metrics/00_helpers/get_psutil_disk/9.1/metric.sql pgwatch2psql -f pgwatch2/metrics/00_helpers/get_psutil_cpu/9.1/metric.sql pgwatch2psql -f pgwatch2/metrics/00_helpers/get_psutil_mem/9.1/metric.sql pgwatch2psql -f pgwatch2/metrics/00_helpers/get_stat_activity/9.2/metric.sql pgwatch2psql -f pgwatch2/metrics/00_helpers/get_stat_statements/9.4/metric.sql pgwatch2psql -f pgwatch2/metrics/00_helpers/get_wal_size/10/metric.sql pgwatch2
复制

5

安装go

5.1 安装go语言
yum install -y go
复制
5.2 到pgwatch2 目录下执行build_gatherer.sh
5.3 执行pgwatch2程序,查看grafana

本文作者:陈辉耀

本文来源:IT那活儿(上海新炬王翦团队)

文章转载自IT那活儿,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论