grafana-loki-promtai
官网
https://github.com/grafana/loki/releases?page=3
grafana
https://grafana.com/grafana/download/10.4.2?pg=get&plcmt=selfmanaged-box1-cta1
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-10.4.2.linux-amd64.tar.gz
tar -zxvf grafana-enterprise-10.4.2.linux-amd64.tar.gz
mv grafana-v10.4.2/ grafana
汉化
vi /usr/local/grafana/conf/defaults.ini
#default_language = en-US
default_language = zh-Hans
sudo useradd -r grafana
sudo groupadd -r grafana
sudo chown -R grafana:grafana /usr/local/grafana
vim /etc/systemd/system/grafana.service
[Unit]
Description=Grafana
Documentation=https://grafana.com/docs/grafana/latest/
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/grafana/bin/grafana-server --config /usr/local/grafana/conf/defaults.ini --homepath /usr/local/grafana
User=grafana
Group=grafana
Restart=on-failure
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable grafana
systemctl start grafana
systemctl status grafana
sudo systemctl status grafana.service
sudo journalctl -u grafana.service -f
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --reload
https://grafana.com/grafana/dashboards/
loki
/usr/local/loki
- loki (压缩包解压后的二进制文件)
- loki-config.yml (配置文件)
loki-config.yml
# 不开启鉴权
auth_enabled: false
# http和grpc端口
server:
http_listen_port: 3100
grpc_listen_port: 9096
# 数据索引和块存储配置
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
# 缓存管理
query_range:
results_cache:
cache:
embedded_cache:
enabled: false
# 数据存储管理
schema_config:
configs:
- from: 2023-09-01
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
# 数据块的存储策略
chunk_store_config:
max_look_back_period: 240h
# 保存创建数据索引和块等信息的表存储策略
table_manager:
retention_deletes_enabled: true
retention_period: 240h
# 数据块压缩配置
compactor:
working_directory: /tmp/loki/retention
shared_store: filesystem
compaction_interval: 10m
retention_enabled: true
retention_delete_delay: 2h
retention_delete_worker_count: 150
vim /etc/systemd/system/loki.service
[Unit]
Description=Loki: A horizontally-scalable, highly-available, multi-tenant log aggregation system
Documentation=https://grafana.com/docs/loki/latest/
After=network.target
[Service]
ExecStart=/usr/local/loki/loki -config.file=/usr/local/loki/loki-config.yml
Restart=always
User=loki
Group=loki
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
sudo useradd --system --no-create-home --shell /bin/false loki
sudo chown -R loki:loki /usr/local/loki/loki
sudo chmod +x /usr/local/loki/loki
sudo systemctl daemon-reload
sudo systemctl start loki
sudo systemctl enable loki
sudo systemctl status loki
sudo journalctl -u loki -f
firewall-cmd --zone=public --add-port=3100/tcp --permanent
firewall-cmd --zone=public --add-port=9096/tcp --permanent
firewall-cmd --reload
http://192.168.83.252:3100/metrics
Promtail
/usr/local/promtail
- promtail (压缩包解压后的二进制文件)
- promtail-local-config.yaml (配置文件)
promtail-local-config.yaml
server:
http_listen_port: 9080
grpc_listen_port: 0
positions:
filename: /tmp/positions.yaml
clients:
- url: http://192.168.83.252:3100/loki/api/v1/push
scrape_configs:
- job_name: '250-cyg-cloud-auth'
static_configs:
- targets:
- 192.168.83.250
labels:
job: '250-cyg-cloud-auth'
__path__: /logs/cyg-cloud-auth/cyg-cloud-auth.log
stream: 'stdout'
- job_name: '250-cyg-cloud-fic'
static_configs:
- targets:
- 192.168.83.250
labels:
job: '250-cyg-cloud-fic'
__path__: /logs/cyg-cloud-fic/cyg-cloud-fic.log
stream: 'stdout'
- job_name: '250-cyg-cloud-gateway'
static_configs:
- targets:
- 192.168.83.250
labels:
job: '250-cyg-cloud-gateway'
__path__: /logs/cyg-cloud-gateway/cyg-cloud-gateway.log
stream: 'stdout'
vim /etc/systemd/system/promtail.service
[Unit]
Description=Promtail: An agent for shipping logs to Loki
Documentation=https://grafana.com/docs/loki/latest/clients/promtail/
After=network.target
[Service]
ExecStart=/usr/local/promtail/promtail -config.file=/usr/local/promtail/promtail-local-config.yaml
Restart=always
User=promtail
Group=promtail
LimitNOFILE=65536
[Install]
WantedBy=multi-user.target
sudo useradd --system --no-create-home --shell /bin/false promtail
sudo groupadd promtail
sudo chmod +x /usr/local/promtail/promtail
sudo chown -R promtail:promtail /usr/local/promtail/promtail
firewall-cmd --zone=public --add-port=9080/tcp --permanent
firewall-cmd --zone=public --add-port=22/tcp --permanent
firewall-cmd --zone=public --add-port=3100/tcp --permanent
firewall-cmd --zone=public --add-port=9096/tcp --permanent
sudo systemctl daemon-reload
sudo systemctl start promtail
sudo systemctl enable promtail
sudo systemctl status promtail
sudo journalctl -u promtail -f