Loki安装文档

Loki日志采集系统

安装环境:Linux CentOS 7,jdk1.8

安装组件:Loki-2.2.1 ,promtail-2.2.1 ,grafana-8.3.0

安装Loki

(1)、创建Loki 安装目录,官网下载Loki安装包并解压安装。

$ mkdir /usr/local/loki
$  chmod a+x  /usr/local/loki
$ cd /usr/local/loki
$ curl -O -L "https://github.com/grafana/loki/releases/download/v2.2.1/loki-linux-amd64.zip"
$ unzip loki-linux-amd64.zip

(2)、获取Loki基本配置文件,配置文件可根据需求进行修改。

wget https://raw.githubusercontent.com/grafana/loki/v2.2.1/cmd/loki/loki-local-config.yaml
auth_enabled: false

server:
  http_listen_port: 3100
  grpc_listen_port: 9096

ingester:
  wal:
    enabled: true
    dir: /tmp/wal
  lifecycler:
    address: 127.0.0.1
    ring:
      kvstore:
        store: inmemory
      replication_factor: 1
    final_sleep: 0s
  chunk_idle_period: 1h       # 此时未接收到新日志的任何区块都将被刷新
  max_chunk_age: 1h           # 日志刷新频率
  chunk_target_size: 1048576  # 日志刷新最大空间
  chunk_retain_period: 30s    # 如果使用索引缓存,则必须大于索引读缓存TTL(默认索引读缓存TTL为5m)
  max_transfer_retries: 0     # 区块传输已禁用

schema_config:
  configs:
    - from: 2020-10-24
      store: boltdb-shipper
      object_store: filesystem
      schema: v11
      index:
        prefix: index_
        period: 24h

storage_config:
  boltdb_shipper:
    active_index_directory: /tmp/loki/boltdb-shipper-active
    cache_location: /tmp/loki/boltdb-shipper-cache
    cache_ttl: 24h         #可以在更长的查询周期内提高性能,使用更多的磁盘空间
    shared_store: filesystem
  filesystem:
    directory: /tmp/loki/chunks

compactor:
  working_directory: /tmp/loki/boltdb-shipper-compactor
  shared_store: filesystem

limits_config:
  reject_old_samples: true
  reject_old_samples_max_age: 168h

chunk_store_config:
  max_look_back_period: 0s

table_manager:
  retention_deletes_enabled: false
  retention_period: 0s

ruler:
  storage:
    type: local
    local:
      directory: /tmp/loki/rules
  rule_path: /tmp/loki/rules-temp
  alertmanager_url: http://localhost:9093
  ring:
    kvstore:
      store: inmemory
  enable_api: true

(3)、输入以下命令启动 Loki

./loki-linux-amd64 -config.file=loki-local-config.yaml

安装promtail

(1)、创建安装目录,官网下载promtail安装包并解压安装

  $ mkdir /usr/local/promtail
  $  chmod a+x  /usr/local/promtail
  $ cd /usr/local/promtail
  $ wget  https://github.com/grafana/loki/releases/download/v2.2.1/promtail-linux-amd64.zip
  $ unzip promtail-linux-amd64.zip

(2)、 获取promtail 配置文件

wget https://raw.githubusercontent.com/grafana/loki/v2.2.1/cmd/promtail/promtail-local-config.yaml
server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml

clients:
 #配置Loki容器地址
  - url: http://localhost:3100/loki/api/v1/push

scrape_configs:
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      #配置日志存储地址
      __path__: /var/log/*log

(3)、启动promtail

 ./promtail-linux-amd64 -config.file=promtail-local-config.yaml

安装 grafana

(1)、grafana 下载安装

wget https://dl.grafana.com/oss/release/grafana-8.0.3-1.x86_64.rpm
sudo yum install grafana-8.0.3-1.x86_64.rpm

(2)、Grafana 启动&状态查看

sudo systemctl daemon-reload
sudo systemctl start grafana-server
sudo systemctl status grafana-server

(3)、Grafana 开机自启动

sudo systemctl enable grafana-server

(4)、访问Grafana ip:3000

udo systemctl start grafana-server
sudo systemctl status grafana-server


(3)、Grafana 开机自启动

sudo systemctl enable grafana-server


(4)、访问Grafana ip:3000 

你可能感兴趣的:(linux,服务器,运维)