Advertisement
Skylighty

workers

Jan 23rd, 2022
825
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Skrypt dostosowany do OS o architekturze AMD64
  4.  
  5. apt-get -y update && apt-get install -y nano  \\
  6.     && apt-get install -y curl \\
  7.     && apt-get install -y net-tools \\
  8.     && apt-get install -y nc \\
  9.     && apt-get install -y unzip \\
  10.     && apt-get install traceroute
  11.  
  12. cd /home/
  13. mkdir MONITORING
  14. cd MONITORING/
  15.  
  16. # Node Exporter
  17. wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
  18. tar -xvzf node_exporter-1.3.1.linux-amd64.tar.gz
  19. rm -f -xvzf node_exporter-1.3.1.linux-amd64.tar.gz
  20. cd node_exporter-1.3.1.linux-amd64
  21. chmod +x node_exporter
  22. touch /etc/systemd/system/node_exporter.service
  23. tee /etc/systemd/system/node_exporter.service <<EOF
  24. [Unit]
  25. Description=System service for NODE EXPORTER - system metrics exportation
  26. Wants=network.target
  27. After=syslog.target network-online.target
  28.  
  29. [Service]
  30. Type=simple
  31. ExecStart=/home/MONITORING/node_exporter-1.3.1.linux-amd64/node_exporter
  32. User=root
  33. Restart=on-failure
  34. RestartSec=10
  35. KillMode=process
  36.  
  37. [Install]
  38. WantedBy=multi-user.target
  39. EOF
  40. chmod 640 /etc/systemd/system/node_exporter.service
  41. systemctl daemon-reload
  42. systemctl enable node_exporter.service
  43. systemctl start node_exporter.service
  44.  
  45. # Promtail
  46. wget https://github.com/grafana/loki/releases/download/v2.4.2/promtail-linux-amd64.zip
  47. unzip promtail-linux-amd64.zip
  48. tee /home/MONITORING/promtail-config.yaml << EOF
  49. server:
  50.   http_listen_port: 9080
  51.   grpc_listen_port: 0
  52.  
  53. positions:
  54.   filename: /tmp/positions.yaml
  55.  
  56. clients:
  57.   - url: 'http://192.168.75.203:3100/loki/api/v1/push'
  58.  
  59. scrape_configs:
  60.   - job_name: journal
  61.     journal:
  62.       max_age: 12h
  63.       labels:
  64.         job: systemd-journal
  65.     relabel_configs:
  66.       - source_labels: ['__journal__systemd_unit']
  67.         target_label: 'unit'
  68.   - job_name: containers
  69.     pipeline_stages:
  70.     - json:
  71.         expressions:
  72.           output: log
  73.           stream: stream
  74.           attrs:
  75.     - regex:
  76.         expression: (?P<image_name>(?:[^|]*[^|])).(?P<container_name>(?:[^|]*[^|])).(?P<image_id>(?:[^|]*[^|])).(?P<container_id>(?:[^|]*[^|]))
  77.         source: tag
  78.     - timestamp:
  79.         format: RFC3339Nano
  80.         source: time
  81.     - labels:
  82.         tag:
  83.         stream:
  84.         image_name:
  85.         container_name:
  86.         image_id:
  87.         container_id:
  88.     - output:
  89.         source: output
  90.     static_configs:
  91.     - targets:
  92.         - localhost
  93.       labels:
  94.         job: containerlogs
  95.         __path__: /var/lib/docker/containers/*/*log
  96.   - job_name: system
  97.     static_configs:
  98.     - targets:
  99.         - localhost
  100.       labels:
  101.         host: $HOSTNAME
  102.         job: varlogs
  103.         __path__: /var/log/*log
  104. EOF
  105. touch /etc/systemd/system/promtail.service
  106. tee /etc/systemd/system/promtail.service <<EOF
  107. [Unit]
  108. Description=System service for Promtail - Loki agent for pushing logs
  109. Wants=network.target
  110. After=syslog.target network-online.target
  111.  
  112. [Service]
  113. Type=simple
  114. ExecStart=/home/MONITORING/promtail-linux-amd64 -config.file=/home/MONITORING/promtail-config.yaml
  115. User=root
  116. Restart=on-failure
  117. RestartSec=10
  118. KillMode=process
  119.  
  120. [Install]
  121. WantedBy=multi-user.target
  122. EOF
  123. chmod 640 /etc/systemd/system/promtail.service
  124. systemctl daemon-reload
  125. systemctl enable promtail.service
  126. systemctl start promtail.service
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement