refactor loki

This commit is contained in:
CanbiZ (MickLesk) 2026-01-22 10:34:57 +01:00
parent 63734bd544
commit 58e9c9d6a6
3 changed files with 133 additions and 27 deletions

View File

@ -31,18 +31,24 @@ function update_script() {
msg_info "Stopping Loki" msg_info "Stopping Loki"
systemctl stop loki systemctl stop loki
if systemctl is-active --quiet promtail 2>/dev/null || dpkg -s promtail >/dev/null 2>&1; then
systemctl stop promtail systemctl stop promtail
fi
msg_ok "Stopped Loki" msg_ok "Stopped Loki"
msg_info "Updating Loki" msg_info "Updating Loki"
$STD apt update $STD apt-get update
$STD apt --only-upgrade install -y loki $STD apt-get --only-upgrade install -y loki
$STD apt --only-upgrade install -y promtail if dpkg -s promtail >/dev/null 2>&1; then
$STD apt-get --only-upgrade install -y promtail
fi
msg_ok "Updated Loki" msg_ok "Updated Loki"
msg_info "Starting Loki" msg_info "Starting Loki"
systemctl start loki systemctl start loki
if dpkg -s promtail >/dev/null 2>&1; then
systemctl start promtail systemctl start promtail
fi
msg_ok "Started Loki" msg_ok "Started Loki"
msg_ok "Updated successfully!" msg_ok "Updated successfully!"
exit exit

View File

@ -16,26 +16,75 @@ update_os
msg_info "Installing Loki" msg_info "Installing Loki"
$STD apk add loki $STD apk add loki
$STD sed -i '/http_addr/s/127.0.0.1/0.0.0.0/g' /etc/conf.d/loki $STD sed -i '/http_addr/s/127.0.0.1/0.0.0.0/g' /etc/conf.d/loki
$STD rc-service loki start
mkdir -p /var/lib/loki/{chunks,boltdb-shipper-active,boltdb-shipper-cache}
chown -R loki:grafana /var/lib/loki
mkdir -p /var/log/loki
chown -R loki:grafana /var/log/loki
cat <<EOF >/etc/loki/loki-local-config.yaml
auth_enabled: false
server:
http_listen_port: 3100
log_level: info
common:
instance_addr: 127.0.0.1
path_prefix: /var/lib/loki
storage:
filesystem:
chunks_directory: /var/lib/loki/chunks
rules_directory: /var/lib/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
limits_config:
metric_aggregation_enabled: true
ruler:
alertmanager_url: http://localhost:9093
EOF
chown loki:grafana /etc/loki/loki-local-config.yaml
chmod 644 /etc/loki/loki-local-config.yaml
echo "output_log=\"\${output_log:-/var/log/loki/output.log}\"" >> /etc/init.d/loki
echo "error_log=\"\${error_log:-/var/log/loki/error.log}\"" >> /etc/init.d/loki
echo "start_stop_daemon_args=\"\${SSD_OPTS} -1 \${output_log} -2 \${error_log}\"" >> /etc/init.d/loki
$STD rc-update add loki default $STD rc-update add loki default
$STD mkdir /tmp/loki/ $STD rc-service loki start
$STD chown -R loki:grafana /tmp/loki/
$STD mkdir /var/log/loki/
$STD chown -R loki:grafana /var/log/loki/
$STD chmod 755 /etc/loki/loki-local-config.yaml
$STD sed -i '/^querier:/,/enable_multi_variant_queries: false/ s/^/#/' /etc/loki/loki-local-config.yaml
$STD echo "output_log=\"\${output_log:-/var/log/loki/output.log}\"" >> /etc/init.d/loki
$STD echo "error_log=\"\${error_log:-/var/log/loki/error.log}\"" >> /etc/init.d/loki
$STD echo "start_stop_daemon_args=\"\${SSD_OPTS} -1 \${output_log} -2 \${error_log}\"" >> /etc/init.d/loki
$STD rc-service loki restart
msg_ok "Installed Loki" msg_ok "Installed Loki"
msg_info "Installing Promtail" read -rp "Would you like to install Promtail? (y/N): " INSTALL_PROMTAIL
$STD apk add loki-promtail if [[ "${INSTALL_PROMTAIL,,}" =~ ^(y|yes)$ ]]; then
$STD sed -i '/http_addr/s/127.0.0.1/0.0.0.0/g' /etc/conf.d/loki msg_info "Installing Promtail"
$STD rc-service loki-promtail start $STD apk add loki-promtail
$STD rc-update add loki-promtail default $STD sed -i '/http_addr/s/127.0.0.1/0.0.0.0/g' /etc/conf.d/loki-promtail
msg_ok "Installed Promtail" $STD rc-update add loki-promtail default
$STD rc-service loki-promtail start
msg_ok "Installed Promtail"
fi
motd_ssh motd_ssh
customize customize

View File

@ -20,17 +20,68 @@ setup_deb822_repo \
"https://apt.grafana.com" \ "https://apt.grafana.com" \
"stable" \ "stable" \
"main" "main"
msg_ok "Grafana Repository setup sucessfully" msg_ok "Grafana Repository setup successfully"
msg_info "Installing Loki" msg_info "Installing Loki"
$STD apt install -y loki $STD apt install -y loki
mkdir -p /var/lib/loki/{chunks,boltdb-shipper-active,boltdb-shipper-cache}
chown -R loki:loki /var/lib/loki
cat <<EOF >/etc/loki/config.yml
auth_enabled: false
server:
http_listen_port: 3100
log_level: info
common:
instance_addr: 127.0.0.1
path_prefix: /var/lib/loki
storage:
filesystem:
chunks_directory: /var/lib/loki/chunks
rules_directory: /var/lib/loki/rules
replication_factor: 1
ring:
kvstore:
store: inmemory
schema_config:
configs:
- from: 2020-10-24
store: tsdb
object_store: filesystem
schema: v13
index:
prefix: index_
period: 24h
query_range:
results_cache:
cache:
embedded_cache:
enabled: true
max_size_mb: 100
limits_config:
metric_aggregation_enabled: true
ruler:
alertmanager_url: http://localhost:9093
EOF
chown loki:loki /etc/loki/config.yml
systemctl enable -q --now loki systemctl enable -q --now loki
msg_ok "Installed Loki" msg_ok "Installed Loki"
msg_info "Installing Promtail" read -rp "Would you like to install Promtail? (y/N): " INSTALL_PROMTAIL
$STD apt install -y promtail if [[ "${INSTALL_PROMTAIL,,}" =~ ^(y|yes)$ ]]; then
systemctl enable -q --now promtail msg_info "Installing Promtail"
msg_ok "Installed Promtail" $STD apt install -y promtail
systemctl enable -q --now promtail
msg_ok "Installed Promtail"
fi
motd_ssh motd_ssh
customize customize