安装
Loki、promtail、Grafana Prometheus
二进制包安装
Loki,promtail配置文件下载
- wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
- wget https://raw.githubusercontent.com/grafana/loki/master/cmd/promtail/promtail-local-config.yaml
二进制包下载:
最新版本地址:https://github.com/grafana/loki/releases/
loki:
prometheus:
Docker 安装 (本次未测试Docker)
https://hub.docker.com/r/grafana/loki
Loki Docker Image
Running Docker
- docker run -d --name=loki -p 3100:3100 grafana/loki
- To persist data in a docker volume named loki-data:
- docker run -d --name=loki --mount source=loki-data,target=/loki -p 3100:3100 grafana/loki
- To run using a custom config file:
- docker run -d --name=loki --mount type=bind,source="path to loki-config.yaml",target=/etc/loki/local-config.yaml -p 3100:3100 grafana/loki
- In most cases you should specify a tagged release version for running, the above examples all use the implied :latest tag:
-
docker run -d --name=loki -p 3100:3100 grafana/loki:1.4.1
promtail
Loki配置文件
[root@local-debain:~]# cat /opt/loki/loki-local-config.yaml
auth_enabled: false
server:
http_listen_port: 3100
grpc_listen_port: 9096
limits_config:
ingestion_rate_mb: 10
ingestion_burst_size_mb: 20
max_concurrent_tail_requests: 20
max_cache_freshness_per_query: 10m
max_streams_per_user: 50
common:
path_prefix: /tmp/loki
storage:
filesystem:
chunks_directory: /tmp/loki/chunks
rules_directory: /tmp/loki/rules
replication_factor: 1
ring:
instance_addr: 127.0.0.1
kvstore:
store: inmemory
schema_config:
configs:
- from: 2022-05-26
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
chunks:
period: 24h
ruler:
alertmanager_url: http://localhost:9093
table_manager:
retention_deletes_enabled: true
retention_period: 96h
compactor:
working_directory: /tmp/loki/retention
shared_store: filesystem
compaction_interval: 10m
retention_enabled: true
retention_delete_delay: 10s
retention_delete_worker_count: 150
# By default, Loki will send anonymous, but uniquely-identifiable usage and configuration
# analytics to Grafana Labs. These statistics are sent to https://stats.grafana.org/
#
# Statistics help us better understand how Loki is used, and they show us performance
# levels for most users. This helps us prioritize features and documentation.
# For more information on what's sent, look at
# https://github.com/grafana/loki/blob/main/pkg/usagestats/stats.go
# Refer to the buildReport method to see what goes into a report.
#
# If you would like to disable reporting, uncomment the following lines:
#analytics:
# reporting_enabled: false
promtail配置文件
[root@local-debain:~]# cat /opt/promtail/promtail-local-config.yaml
---
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://127.0.0.1:3100/loki/api/v1/push
scrape_configs:
- job_name: Local_Nginx
static_configs:
- targets:
- localhost
labels:
job: nginx
agent: promtail
__path__: /var/log/nginx/*.log
创建安装目录,解压程序并移动到指定特定目录
loki:
mkdir -p /opt/loki
mkdir -p /opt/loki/loki_data
mv loki-linux-amd64 loki-local-config.yaml /opt/loki
promtail:
mkdir -p /opt/promtail
mv promtail-linux-amd64 promtail-local-config.yaml /opt/promtail
创建Systemd服务启动loki
vim /etc/systemd/system/loki.service
[Unit]
Description=loki
Documentation=https://grafana.com/oss/loki/
After=network.target
[Service]
Type=simple
ExecStart=/opt/loki/loki-linux-amd64 --config.file=/opt/loki/loki-local-config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动 loki
systemctl start loki
systemctl status loki
systemctl enable loki
创建Systemd服务启动 promtail
vim /etc/systemd/system/promtail.service
[Unit]
Description=promtail
Documentation=https://github.com/topics/promtail
After=network.target
[Service]
Type=simple
ExecStart=/opt/promtail/promtail-linux-amd64 --config.file=/opt/promtail/promtail-local-config.yaml
Restart=on-failure
[Install]
WantedBy=multi-user.target
启动
systemctl start promtail
systemctl status promtail
systemctl enable promtail
Prometheus 配置
docker pull prom/prometheus
docker run -d --name prometheus --restart=always -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
[root@local-debain:~]# vim /opt/prometheus/prometheus.yml
global:
scrape_interval: 60s
evaluation_interval: 60s
scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['192.168.11.120:9090']
labels:
instance: prometheus
- job_name: node
static_configs:
- targets: ['192.168.11.120:9200']
labels:
origin_prometheus: prometheus
instance: localhost
hostname: LocalHost
- job_name: My
static_configs:
- targets: ['124.222.7.143:9100']
labels:
origin_prometheus: prometheus
instance: Baron-SH
#- job_name: cadvisor
# static_configs:
# - targets: ['172.17.0.4:8080']
# labels:
# instance: cAdvisor
#- job_name: mysqld
# static_configs:
# - targets: ['172.17.0.3:9104']
# labels:
# instance: mysql-exporter
Prometheus node-exporter
docker pull prom/node-exporter
docker run -d -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" --name node-exporter prom/node-exporter
grafana
docker run -d --name grafana --restart=always -p 3000:3000 --name=grafana -v /opt/grafana-storage:/var/lib/grafana grafana/grafana
docker pull grafana/grafana
原文:https://www.yoyoask.com/?p=4436&utm_source=pocket_mylist
参考文章:https://grafana.com/docs/loki/latest/installation/local/
https://grafana.com/grafana/dashboards/13865
https://www.cnblogs.com/aganippe/p/16286332.html
没有评论