安裝influxdb1.x
wget https://dl.influxdata.com/influxdb/releases/influxdb-1.8.0.x86_64.rpm
yum -y localinstall influxdb-1.8.0.x86_64.rpm
編輯配置文件
最終修改效果項如下所示
bind-address = "0.0.0.0:8088"
[meta]
dir = "/var/lib/influxdb/meta"
[data]
dir = "/var/lib/influxdb/data"
wal-dir = "/var/lib/influxdb/wal"
cache-max-memory-size = "8g"
series-id-set-cache-size = 100
[coordinator]
max-concurrent-queries = 0
query-timeout = "0s"
log-queries-after = "10s"
max-select-series = 0
max-select-buckets = 0
[retention]
[shard-precreation]
advance-period = "10m"
[monitor]
[http]
enabled = true
bind-address = ":8086"
log-enabled = false
max-row-limit = 10000
啟動服務(wù)
systemctl start influxdb
systemctl enable influxdb
建庫
curl -XPOST http://192.168.241.13:8086/query --data-urlencode "q=CREATE DATABASE prometheus"
或者
influx -precision rfc3339
create database prometheus;
show databases;
準(zhǔn)備remote_storage_adapter
對于業(yè)務(wù)比較大的環(huán)境Local storage是絕對滿足不了的,那么就要用remote storage了。
Prometheus的remote storage需要借助adapter實現(xiàn),adapter會提供write url和read url給Prometheus,這樣Prometheus獲取到數(shù)據(jù)后就會先寫到本地然后再調(diào)用write url寫到遠端。
下載一個可執(zhí)行文件remote_storage_adapter。
GitHub地址:
https://github.com/prometheus/prometheus/blob/main/documentation/examples/remote_storage/remote_storage_adapter/README.md
需要安裝一個go環(huán)境并進行build。我已經(jīng)build好了,下載下面的地址可以直接用。
wget https://github.com/zyiqian/charts/blob/main/prometheus/remote_storage_adapter
chmod +x remote_storage_adapter
手工啟動
nohup /usr/local/sbin/remote_storage_adapter
--influxdb-url=http://192.168.241.13:8086
--influxdb.database=prometheus
--influxdb.retention-policy=autogen >/var/log/remote_storage_adapter.log 2>&1 &
將remote_storage_adapter注冊為系統(tǒng)服務(wù)
cat>/lib/systemd/system/remote_storage_adapter.service<<EOF
[Service]
Restart=on-failure
WorkingDirectory=/root/
ExecStart=/usr/local/sbin/remote_storage_adapter --influxdb-url=http://192.168.241.13:8086/ --influxdb.database="prometheus" --influxdb.retention-policy=autogen
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable remote_storage_adapter
systemctl start remote_storage_adapter
systemctl status remote_storage_adapter
配置prometheus遠程寫入
修改prometheus.yml中的配置remoteWrite和remoteRead
remote_write:
- url: "http://192.168.241.13:8086/api/v1/prom/write?db=prometheus"
remote_read:
- url: "http://192.168.241.13:8086/api/v1/prom/read?db=prometheus"
查看Influxdb
# influx
Connected to http://localhost:8086 version 1.8.0
influxdb shell version: 1.8.0
> show databases;
name: databases
name
----
prometheus
_internal
> use prometheus
Using database prometheus
> SHOW MEASUREMENTS;
name: measurements
name
----
ALERTS
ALERTS_FOR_STATE
aggregator_openapi_v2_regeneration_count