1. 本际云推荐 - 专业推荐VPS、服务器,IDC点评首页
  2. 云主机运维
  3. VPS运维

pgwatch2(pg)部署文档

pgwatch2部署文档

欢迎来到IT那活儿,本文由本际云服务器推荐网的小编小本本为您呈现pgwatch2部署文档,以下是具体步骤:

pgwatch2(pg)部署文档

使用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/ -llogfile 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.sh

psql -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 pgwatch2

psql -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.conf

shared_preload_libraries=pg_stat_statements

track_io_timing=on

vi /var/lib/pgsql/11/data/pg_hba.conf

安装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=true

bind-address=”127.0.0.1:8086″

2.4 创建influxdb目录并赋权:

mkdir -p /var/lib/influxdb/data

mkdir -p /var/lib/influxdb/meta

mkdir -p /var/lib/influxdb/wal

chown -R influxdb:influxdb /var/lib/influxdb

2.5 创建pgwatch2用户以及同名的数据库,并且授权

CREATE USER pgwatch2 WITH PASSWORD jkl;

CREATE DATABASE pgwatch2;

use pgwatch2;

GRANT ALL ON pgwatch2 TO “pgwatch2”;

show users;

show databases;

安装grafana

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.ini

type = postgres

host = 127.0.0.1:5432

name = pgwatch2_grafana

user = pgwatch2_grafana

password = jkl

3.4 启动并查看grafana状态:

systemctl start grafana-server.service

systemctl status grafana-server.service

3.5 登录web页面添加数据源:

http://xxx.xxx.xxx.xxx:3000

用户名admin

密码admin

3.6 添加influx数据源

3.7 导入仪表盘

安装Python

4 安装Python:

4.1 使用yum安装Python3:

yum install -y python3.x86_64

yum 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 pgwatch2

psql -f pgwatch2/metrics/00_helpers/get_psutil_cpu/9.1/metric.sql pgwatch2

psql -f pgwatch2/metrics/00_helpers/get_psutil_mem/9.1/metric.sql pgwatch2

psql -f pgwatch2/metrics/00_helpers/get_stat_activity/9.2/metric.sql pgwatch2

psql -f pgwatch2/metrics/00_helpers/get_stat_statements/9.4/metric.sql pgwatch2

psql -f pgwatch2/metrics/00_helpers/get_wal_size/10/metric.sql pgwatch2

安装go

5 安装go语言:

5.1 使用yum安装:

yum install -y go

5.2 到pgwatch2目录下执行build_gatherer.sh

5.3 执行pgwatch2程序,查看grafana

本文作者:陈辉耀

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

原创文章,作者:小编小本本,如若转载,请注明出处:https://www.benjiyun.com/yunzhujiyunwei/vps-yunwei/6267.html