命令记不住

登陆

prometheus 更换 influxdb

prometheus更换influxdb

1.系统环境

使用influxdb 作为prometheus持久化存储和使用mysql 作为grafana 持久化存储的安装方法

influxdb-1.8.1.x86_64.rpm
prometheus-2.34.0
grafana-7.5.7-1.x86_64.rpm

2.安装influxdb

检查并安装influxdb

软件包查看地址:https://portal.influxdata.com/downloads/

rpm -qa | grep influxdb
rpm -e influxdb
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.1.x86_64.rpm

#版本信息可以从这里查看 https://portal.influxdata.com/downloads/,要下载不同的版本只需修改上面的版本信息即可。
yum install -y influxdb-1.8.1.x86_64.rpm

修改influxdb配置文件,默认启动端口8086

vim /etc/influxdb/influxdb.conf

influxdb的 启动、停止、查看状态、设置开机启动

systemctl status influxdb
systemctl enable influxdb --now
systemctl status influxdb

3.创建http接口用于prometheus

执行

curl -XPOST http://localhost:8086/query --data-urlencode "q=CREATE DATABASE prometheus"

返回结果

{"results":[{"statement_id":0}]}

查看数据库prometheus中的保留策略,并修改为默认保留365天

[root@bjo-monitor-ops ~]# influx
Connected to http://localhost:8086 version 1.8.1
InfluxDB shell version: 1.8.1
> show databases;
name: databases
name
----
_internal
prometheus
> use prometheus;
Using database prometheus
> show retention policies on prometheus;
name    duration shardGroupDuration replicaN default
----    -------- ------------------ -------- -------
autogen 0s       168h0m0s           1        true
> alter retention policy "autogen" on "prometheus" duration 365d default;
> show retention policies on prometheus;
name    duration  shardGroupDuration replicaN default
----    --------  ------------------ -------- -------
autogen 8760h0m0s 168h0m0s           1        true
> exit

查看数据库prometheus中的保留策略
show retention policies on prometheus;
修改数据库prometheus中的默认保留策略为365天。
alter retention policy "autogen" on "prometheus" duration 365d default;

4.修改prometheus配置

停止prometheus

systemctl stop prometheus.service

修改找到的起效配置文件

vim /etc/prometheus/prometheus.yml

# Alertmanager configuration
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      # - alertmanager:9093
# 远程读写特性相关的配置,Remote write configuration (for Graphite, OpenTSDB, or InfluxDB).
#
remote_write:
 - url: "http://localhost:8086/api/v1/prom/write?db=prometheus"
remote_read:
 - url: "http://localhost:8086/api/v1/prom/read?db=prometheus"

重启Prometheus

systemctl restart prometheus.service

.

5.查看Influxdb相关信息

查看Influxdb数据库

# influx
Connected to http://localhost:8086 version 1.8.1
InfluxDB shell version: 1.8.1
> use prometheus;
Using database prometheus
> show measurements;
name: measurements
name
----
go_gc_duration_seconds
go_gc_duration_seconds_count
.
.
scrape_samples_scraped
scrape_series_added
up
> exit

查看influxdb相关配置

# ll /usr/bin/influx*

/usr/bin/influxd           influxdb服务器
/usr/bin/influx            influxdb命令行客户端
/usr/bin/influx_inspect    查看工具
/usr/bin/influx_stress     压力测试工具
/usr/bin/influx_tsm        数据库转换工具(将数据库从b1或bz1格式转换为tsm1格式)

# ll /var/lib/influxdb/
/var/lib/influxdb/data     存放最终存储的数据,文件以.tsm结尾
/var/lib/influxdb/meta     存放数据库元数据
/var/lib/influxdb/wal      存放预写日志文件

PID文件/var/lib/influxdb/influxd.pid

6.Grafana在线安装插件

命令行

# 查找
grafana-cli plugins list-remote
# 安装
grafana-cli plugins install alexanderzobnin-zabbix-app
# 重启Grafana服务,让安装的插件生效
systemctl restart grafana-server
# 查看Grafana已安装的插件列表
grafana-cli plugins ls

Grafana数据源

Name:随便输入
Default:设置为开启状态
URL:http://192.168.73.34:9090/ ,写你的prometheus主页地址。
Access:Server(default)
Scrape interval:15s

.

推荐阅读