Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- :<<'END'
- Written on 04.02.2022 by Pawel Gasiewski aka Syklighty for Hawe Telekom sp.z.o.o
- Versions of installed software are up to date and working for a date above.
- Software is designated for Linux AMD64 architecture.
- ____ _ _ _ _ _
- / ___|| | ___ _| (_) __ _| |__ | |_ _ _
- \___ \| |/ / | | | | |/ _` | '_ \| __| | | |
- ___) | <| |_| | | | (_| | | | | |_| |_| |
- |____/|_|\_\\__, |_|_|\__, |_| |_|\__|\__, |
- |___/ |___/ |___/
- END
- GREEN='\033[0;32m'
- RED='\033[0;31m'
- NC='\033[0m'
- cd /usr/local/bin
- apt-get install -y unzip > /dev/null
- PS3='Please enter what do you want to install: '
- options=("Promtail" "Grafana Server" "Prometheus Server" "Loki Server" "Node Exporter" "Quit")
- select opt in "${options[@]}"
- do
- case $opt in
- "Promtail")
- echo -e "${GREEN}OK. Installing Promtail and adding system service${NC} \n"
- wget https://github.com/grafana/loki/releases/download/v2.4.2/promtail-linux-amd64.zip
- unzip promtail-linux-amd64.zip
- rm -f promtail-linux-amd64.zip
- tee config-promtail.yaml << EOF > /dev/null
- apiVersion: v1
- kind: ConfigMap
- metadata:
- name: promtail-config
- data:
- promtail.yml: |
- client:
- url: 'http://192.168.75.203:3100/loki/api/v1/push'
- scrape_configs:
- - pipeline_stages:
- - docker:
- job_name: kubernetes-pods-name
- kubernetes_sd_configs:
- - role: pod
- relabel_configs:
- - source_labels:
- - __meta_kubernetes_pod_label_name
- target_label: __service__
- - source_labels:
- - __meta_kubernetes_pod_node_name
- target_label: __host__
- - action: replace
- replacement: $1
- separator: /
- source_labels:
- - __meta_kubernetes_namespace
- - __service__
- target_label: k8s_app
- - action: replace
- source_labels:
- - __meta_kubernetes_namespace
- target_label: k8s_namespace_name
- - action: replace
- source_labels:
- - __meta_kubernetes_pod_name
- target_label: k8s_pod_name
- - action: replace
- source_labels:
- - action: replace
- source_labels:
- - __meta_kubernetes_pod_container_name
- target_label: k8s_container_name
- - replacement: /var/log/pods/*$1/*.log
- separator: /
- source_labels:
- - __meta_kubernetes_pod_uid
- - __meta_kubernetes_pod_container_name
- target_label: __path__
- - replacement: /var/log/pods/*$1/*.log
- separator: /
- source_labels:
- - __meta_kubernetes_pod_uid
- - __meta_kubernetes_pod_container_name
- target_label: __path__
- - pipeline_stages:
- - docker:
- job_name: kubernetes-pods-static
- kubernetes_sd_configs:
- - role: pod
- relabel_configs:
- - action: replace
- source_labels:
- - __meta_kubernetes_pod_label_component
- target_label: __service__
- - source_labels:
- - __meta_kubernetes_pod_node_name
- target_label: __host__
- - action: replace
- replacement: $1
- separator: /
- source_labels:
- - __meta_kubernetes_namespace
- - __service__
- target_label: k8s_app
- - action: replace
- source_labels:
- - __meta_kubernetes_namespace
- target_label: k8s_namespace_name
- - action: replace
- source_labels:
- - __meta_kubernetes_pod_name
- target_label: k8s_pod_name
- - action: replace
- source_labels:
- - __meta_kubernetes_pod_container_name
- target_label: k8s_container_name
- - replacement: /var/log/pods/*$1/*.log
- separator: /
- source_labels:
- - __meta_kubernetes_pod_annotation_kubernetes_io_config_mirror
- - __meta_kubernetes_pod_container_name
- target_label: __path__
- - pipeline_stages:
- job_name: k8s_nodes
- kubernetes_sd_configs:
- - role: node
- EOF
- tee /etc/systemd/system/promtail.service << EOF > /dev/null
- [Unit]
- Description=System service for Promtail - Loki agent for pushing logs
- Wants=network.target
- After=syslog.target network-online.target
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/promtail-linux-amd64 -config.file=/usr/local/bin/config-promtail.yaml
- User=root
- Restart=on-failure
- RestartSec=10
- KillMode=process
- [Install]
- WantedBy=multi-user.target
- EOF
- chmod 640 /etc/systemd/system/promtail.service
- systemctl daemon-reload
- systemctl enable promtail.service
- systemctl start protmail.service
- ;;
- "Grafana Server")
- echo -e "${GREEN}OK. Installing Grafana Server and adding system service${NC} \n"
- apt-get install -y adduser libfontconfig1
- wget https://dl.grafana.com/enterprise/release/grafana-enterprise_8.3.4_amd64.deb
- dpkg -i grafana-enterprise_8.3.4_amd64.deb
- rm -f grafana-enterprise_8.3.4_amd64.deb
- systemctl daemon-reload
- systemctl enable grafana-server
- systemctl start grafana-server
- ;;
- "Prometheus Server")
- echo -e "${GREEN}OK. Installing Prometheus Server with default config and adding system service${NC} \n"
- wget https://github.com/prometheus/prometheus/releases/download/v2.32.1/prometheus-2.32.1.linux-amd64.tar.gz
- tar -xvzf prometheus-2.32.1.linux-amd64.tar.gz
- rm -f prometheus-2.32.1.linux-amd64.tar.gz
- tee /etc/systemd/system/prometheus.service << EOF > /dev/null
- [Unit]
- Description=System service for Prometheus Server
- Wants=network.target
- After=syslog.target network-online.target
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/prometheus-2.32.1.linux-amd64/prometheus --config.file=/usr/local/bin/prometheus-2.32.1.linux-amd64/prometheus.yml
- User=root
- Restart=on-failure
- RestartSec=10
- KillMode=process
- [Install]
- WantedBy=multi-user.target
- EOF
- chmod 640 /etc/systemd/system/prometheus.service
- systemctl daemon-reload
- systemctl enable prometheus.service
- systemctl start prometheus.service
- ;;
- "Loki Server")
- echo -e "${GREEN}OK. Installing Loki Server with default config and adding systems service ${NC} \n"
- wget https://github.com/grafana/loki/releases/download/v2.4.2/loki-linux-amd64.zip
- unzip loki-linux-amd64.zip
- rm -f loki-linux-amd64.zip
- tee config-loki.yaml << EOF > /dev/null
- auth_enabled: false
- 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
- schema_config:
- configs:
- - from: 2020-10-24
- store: boltdb-shipper
- object_store: filesystem
- schema: v11
- index:
- prefix: index_
- period: 24h
- ruler:
- alertmanager_url: http://localhost:9093
- EOF
- tee /etc/systemd/system/loki.service << EOF > /dev/null
- [Unit]
- Description=System service for Loki Server
- Wants=network.target
- After=syslog.target network-online.target
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/loki-linux-amd64 -config.file=/usr/local/bin/config-loki.yaml
- User=root
- Restart=on-failure
- RestartSec=10
- KillMode=process
- [Install]
- WantedBy=multi-user.target
- EOF
- chmod 640 /etc/systemd/system/loki.service
- systemctl daemon-reload
- systemctl enable loki.service
- systemctl start loki.service
- ;;
- "Node Exporter")
- echo -e "${GREEN}OK. Installing Node Exporter and adding system service${NC} \n"
- wget https://github.com/prometheus/node_exporter/releases/download/v1.3.1/node_exporter-1.3.1.linux-amd64.tar.gz
- tar -xvzf node_exporter-1.3.1.linux-amd64.tar.gz
- rm -f node_exporter-1.3.1.linux-amd64.tar.gz
- cp node_exporter-1.3.1.linux-amd64/node_exporter .
- rm -r node_exporter-1.3.1.linux-amd64
- tee /etc/systemd/system/node-exporter.service << EOF > /dev/null
- [Unit]
- Description=System service Node Exporter - hardware metrics exporter
- Wants=network.target
- After=syslog.target network-online.target
- [Service]
- Type=simple
- ExecStart=/usr/local/bin/node_exporter
- User=root
- Restart=on-failure
- RestartSec=10
- KillMode=process
- [Install]
- WantedBy=multi-user.target
- EOF
- chmod 640 /etc/systemd/system/node-exporter.service
- systemctl daemon-reload
- systemctl enable node-exporter.service
- systemctl start node-exporter.service
- ;;
- "Quit")
- echo -e "${GREEN}User requsted exit${NC} \n"
- exit
- ;;
- *) echo -e "${RED}Invalid option $REPLY ${NC} \n";;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement