说明

自己记录的安装过程, 作为资料供自己使用.

参考

https://gitee.com/frankchenlong/plumelog
https://www.cnblogs.com/mrhugui/p/11544145.html
http://www.soolco.com/post/94167_1_1.html
https://sbcode.net/grafana/install-loki-service/
https://sbcode.net/grafana/install-promtail-service/

安装 loki

  1. wget https://github.com/grafana/loki/releases/download/v2.1.0/loki-linux-amd64.zip
  2. wget https://github.com/grafana/loki/releases/download/v2.1.0/promtail-linux-amd64.zip
  3. wget https://raw.githubusercontent.com/grafana/loki/v2.1.0/cmd/loki/loki-local-config.yaml
  4. wget https://raw.githubusercontent.com/grafana/loki/v2.1.0/cmd/promtail/promtail-local-config.yaml
  5. ./loki-linux-amd64 -config.file=loki-local-config.yaml
  6. # 开放3100端口
  7. firewall-cmd --zone=public --add-port=3100/tcp --permanent
  8. # 配置立即生效
  9. firewall-cmd --reload

安装 grafana

  1. wget https://dl.grafana.com/oss/release/grafana-7.4.3-1.x86_64.rpm
  2. sudo yum install grafana-7.4.3-1.x86_64.rpm
  3. service grafana-server start

设置开机启动

grafana 开机启动

  1. systemctl enable grafana-server

loki 开机启动

  1. cd /etc/systemd/system
  2. touch loki.service
  3. vim /etc/systemd/system/loki.service

将以下内容复制进 loki.service

  1. [Unit]
  2. Description=Loki service
  3. After=network.target
  4. [Service]
  5. Type=simple
  6. ExecStart=/root/loki/loki-linux-amd64 -config.file /root/loki/loki-local-config.yaml
  7. [Install]
  8. WantedBy=multi-user.target
  1. service loki start
  2. service loki status
  3. systemctl enable loki.service

promtail 类同 loki, 注意 execstart 的内容根据自己实际目录进行配置
参考一下配置

  1. server:
  2. http_listen_port: 9080
  3. grpc_listen_port: 0
  4. positions:
  5. filename: /tmp/positions.yaml
  6. clients:
  7. - url: http://localhost:3100/loki/api/v1/push
  8. scrape_configs:
  9. - job_name: test
  10. static_configs:
  11. - targets:
  12. - test
  13. labels:
  14. job: test
  15. host: localhost
  16. __path__: /home/logs/*/*/*log

https://tungchi.cn/2021/04/22/?p=55