Public repo to distribute scripts and config's
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 

75 lignes
1.8 KiB

  1. #!/bin/bash
  2. # This script will setup Promtail to push to https://int.loki.grid.tf
  3. set -euo pipefail
  4. ### Install Promtail
  5. export DEBIAN_FRONTEND=noninteractive
  6. mkdir -p /etc/apt/keyrings/
  7. wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor > /etc/apt/keyrings/grafana.gpg
  8. echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" > /etc/apt/sources.list.d/grafana.list
  9. apt-get update -qq && apt-get install -y promtail
  10. usermod -a -G adm promtail
  11. ### Ensure persistent positions directory exists (apt-installed promtail user has primary group nogroup)
  12. install -d -o promtail -g nogroup -m 0755 /var/lib/promtail
  13. ### Set config
  14. cat << EOF > /etc/promtail/config.yml
  15. server:
  16. http_listen_port: 9080
  17. grpc_listen_port: 0
  18. positions:
  19. filename: /var/lib/promtail/positions.yaml
  20. clients:
  21. - url: https://int.loki.grid.tf/loki/api/v1/push
  22. scrape_configs:
  23. - job_name: system
  24. static_configs:
  25. - targets:
  26. - localhost
  27. labels:
  28. host: \${HOSTNAME}
  29. job: varlogs
  30. __path__: /var/log/*log
  31. - job_name: journal
  32. journal:
  33. json: false
  34. max_age: 24h
  35. path: /var/log/journal
  36. labels:
  37. host: \${HOSTNAME}
  38. job: systemd-journal
  39. relabel_configs:
  40. - source_labels: ['__journal__systemd_unit']
  41. target_label: 'unit'
  42. EOF
  43. ### Edit service
  44. cat << EOF > /etc/systemd/system/promtail.service
  45. [Unit]
  46. Description=Promtail service
  47. After=network.target
  48. [Service]
  49. Type=simple
  50. User=promtail
  51. Environment="HOSTNAME=%H"
  52. ExecStart=/usr/bin/promtail -config.file /etc/promtail/config.yml -config.expand-env=true
  53. # Give a reasonable amount of time for promtail to start up/shut down
  54. TimeoutSec = 60
  55. Restart = on-failure
  56. RestartSec = 2
  57. [Install]
  58. WantedBy=multi-user.target
  59. EOF
  60. ### Reload, enable, restart
  61. systemctl daemon-reload
  62. systemctl enable promtail
  63. systemctl restart promtail
  64. systemctl status promtail --no-pager