新聞中心
前面我們提到了 Loki 部署的單體模式和??讀寫分離兩種模式??,當(dāng)你的每天日志規(guī)模超過(guò)了 TB 的量級(jí),那么可能我們就需要使用到微服務(wù)模式來(lái)部署 Loki 了。

專注于為中小企業(yè)提供成都做網(wǎng)站、成都網(wǎng)站制作服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)寧化免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000家企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
微服務(wù)部署模式將 Loki 的組件實(shí)例化為不同的進(jìn)程,每個(gè)進(jìn)程都被調(diào)用并指定其目標(biāo),每個(gè)組件都會(huì)產(chǎn)生一個(gè)用于內(nèi)部請(qǐng)求的 gRPC 服務(wù)器和一個(gè)用于外部 API 請(qǐng)求的 HTTP 服務(wù)。
- ingester
- distributor
- query-frontend
- query-scheduler
- querier
- index-gateway
- ruler
- compactor
將組件作為單獨(dú)的微服務(wù)運(yùn)行允許通過(guò)增加微服務(wù)的數(shù)量來(lái)進(jìn)行擴(kuò)展,定制的集群對(duì)各個(gè)組件具有更好的可觀察性。微服務(wù)模式部署是最高效的 Loki 安裝,但是,它們的設(shè)置和維護(hù)也是最復(fù)雜的。
對(duì)于超大的 Loki 集群或需要對(duì)擴(kuò)展和集群操作進(jìn)行更多控制的集群,建議使用微服務(wù)模式。
微服務(wù)模式最適合在 Kubernetes 集群中部署,提供了 Jsonnet 和 Helm Chart 兩種安裝方式。
Helm Chart
同樣這里我們還是使用 Helm Chart 的方式來(lái)安裝微服務(wù)模式的 Loki,在安裝之前記得將前面章節(jié)安裝的 Loki 相關(guān)服務(wù)刪除。
首先獲取微服務(wù)模式的 Chart 包:
$ helm repo add grafana https://grafana.github.io/helm-charts
$ helm pull grafana/loki-distributed --untar --version 0.48.4
$ cd loki-simple-scalable
該 Chart 包支持下表中顯示的組件,Ingester、distributor、querier 和 query-frontend 組件是始終安裝的,其他組件是可選的。
|
組件 |
可選 |
默認(rèn)開啟? |
|
gateway |
||
|
ingester |
n/a |
|
|
distributor |
n/a |
|
|
querier |
n/a |
|
|
query-frontend |
n/a |
|
|
table-manager |
||
|
compactor |
||
|
ruler |
||
|
index-gateway |
||
|
memcached-chunks |
||
|
memcached-frontend |
||
|
memcached-index-queries |
||
|
memcached-index-writes |
該 Chart 包在微服務(wù)模式下配置 Loki,已經(jīng)過(guò)測(cè)試,可以與 boltdb-shipper? 和 memberlist? 一起使用,而其他存儲(chǔ)和發(fā)現(xiàn)選項(xiàng)也可以使用,但是,該圖表不支持設(shè)置 Consul 或 Etcd 以進(jìn)行發(fā)現(xiàn),它們需要進(jìn)行單獨(dú)配置,相反,可以使用不需要單獨(dú)的鍵/值存儲(chǔ)的 memberlist。默認(rèn)情況下該 Chart 包會(huì)為成員列表創(chuàng)建了一個(gè) Headless Service,ingester、distributor、querier 和 ruler 是其中的一部分。
安裝minio
比如我們這里使用 memberlist、boltdb-shipper 和 minio 來(lái)作存儲(chǔ),由于這個(gè) Chart 包沒有包含 minio,所以需要我們先單獨(dú)安裝 minio:
$ helm repo add minio https://helm.min.io/
$ helm pull minio/minio --untar --version 8.0.10
$ cd minio
創(chuàng)建一個(gè)如下所示的 values 文件:
# ci/loki-values.yaml
accessKey: "myaccessKey"
secretKey: "mysecretKey"
persistence:
enabled: true
storageClass: "local-path"
accessMode: ReadWriteOnce
size: 5Gi
service:
type: NodePort
port: 9000
nodePort: 32000
resources:
requests:
memory: 1Gi
直接使用上面配置的 values 文件安裝 minio:
$ helm upgrade --install minio -n logging -f ci/loki-values.yaml .
Release "minio" does not exist. Installing it now.
NAME: minio
LAST DEPLOYED: Sun Jun 19 16:56:28 2022
NAMESPACE: logging
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Minio can be accessed via port 9000 on the following DNS name from within your cluster:
minio.logging.svc.cluster.local
To access Minio from localhost, run the below commands:
1. export POD_NAME=$(kubectl get pods --namespace logging -l "release=minio" -o jsonpath="{.items[0].metadata.name}")
2. kubectl port-forward $POD_NAME 9000 --namespace logging
Read more about port forwarding here: http://kubernetes.io/docs/user-guide/kubectl/kubectl_port-forward/
You can now access Minio server on http://localhost:9000. Follow the below steps to connect to Minio server with mc client:
1. Download the Minio mc client - https://docs.minio.io/docs/minio-client-quickstart-guide
2. Get the ACCESS_KEY=$(kubectl get secret minio -o jsonpath="{.data.accesskey}" | base64 --decode) and the SECRET_KEY=$(kubectl get secret minio -o jsonpath="{.data.secretkey}" | base64 --decode)
3. mc alias set minio-local http://localhost:9000 "$ACCESS_KEY" "$SECRET_KEY" --api s3v4
4. mc ls minio-local
Alternately, you can use your browser or the Minio SDK to access the server - https://docs.minio.io/categories/17
安裝完成后查看對(duì)應(yīng)的 Pod 狀態(tài):
$ kubectl get pods -n logging
NAME READY STATUS RESTARTS AGE
minio-548656f786-gctk9 1/1 Running 0 2m45s
$ kubectl get svc -n logging
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
minio NodePort 10.111.58.1969000:32000/TCP 3h16m
可以通過(guò)指定的 32000 端口來(lái)訪問 minio:
然后記得創(chuàng)建一個(gè)名為 loki-data 的 bucket。
安裝Loki
現(xiàn)在將我們的對(duì)象存儲(chǔ)準(zhǔn)備好后,接下來(lái)我們來(lái)安裝微服務(wù)模式的 Loki,首先創(chuàng)建一個(gè)如下所示的 values 文件:
# ci/minio-values.yaml
loki:
structuredConfig:
ingester:
max_transfer_retries: 0
chunk_idle_period: 1h
chunk_target_size: 1536000
max_chunk_age: 1h
storage_config:
aws:
endpoint: minio.logging.svc.cluster.local:9000
insecure: true
bucketnames: loki-data
access_key_id: myaccessKey
secret_access_key: mysecretKey
s3forcepathstyle: true
boltdb_shipper:
shared_store: s3
schema_config:
configs:
- from: 2022-06-21
store: boltdb-shipper
object_store: s3
schema: v12
index:
prefix: loki_index_
period: 24h
distributor:
replicas: 2
ingester:
replicas: 2
persistence:
enabled: true
size: 1Gi
storageClass: local-path
querier:
replicas: 2
persistence:
enabled: true
size: 1Gi
storageClass: local-path
queryFrontend:
replicas: 2
gateway:
nginxConfig:
httpSnippet: |-
client_max_body_size 100M; serverSnippet: |-
client_max_body_size 100M;
上述配置會(huì)選擇性地覆蓋 loki.config 模板文件中的默認(rèn)值,使用 loki.structuredConfig 可以在外部設(shè)置大多數(shù)配置參數(shù)。loki.config、loki.schemaConfig 和 loki.storageConfig 也可以與 loki.structuredConfig 結(jié)合使用。loki.structuredConfig 中的值優(yōu)先級(jí)更高。
這里我們通過(guò) loki.structuredConfig.storage_config.aws 指定了用于保存數(shù)據(jù)的 minio 配置,為了高可用,核心的幾個(gè)組件我們配置了2個(gè)副本,ingester 和 querier 配置了持久化存儲(chǔ)。
現(xiàn)在使用上面的 values 文件進(jìn)行一鍵安裝:
$ helm upgrade --install loki -n logging -f ci/minio-values.yaml .
Release "loki" does not exist. Installing it now.
NAME: loki
LAST DEPLOYED: Tue Jun 21 16:20:10 2022
NAMESPACE: logging
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
***********************************************************************
Welcome to Grafana Loki
Chart version: 0.48.4
Loki version: 2.5.0
***********************************************************************
Installed components:
* gateway
* ingester
* distributor
* querier
* query-frontend
上面會(huì)分別安裝幾個(gè)組件:gateway、ingester、distributor、querier、query-frontend,對(duì)應(yīng)的 Pod 狀態(tài)如下所示:
$ kubectl get pods -n logging
NAME READY STATUS RESTARTS AGE
loki-loki-distributed-distributor-5dfdd5bd78-nxdq8 1/1 Running 0 2m40s
loki-loki-distributed-distributor-5dfdd5bd78-rh4gz 1/1 Running 0 116s
loki-loki-distributed-gateway-6f4cfd898c-hpszv 1/1 Running 0 21m
loki-loki-distributed-ingester-0 1/1 Running 0 96s
loki-loki-distributed-ingester-1 1/1 Running 0 2m38s
loki-loki-distributed-querier-0 1/1 Running 0 2m2s
loki-loki-distributed-querier-1 1/1 Running 0 2m33s
loki-loki-distributed-query-frontend-6d9845cb5b-p4vns 1/1 Running 0 4s
loki-loki-distributed-query-frontend-6d9845cb5b-sq5hr 1/1 Running 0 2m40s
minio-548656f786-gctk9 1/1 Running 1 (123m ago) 47h
$ kubectl get svc -n logging
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
loki-loki-distributed-distributor ClusterIP 10.102.156.1273100/TCP,9095/TCP 22m
loki-loki-distributed-gateway ClusterIP 10.111.73.13880/TCP 22m
loki-loki-distributed-ingester ClusterIP 10.98.238.2363100/TCP,9095/TCP 22m
loki-loki-distributed-ingester-headless ClusterIP None3100/TCP,9095/TCP 22m
loki-loki-distributed-memberlist ClusterIP None7946/TCP 22m
loki-loki-distributed-querier ClusterIP 10.101.117.1373100/TCP,9095/TCP 22m
loki-loki-distributed-querier-headless ClusterIP None3100/TCP,9095/TCP 22m
loki-loki-distributed-query-frontend ClusterIP None3100/TCP,9095/TCP,9096/TCP 22m
minio NodePort 10.111.58.1969000:32000/TCP 47h
Loki 對(duì)應(yīng)的配置文件如下所示:
$ kubectl get cm -n logging loki-loki-distributed -o yaml
apiVersion: v1
data:
config.yaml: |
auth_enabled: false
chunk_store_config:
max_look_back_period: 0s
compactor:
shared_store: filesystem
distributor:
ring:
kvstore:
store: memberlist
frontend:
compress_responses: true
log_queries_longer_than: 5s
tail_proxy_url: http://loki-loki-distributed-querier:3100
frontend_worker:
frontend_address: loki-loki-distributed-query-frontend:9095
ingester:
chunk_block_size: 262144
chunk_encoding: snappy
chunk_idle_period: 1h
chunk_retain_period: 1m
chunk_target_size: 1536000
lifecycler:
ring:
kvstore:
store: memberlist
replication_factor: 1
max_chunk_age: 1h
max_transfer_retries: 0
wal:
dir: /var/loki/wal
limits_config:
enforce_metric_name: false
max_cache_freshness_per_query: 10m
reject_old_samples: true
reject_old_samples_max_age: 168h
split_queries_by_interval: 15m
memberlist:
join_members:
- loki-loki-distributed-memberlist
query_range:
align_queries_with_step: true
cache_results: true
http://m.fisionsoft.com.cn/article/djoogog.html


咨詢
建站咨詢
