「Redmine」- 灵活的项目管理应用

Requirements
# Operating system: 任何安装Ruby环境的机器皆可。
!!我们使用CentOS 7.4服务器。
# Ruby interpreter: 安装Ruby环境。依照文档「Ruby interpreter」要求安装。
!!我们采用RVM安装Ruby 2.6环境。
# Supported database back-ends: 选用MySQL数据库。
!!直接从Yum源中安装MySQL 5.6版本。
# Optional components 可选组件需要安装一些额外的包。比如,SCM,ImageMagick等等。
Redmine Version
!!安装Ruby 2.6环境就是为了选用Redmine 4.0.4版本。
下载:wget https://www.redmine.org/releases/redmine-4.0.4.tar.gz
Installation procedure
#0 注意事项
(1)在Linux中的ACL、SELINUX在导致在安装过程中出现一些问题。
(2)如果不想手动安装,则可以考虑使用第三方的包:「Third-party Redmine bundles」
#1 下载并解压(跳过)
将Redmine解压到/usr/local/redmine/中。
#2 创建数据库用户

CREATE DATABASE redmine CHARACTER SET utf8mb4;
CREATE USER ‘redmine’@’localhost’ IDENTIFIED BY ‘my_password’;
GRANT ALL PRIVILEGES ON redmine.* TO ‘redmine’@’localhost’;

#3 修改数据库配置
复制配置文件:cp config/database.yml.example config/database.yml
修改配置文件:vim config/database.yml
#4 依赖安装

# Redmine使用bundler管理依赖
gem install bundler

# 安装相关依赖(但是你需要先修改一下源)
bundle config mirror.https://rubygems.org https://gems.ruby-china.com
bundle install –without “development” “test” # 如果不修改源,则会卡住不动

# 在执行「bundle install –without “development” “test”」时遇到了一些错误。[……]

READ MORE

「Wekan」- 看板工具(kanban)

问题描述
该笔记将记录:在 Linux 中,如何安装 Wekan 看板工具,简单的使用方法,以及常见问题处理。
解决方案
部署方式的选择
参考 Platforms · wekan/wekan Wiki 文档,以了解官方支持所有部署方式。
我们尝试通过 UCS 安装:UCS 算是个 Linux 发行版,但是与其他发行版的意图不同。它集成各种基础服务(DNS, DHCP, …),我们能够通过 Web 界面直接安装应用,包括这里的 Wekan 应用。优点在于(1)简化部署、自动升级、易于维护,而缺点是(1)鉴于国内的网络环境,会出现各种失败。经过一番折腾,最终我们放弃这种方法。
我们最后通过 Docker Compose 安装(对于我们来说,这优于其他方法)。该方法的缺点是(1)需要自行维护,升级,部署;(2)数据保存在 Docker Volume 中,需要谨慎操作数据。
第一步、服务部署

git clone https://github.com/wekan/wekan.git
cd wekan

# 1)修改服务的端口映射,默认为 80:8080 与本地冲突;
# 2)修改数据存储,将其挂载到本地目录,而非 dockre volume 存储;
# 3)镜像不要使用 latest 标签,因为该 TAG 处于开发状态,未经测试;
vim docker-compose.yaml

# 启动服务
docker-compose up -d

第二步、登录注册
当前版本:quay.io/wekan/wekan:v5.17
根据官方文档(Adding users · wekan/wekan Wiki),没有默认帐号密码,首个注册的用户将成为管理员。
数据备份与数据恢复
参考 Docker · wekan/wekan Wiki · GitHub 文档
数据备份:

# 停止应用
docker stop wekan-app # 防止数据写入

# 导出数据
docker exec -it wekan-db bash
cd /data
rm -rf dump
mongodump
exit

# 复制数据到本地
docker cp wekan-db:/data/dump .

数据恢复:

# 停止应用
docker stop wekan-app # 防止数据写入

# 复制数据到容器
docker exec -it wekan-db bash
cd /data
rm -rf dump
exit
docker cp dump wekan-db:/data/

# 导入数据
docker exec -it wekan-db bash
cd /da[……]

READ MORE

「SonarQube」- Code Quality and Security

[……]

READ MORE

「SonarQube」- 安装、升级

注意事项
生产环境、内嵌数据库
Migrate H2 database for SonarQube version upgrade – SonarQube
我们的 SonarQube 7.9 版本,需要升级到 SonarQube 8.0 版本,但是升级失败。 原因是当初部署的时候使用内嵌数据库,并一直沿用至今,而内嵌数据库是无法迁移的。 官方文档对于内嵌数据库的问题已经再三强调,我们也只能重新部署新的版本。
服务部署
WIP
反向代理
参考 Securing the Server Behind a Proxy 文档,以获取对 Nginx 反向代理的官方配置。

# the server directive is nginx’s virtual host directive
server {
# port to listen on. Can also be set to an IP:PORT
listen 80;

# sets the domain[s] that this vhost server requests for
server_name www.somecompany.com;

location / {
proxy_pass http://sonarhost:sonarport;
}
}[……]

READ MORE

「SonarQube」- 备份与恢复

问题描述
我们使用 Docker 运行 SonarQube 服务。现在我们需要对 SonarQube 服务进行备份。
该笔记将记录: SonarQube 服务的数据备份与恢复方法。
解决方案
官方文档对备份恢复的描述倒是简单,如下(Backup and Restore | SonarQube Docs):

Backing Up Data
Most databases come with backup tools. We recommend using these tools to back up your data.

Restoring Data
To restore data from backup, follow these steps:

Stop the server.
Restore the backup.
Drop the Elasticsearch indexes by deleting the contents of $SQ_HOME/data/es6 directory.
Restart the server.

简单的数据备份
因为不到 4G 数据量,我们也就简单做: 1)停止 SonarQube 服务:docker-compose down 2)执行数据全量备份:rsync –delete -a /path/to/sonarqube /path/to/sonarqube.backup.$(date “+%Y%m%d”) 3)重新启动 SonarQube 服务:docker-compose up
参考文献
Backup and Restore | SonarQube Docs[……]

READ MORE

「SonarQube」- 代码质量检查

配置 SonarQube 检测代码
https://www.sonarqube.org/roadmap
重置密码
How to recover admin password for SONAR Reinstating Admin Access
默认的 用户名/密码 是 admin/admin 。如果忘记密码可以进行重置:

— SonarQube 7.7
update users set crypted_password = ‘$2a$12$uCkkXmhW5ThVK8mpBvnXOOJRLd64LJeHTeCkSuB3lfaR2N0AYBaSi’,
salt=null, hash_method=’BCRYPT’ where login = ‘admin’

参考文献
SonarQube: Continuous Inspection Wikipedia/SonarQube GitHub/SonarSource/sonarqube[……]

READ MORE

「OBSERVABILITY」- 学习指南

研究对象
观测系统
研究结果
1)理论:掌握与观测相关的概念及术语,相关的技术解决方案; 2)实践:部署观测系统,实现对现网环境及系统运行的观测;
研究工具
WIP[……]

READ MORE

「OBSERVABILITY」- 日志收集方案

问题描述
该笔记将记录:与集群日志收集有关的内容,以及常见问题的解决办法;
解决方案
Apache Flume
Welcome to Apache Flume — Apache Flume
GoAccess
GoAccess – Visual Web Log Analyzer
Logwatch
Logwatch download | SourceForge.net
日志类别
系统日志 容器日志
systemd-journal
属于系统日志
kubernetes-events
属于容器日志
收集方案: 1)Grafana Agent/Kubernetes Events
kubernetes-container
linux-kernel
Linux 内核日志;
关于 Linux 系统日志
日志服务
日志轮转
日志分析
关于日志的集中化管理
应用程序错误日志管理
Sentry – https://sentry.io/welcome
日志的来源可以分为两种: 1)由系统产生的日志,通常用 syslog 处理; 2)由应用程序产生的日志,写入自定义的日志文件;
「shell 在手分析服务器日志不愁?」
「Top 8 Log Analyzers」
「基于 Fluentd 的日志收集方案」
「Fluentd | Open Source Data Collector | Unified Logging Layer」
Sentry
ElastAlert – https://github.com/Yelp/elastalert
清华大学开源软件镜像站: https://mirrors.tuna.tsinghua.edu.cn/elasticstack/
参考文献
Wikipedia/Rsyslog Wikipedia/syslog 12 Critical Linux Log Files You Must be Monitoring[……]

READ MORE

「OBSERVABILITY」- 应用性能监测

解决方案
Open Source Application Performance Monitoring (APM) Tools
4)Pinpoint 1)Apache SkyWalking™ | SkyWalking Team 3)Dapper, a Large-Scale Distributed Systems Tracing Infrastructure – Google Research
1)Jaeger: open source, end-to-end distributed tracing 2)OpenZipkin · A distributed tracing system 3)
方案对比
使用 OpenTelemetry 零代码修改接收 SkyWalking 追踪数据 https://zhuanlan.zhihu.com/p/556409746
skywalking 兼容 OpenTelemetry 标准 skywalking 也可以接入 使用 OpenTelemetry 零代码修改接收 SkyWalking 追踪数据 标准里
目前使用较多的就是 pinpoint zipkin jaeger skywalking 这些吧, 然后就官方 agant 支持 rust 的话有 zipkin、skywalking,这两个也都兼容 OpenTelemetry 标准
Rust | OpenTelemetry https://opentelemetry.io/docs/instrumentation/rust/
skywalking-rust/simple_trace_report.rs at master · apache/skywalking-rust (github.com) 这个例子里 skywalking 是 agent 主动上报的
opentelemetry-rust/server.rs at main · open-telemetry/opentelemetry-rust (github.com) 这里有一个跟 grpc 集成的例子,用的就是 tonic 它例子里好像是可以自动处理 propagator 的
[rust 微服务]grpc 分布式追踪怎么做?OpenTelemetry?jaeger?_哔哩哔哩_bilibili skywalking java 栈的,特吃资源。功能也是大而全 jaeger 的 ui 简陋[……]

READ MORE

「Fluentd」- 安装(CentOS 7.x)

第一步、准备工作
1)同步服务器时间: 参考 Time Synchronization/systemd-based 笔记
2)增加文件描述符: 在安装后,通过 systemctl edit 修改,而非修改 system.conf 文件
3)调整内核的参数: 根据官方文件建议,如果是在由多个 Fluentd 实例组成的高负载环境中,优化网络内核参数
第二步、安装启动

# 该脚本将添加 /etc/yum.repos.d/td.repo 仓库,并安装 td-agent 服务
curl -L https://toolbelt.treasuredata.com/sh/install-redhat-td-agent3.sh | sh

# 增加文件描述符
systemctl edit td-agent.service

# 启动服务
systemctl start td-agent.service
systemctl enable td-agent.service

第三步、测试服务
默认 /etc/td-agent/td-agent.conf 配置,从 HTTP 接收数据,并写入 /var/log/td-agent/td-agent.log 文件。
#1 第一步、使用 tail 命令监控日志:

tail -f /var/log/td-agent/td-agent.log

#2 执行如下命令发送“日志”数据:

curl -X POST -d ‘json={“json”:”message”}’ ‘http://localhost:8888/debug.test’

#3 然后观察控制台,如果产生类似如下输入,则表示服务搭建成功:

2020-05-26 16:34:27.089123484 +0800 debug.test: {“json”:”message”}

参考文献
Fluentd/Before Installation Fluentd/Install by RPM Package (Redhat Linux)[……]

READ MORE

「Grafana」- 概念术语

功能概述(⇒ Introduction to Grafana)
Introduction to Grafana | Grafana documentation
Grafana 的主要用途便是数据展示(可视化)。
Grafana OSS,Grafana Open Source Software
当安装后,我们能够根据自己的需要来定制 Grafana 界面,具有多种多样的选择: 1)首先是 in Getting started with Grafana 页面,引导我们入门; 2)通过 Playlist 特性,我们能够来显示天气、只能家居等等内容; 3)作为管理员,能够通过 authentication 和 Provisioning 为团队提供服务; 4)更多的引导和想法,参考 Grafana Labs Community Forums 社区;
Explore metrics, logs, and traces:通过 Grafana 能够浏览数据,进行各种对比。参考 Explore 文档,获取更多详细内容; Alerts:支持多种告警渠道(PagerDuty, SMS, email, VictorOps, OpsGenie, Slack),通过 Alert Rules 来配置告警规则; Annotations:注解功能,允许我们在图上添加注解描述性信息。在出现问题时,关联数据很有用。 Dashboard variables:是对 Dashboard 的复用,允许页面引用变量来呈现不同页面,Variables 决定 Dashboard 的展示数据; Configure Grafana:允许我们对 Grafana 进行各种的配置,前提是我们了解 Grafana 的配置选项及使用方法。 Import dashboards and plugins:支持导入 Dashboard 与 插件。 Authentication:支持多种认证方式,并能将用户划入不同的组织当中。企业版还能划入 Team 中,并集成其他认证系统。 Provisioning:通过该特性,我们能够实现 Grafana 的快速自动部署及应用,快速为团队提供 Grafana 服务; Permissions:通过权限来分离和共享 Dashboard,多不同用户施以不同的权限,企业版还能细化到 Datasource 级别; Other Grafana Labs OSS Projects:Loki 日志平台;Tempo 性能追踪平台;Mimir 为 Prometheus 提供可扩展的长期存储;
Grafana Enterprise
其是 Grafana 企业版本,提供各种企业级功能特性。 出于成本考虑,我们暂时不会购买企业版授权,所以不再关注此部分内容。
Gra[……]

READ MORE

「Grafana」- 配置维护

配置文件(⇒ Setup/Configure Grafana)
Configure Grafana | Grafana documentation
配置文件路径: 1)$WORKING_DIR/conf/defaults.ini 或 /usr/local/etc/grafana/grafana.ini; 2)具体路径取决于系统;
配置注释: 1)使用 ; 对行进行注释;
通过环境变量覆盖配置: 1)GF_<SectionName>_<KeyName> 来指定被覆盖变量的名称;
在配置文件中,使用变量: 1)我们使用的环境变量:${<environment variable>} 2)或者 $__<provider>{<argument>} 形式: —- $__env{LOGDIR}/grafana 从环境变量中读取; —- $__file{/etc/secrets/gf_sql_password} 从文件中读取; —- $__vault{XXXX} 从 Vault 中读取;
至于文档的其余部分,多是配置参数的具体细节,这里不再展开。
Configure Grafana Enterprise
关于企业版的配置,我们这里不再关注。
服务重启(⇒ Setup/Restart Grafana)
与常规的服务重启相似: 1)brew services restart grafana 2)systemctl restart grafana-server 3)docker-compose restart grafana 4)……[……]

READ MORE

「Grafana」- 安装部署

版本选择(⇒ What’s new)
What’s new | Grafana documentation
正如官方文档所述,Grafana 一直在变,对于发布亮点,参考 What’s new 页面。
当部署时,我们通常选用最新的稳定版本(升级是早晚的事情,选用旧版本也要升级)。
服务部署(⇒ Setup/Install Grafana)
Setup | Grafana documentation
官方提供各种安装方法: 1)Install on Debian or Ubuntu 2)Run Grafana Docker image 3)Deploy Grafana on Kubernetes(针对我们的场景,我们只关心该部署方式) 4)Install on RPM-based Linux 5)Install on Windows 6)Install on macOS
服务升级(⇒ Setup/Upgrade Grafana)
Upgrade Grafana | Grafana documentation
根据官方文档描述,升级过程比较简单,但是依旧可能存在轻微地破坏性的变化。
在升级前,官方建议: 1)备份插件 2)备份配置 3)数据库备份,以在降级时恢复;[……]

READ MORE

「Kubernetes」- 部署 Grafana 服务

问题描述
该笔记将记录:在 Kubernetes Cluster 中,部署 Grafana 的方法,以及常见问题的解决办法。
解决方案
官方文档目前仅提供通过 YAML 进行部署的方法,而我们主要采用 HELM 进行部署。
通过 HELM 部署

# 生成 values 文件,并进行配置
helm show values grafana/grafana > grafana.helm-values.yaml

vim grafana.helm-values.yaml
…(1)调整 Ingress 配置

# 安装 Grafana 服务
helm –namespace=grafana upgrade –install grafana grafana/grafana -f grafana.helm-values.yaml

# 查看 Grafana 密码
kubectl get secret –namespace grafana loki-grafana -o jsonpath=”{.data.admin-password}” | base64 –decode ; echo

# Add datasource
# Basic Auth: Username:Password
# http://loki-loki-distributed-gateway.loki.svc.cluster.local/

登录 Grafana 系统
http://localhost:3000/ admin password
参考文献
Deploy Grafana on Kubernetes | Grafana documentation grafana/helm-charts[……]

READ MORE

「Grafana」- 高可用性(⇒ Setup/Set up Grafana for high availability)

[……]

READ MORE

「Grafana」- 观测 Grafana 指标(⇒ Setup/Set up Grafana monitoring)

该笔记提到的监控日志告警是对 Grafana 的检测,而非利用 Grafana 来监控其他服务。
Grafana 支持 Jaeger tracing;能够向 Prometheus 暴露指标;
TODO ! Grafana Loki 的规则及告警的使用方法; TODO ! Grafana Loki 配置告警规则,并在告警中显示日志;[……]

READ MORE

「GRAFANA」- 数据源(Data Source)

数据源列表
Alertmanager AWS CloudWatch Azure Monitor Elasticsearch Google Cloud Monitoring Graphite Loki Microsoft SQL Server (MSSQL) MySQL OpenTSDB PostgreSQL Prometheus Jaeger Zipkin Tempo Testdata
FIXME ! Grafana 展示 Zabbix 监控数据; How to Monitor MySQL with Grafana | Grafana Labs
InfluxDB
通过 Dashboard 配置(GUI)
Grafana documentation/InfluxDB data source
Data Sources / InfluxDB
Query Language: Flux(InfluxDB 2.4.0 使用 Flux 为其查询语言)
HTTP URL: http://172.31.253.41:8086 Access: Server (default)
InfluxDB Details Organization: k4nz.com Token: xxxxxxxxxxxxxxxxxxxx Default Bucket: pve
通过 YAML 配置
Grafana documentation/Provision InfluxDB

apiVersion: 1

datasources:
– name: InfluxDB_v2_Flux
type: influxdb
access: proxy
url: http://localhost:8086
secureJsonData:
token: api-token
jsonData:
version: Flux
organization: organization
defaultBucket: bucket
tlsSkipVerify: true

通过 Provisioning 配置
Data source management | Grafana documentation Grafana documentation/Data sources/Loki
问题描述
当更新 Grafana 配置后,需要重启服务以加载配置,但是如果数据没有持久化,则会导致数据丢失;
解决方案
虽然能够通过内置数据库(sqlite)来持久化存储,但是我们通过配置的方式来进行数据源的配置;
不同 Datasource 的配置方法不同,参考特定[……]

READ MORE

「Grafana」- Explore:数据浏览器(⇒ Explore)

参考文献
Explore | Grafana documentation[……]

READ MORE

「Grafana」- 安全、用户、权限(=> Setup/Configure security)

保护 Grafan 的安全: 1)限制能够访问服务的地址或主机名;限制能够访问数据源的网络地址或主机名;data_source_proxy_whitelist; 2)请求安全:显示用户的请求频率; 3)防火墙安全:通过防火墙,限制对 Grafana 的访问; 4)代理服务器:通过代理服务器来访问 Grafana 界面; 5)显示用户查询权限:即使 Viewer 仅具有某些受限访问权限,而实际上还是能够通过 API 发送各种查询;通过企业版 Data Source Permissions 限制对多个不同数据源的访问权限;或常见组织,在组织内使用数据源,通过数据源的限制,来控制用户访问的数据; 6)匿名访问:对于匿名访问进行一定程度的控制;
Configure authentication
配置访问认证,集中认证:
Configure generic OAuth authentication Configure Google OAuth2 Authentication Configure JWT Authentication Configure Azure AD OAuth2 authentication Configure GitLab OAuth2 Authentication Configure LDAP Authentication Configure enhanced LDAP integration Configure Grafana authentication Configure SAML authentication Configure Okta OAuth2 authentication Configure auth proxy authentication Configure GitHub OAuth2 Authentication
Configure LDAP Authentication
Configure LDAP Authentication | Grafana documentation
FIXME ! Grafana !!! LDAP 相关的认证将是我们关注的重点
Configure database encryption
配置数据库加密:
Encrypt database secrets using Google Cloud KMS Encrypt database secrets using Hashicorp Vault Encrypt database secrets using AWS KMS Encrypt database secrets using Azure Key Vault Integrate Grafana with Hashicorp Vaul[……]

READ MORE

「Grafana Agent」- 指标、日志、追踪

问题描述
我们使用 Grafana Loki 日志系统,现在我们需要采集 Kubernetes Events 信息,并保存到我们的 Grafana Loki 系统中;
经过 Google 查找,我们得知 Grafana Agent 能够完成对 Kubernetes Events 的采集和处理(Kubernetes Events (beta));
该笔记将记录:我们将学习 Grafana Agent 的使用方法,以及与其相关的配置案例,并针对特定问题的解决办法;
解决方案
Grafana Agent | Grafana Agent documentation
GitHub – grafana/agent: Telemetry agent for the LGTM stack.
原理简述
WIP
特性特征
Grafana Agent 具有很多亮点;
但是对于我们来说,它最突出的地方是对各种 exporter 做了集成:其内嵌各种 Exporter 服务(诸如 node_exporter、mysql_exporter 等等),还集成 Log、Metric、Trace 的客户端,减轻我们对微服务的管理。
应用场景
Kubernetes Events Collection[……]

READ MORE

「Grafana Agent」- 服务部署

with Helm
Installing Grafana Agent Operator with Helm | Grafana Agent documentation

helm repo add grafana https://grafana.github.io/helm-charts
helm pull grafana/grafana-agent-operator # grafana-agent-operator-0.2.8.tgz

helm show values ./grafana-agent-operator-0.2.8.tgz > grafana-agent-operator-0.2.8.helm-values.yaml
vim grafana-agent-operator-0.2.8.helm-values.yaml
…(1)nameOverride: “grafana-agent”
…(2)fullnameOverride: “grafana-agent”
…(3)kubeletService.namespace: observing-client

helm install –namespace=observing-client –create-namespace \
grafana-agent \
./grafana-agent-operator-0.2.8.tgz -f grafana-agent-operator-0.2.8.helm-values.yaml[……]

READ MORE

「Grafana Agent」- 采集 Kubernetes Events 日志

问题描述
该笔记将记录:通过 Grafana Agent 采集 Kubernetes Events 日志的方法,以及相关问题的解决办法。
解决方案
第一步、部署 Grafana Agent Operator 组件
参考 Grafana Agent documentation/Installing Grafana Agent Operator with Helm 文档,以获取更多安装细节; 或者,参考 Installing and Upgrading 笔记;
我们通过 Grafana Agent Operator 组件来完成 Grafana Agent 的部署及管理;
第二步、部署 Grafana Agent 实例
参考 Custom Resource Quickstart/Step 1: Deploy GrafanaAgent resource 文档,该文档足够我们运行一个 Grafana Agent 实例;
但是,针对 Kubernetes Events 采集,需要增加额外的 Integration 配置:

apiVersion: monitoring.grafana.com/v1alpha1
kind: GrafanaAgent
metadata:
name: grafana-agent
namespace: observing-client
labels:
app: grafana-agent
spec:

integrations:
selector:
matchLabels:
agent: grafana-agent-integrations

第三步、部署 Log Instance 资源


apiVersion: monitoring.grafana.com/v1alpha1
kind: LogsInstance
metadata:
name: infra-log-central
namespace: observing-client
labels:
agent: grafana-agent-logs
spec:
clients:

# 专用于 kubernetes events 的日志
– url: http://loki-loki-distributed-gateway.loki.svc.cluster.local/loki/api/v1/push
basicAuth:
username:
name: infra-log-central
key: username
password[……]

READ MORE

「Grafana Loki」- 日志收集

问题描述
在我们的技术栈中,Grafana Loki 出现的频率较高,能够覆盖我们多数业务场景,所以我们将尝试对其学习并使用;
该笔记将记录:我们对 Grafana Loki 的学习笔记,与之关的概念术语、部署、使用、维护,及常见问题解决办法;
解决方案
官方文档是我们学习的开始,以官方文档为中心进行学习与使用。
该部分笔记将围绕官方文档展开:
Release notes => Installing and Upgrading Fundamentals => Concepts and Fundamentals Installation => Installing and Upgrading Upgrading => Installing and Upgrading Getting started => Getting Started Best practices => Best practices
Configuration Clients(负责将查询日志发送到 Grafana Loki 中) —- Loki Promtail —- Lambda Promtail —- AWS —- Docker driver —- Fluent Bit —- Fluentd —- Logstash —- k6 load testing Alerting and Recording Rules => Alerting and Recording Rules LogQL => LogQL Operations(运维管理相关的内容,包括 认证、多租户、存储、排障 等等;) —- Authentication => Problems Solving and How-to —- Loki in Grafana —- Observability —- Overrides Exporter —- Scalability —- Storage => Storage (Grafana Loki) —- Multi-tenancy —- Loki Canary —- Troubleshooting —- Recording Rules HTTP API => HTTP API, REST API Storage => Storage (Grafana Loki) Tools Community => Concepts and Fundamentals/Community Maintaining => Concepts and Fundamentals/Maintaining Design[……]

READ MORE

「Grafana Loki」- 概念术语

问题描述
该笔记将记录:与 Grafana Loki 相关的内容,以及相关问题的解决方案。
解决方案
下面的内容是快速阅读官方文档而摘录的关键信息,至少对于我们来说是重要的,以形成对 Grafana Loki 的整体认识,并不具备参考价值,详细内容建议阅读官方文档;
如果有必要,子章节将对我们关心的特定概念进行进一步的讨论和描述;
仅索引元数据;日志以块的形式压缩存储;数据保存在对象存储中;
=> Fundamentals
Overview
Grafana Loki 是整个日志栈的核心组件,除此之外还有其他组件; 日志仅索引元数据,是根据标签;原始日志内容保持不变; Agent 收集日志,转为流,并写入 Loki 中;Promtail Agent 专为 Loki 安装而设计,其他 Agent 也可无缝对接 Loki 服务; App -> Agent -> Loki Loki 索引的是流(流是关联到具有唯一标签集的日志集合),高质量的标签集是关键;
特新特征: 1)在索引时,高效的内存使用:仅索引标签是其优势; 2)多租户(Multi-tenancy):多租户可共享 Loki 实例,日志将以 Tenancy ID 进行区分; 3)LogQL:类似于 PromQL,用于日志查询; 4)可扩展性:所有组件可运行在同个进程中,但又可以微服务的形式独立运行,以支持扩展; 5)灵活性:许多代理(客户端)都有插件支持,这可将现有的可观察性堆栈加入 Loki,使得 Loki 成为其日志聚合工具,而无需切换现有的可观察性堆栈; 6)Grafana 集成:Loki 与 Grafana 无缝集成,提供完整的可观察性堆栈;
关于 EFK 与 Grafana Loki 的对比(官方肯定会列举自生的优势,所以我们也更加关注这些优势): 1)单进程模式,将数据保存在本地;水平扩展模式,则将数据保存在对象存储中;日志直接存储,其仅索引标签;比完整索引的运行成本更低,并允许开发人员积极地从他们的应用程序中进行日志;缺点就是 如果要查询内容,则需要加载所有与标签匹配的块; 2)Promtail 为 Loki 量身定制:主模式发现日志并转发到 Loki 中(附带标签);并能 K8S 服务发现 Pod,或作为 Docker Log Dirver,也能处理 systemd 日志; 3)与 Prometheus 一起,配合服务发现(相同机制),使得 日志 与 Metric 具有相同的标签,使得问题定问和分析更加容易; 4)Grafana 专门针对来自 Prometheus 和 Loki 等来源的时间序列数据量身定制。可以设置仪表板来可视化指标(即将提供日志支持),并且可以使用探索视图对您的数据进行临时查询。与 Kiba[……]

READ MORE

「Grafana Loki」- 最佳实践

Static labels are good 1)类似 host, application, and environment 都是不错的标签,可以固定使用这些标签;
Use dynamic labels sparingly(有节制地) 1)不要过多的使用动态 Label 2)更推荐使用 filter expression 来过滤日志;
Label values must always be bounded 1)还是再说动态标签的问题,不要由过多不同类型的值;
Be aware of dynamic labels applied by clients 1)还是动态标签的问题,通过 logcli 或 Series API 确定 Label 的类型和其取值类型; 2)防止某些不该出现的 Label 被加入 Stream 中;
Configure caching 1)开启数据缓存,以提升 Loki 性能;
Time ordering of logs 1)日志要按时间顺序发送,否则会被决绝(除非允许非按序日志); 2)或建议在日志上增加新 Label 来标识来自不同系统的日志(适用于多主机但日志时间存在偏差的场景) 3)或者 Promtail 创建新的日志时间;
Use chunk_target_size 1)chunk_target_size 只是 Loki 将 Chunk 填充到特定压缩大小(1.5M),这个大小更高效; 2)还有一些选项会影响 Chunk 的填充大小:max_chunk_age=1h,chunk_idle_period=30m 3) 5-10x or 7.5-10MB 才能填充 1.5M 块大小(具体取决于压缩算法); 4)记住,块是基于流;越多的流,内存将存在越多的块;如果 Stream 过多,那很可能在块填满之前就被 Flush 掉; 5)总之,保证块尽量被填满;如果程序日志过多,可以考虑增加 Label 来创建不同 Stream 以保存日志;
-print-config-stderr / -log-config-reverse-order 1)用于在启动的时候打印配置文件;[……]

READ MORE

「Grafana Loki」- 组件

Distributor
1)Wirte Path 的第一站,进行初始化检查,比如 Tenant ID 等等,以减少 Ingester 压力,然后将流量发往多个 Ingester;Distributor 是无状态,前端负载均衡可以流量均发 2)Validation:时间戳检查、Label 检查、日志长度检查等等; 3)Preprocessing:预先处理,比如对 Label 排序以使得 Hash 一致; 4)Rate limiting:能够针对租户进行频率限制;增加 Distributor 节点,这能够限制某租户在每个 Distributor 的写入频率(加入租户和写入频率是固定的); 注意 distributor 使用自己的 ring 来与对等体注册,并获取节点数量,但这与 Ingester 的 ring 是两回事; 5)Forwarding:负责将数据进行转发到 Ingester(负责最后写入); 6)Replication factor:Distributor 会将日志写入多个 Ingester 中,并要保证 floor(replication_factor / 2) + 1 个写入成功;并且还提供 WAL 机制以防止数据丢失; 7)Hashing:Distributor 与 副本因数结合,以确定 Stream 应该写入哪个 Ingester 中;Stream 是通过 LabelSet 及 Tenant ID 进行 Hash 以找到对应的 Ingester 来存储日志;Ingester 将自己注册到 Hash Ring 中,并附带一堆 Token(Random Unsigned Int 32);进行 Hash 查找时,先找到大于 Stream 的最小 Hash,然后是下一个 Ingrester 的 Token,以此类推(顺时针);Ingester 拥有的 Token 仅负责部分范围 Hash; 8)Quorum consistency:Distributor 使用相同的 Hash ring,所以写入请求发往任意一个 Distributor 都是可以的;Loki 使用 Dynamo 风格的仲裁一致性,以保证读写一致,即 Distributor 将等待 (1/2) +1 个 Ingester 返回后再返回给客户端;
Ingester
1)负责将数据写入后端存储;负责将内存查询的日志返回; 2)lifecycler 来管理 Ingester 的生命周期(但是 WAL 取代此功能):PENDING(当它正在等待另一个 ingester 的切换时), JOINING(当它当前将其令牌插入环并初始化自身时。此时能够接收请求), ACTIVE(当它完全初始化时。它可能会收到对其拥有的令牌的写入和读取请求), LEAVING(当它关闭时。它可能会收到对[……]

READ MORE

「Grafana-Loki」- HTTP API

Loki 提供的 HTTP 接口等等;
参考文献
HTTP API | Grafana Loki documentation[……]

READ MORE

「Grafana Loki」- LogQL:日志查询语句(=> /LogQL)

日志查询
Log stream selector
Log pipeline
Log queries examples
度量值查询
时间范围是用来匹配某个时间内的事件频率;
模板函数
匹配网路地址
查询示例
参考文献
LogQL | Grafana Loki documentation[……]

READ MORE

「Grafana Loki」- 存储(Storage)

问题描述
我们将对与 Grafana Loki 存储有关概念进行进一步的学习,以阅读官方文档为主: 1)/Operations/Storage: Storage | Grafana Loki documentation 2)/Storage: Storage | Grafana Loki documentation
该笔记将记录:阅读官方文档而产生的学习笔记,以及相关问题的解决办法;
解决方案
Loki 需要保存两种数据:Chunk;Index;
Grafana Loki 仅索引标签(并不索引日志内容,这与其他日志系统不同),而日志内容则压缩存储,这两点使得 Loki 能够运维简单且成本低廉;
storage schema
/Operations/Storage/Storage schema | Grafana Loki documentation
Grafana Loki 运行其在运行期间切换日志存储,这里的“切换”是指“从某个时间点开始,将后续日志写入新的存储服务中”;
概念术语(⇒ Storage)
Loki,其收到的每条日志有三个组成部分:Tenant-ID;Label-Set;Log-Content;
Stream(流)
通过 Tenant-ID 与 Label-Set 参数,将日志分类为不同的 Stream;
Chunk(块)
针对同个 Stream 的日志条目,其被压缩为 Chunk(块);
Ingester 接收日志条目,并追加(或创建)Chunk,并保存在内存中,最后周期(可配置)刷新到存储系统中;Loki 支持多种存储系统;
能够用于保存 Chunk 的存储有: 1)Amazon DynamoDB 2)Google Bigtable 3)Apache Cassandra 4)Amazon S3 5)Google Cloud Storage 6)Filesystem (please read more about the filesystem to understand the pros/cons before using with production data) 8)Baidu Object Storage
Index(索引)
在 Index 中,保存有 Steam 的 Label-Set,并且关联到相关的 Chunk; Index 也保存在存储中,Loki 支持使用各种不同的存储来保存 Index;
能够用于保存 Index 的存储有: 1)Single Store (boltdb-shipper) – Recommended for 2.0 and newer index store which stores[……]

READ MORE

「Grafana Loki」- 安装部署

问题描述
我们采用 Promtail 来采集日志,Grafana Loki 来存储日志,以对日志进行集中管理(即单个 Grafana Loki 实例);
该笔记将记录:在 Kubernetes Cluster 中,部署 Grafana Loki 的方法,以及相关问题的解决办法;
解决方案
下载 Loki 和 Promtail 程序; 下载两个程序的配置文件; 启动 Loki 服务; 配置 Promtail 文件以抓取日志,并启动 Promtail 服务;
版本选择(⇒ Release notes)
现在(05/20/2022)最新为 2.5 版本,我们首次部署,所以我们并不关心发行说明;
部署模式
如前所述,Loki 的所有模块都在同个二进制程序中。
Monolithic mode 1)-target=all,所有组件在同个进程中运行; 2)可用于测试或小规模使用(<100G);性能取决于节点性能;流量是循环到各节点; 3)通过 memberlist_config 配置,以使多个成员共享同个存储;
Simple scalable deployment mode 1)读写分离:-target=read and -target=write 2)分离读写而带来的高可用、性能提升; 3)需要前端负载均衡,以将 /loki/api/v1/push 推到 wirte node 中; 4)支持 TB 级别日志;若干 TB 级别;

Microservices mode 1)所有组件独立运行:ingester distributor query-frontend query-scheduler querier index-gateway ruler compactor 2)比较复杂(但配置 Kuberntes 比较容易) 3)具有更好的观测性,也是最高效的 Loki 安装; 4)适用于大规模场景以及高可控性;该模式最适合 Kubernetes 部署。有 Jsonnet 和分布式 Helm 图表安装。
安装方法
Installation | Grafana Loki documentation
Install using Tanka (recommended)
# 05/23/2022 我们没有采用该部署方式,原因是:我们的工作需要面对非常多、各种类型的系统,而 Tanka/Jsonnet 并非所有系统都在使用的工具,所以我们暂时不考虑引入该工具(等该工具大面积普及时我们再开始使用);
Simple scalable deployment with Helm
# 05/23/2022 我们暂时不采用该部署方式,所以相关文档不再阅读;
Instal[……]

READ MORE