当前位置:网站首页>Construction of promtail + Loki + grafana log monitoring system

Construction of promtail + Loki + grafana log monitoring system

2022-04-23 16:36:14 Autumnal equinox fishing fire

Introduction to the environment

The construction environment is centos8, Using two servers , among , Machine one is the application server , The other is a function server , Deploy java Application and Promtail , The function of server construction is loki+Grafana

Deploy the application server

install java, function java application , The default log path is /home/log/ Under the path
( Remember this path , stay Promtail The log path needs to be configured during configuration )

loki And promtail install

loki Download address
https://github.com/grafana/loki
Select the following installation package to download
 Insert picture description here
 Insert picture description here

After downloading the file , Use ftp Upload the file to the corresponding installation directory , Use unzip Path decompression

unzip loki-linux-amd64.zip
unzip promtail-linux-amd64.zip

After decompressing the two installation packages , Need to carry out loki And promtail Start of , There are no configuration files in the installation package of both , The configuration file needs to be generated manually for startup
https://grafana.com/docs/loki/latest/installation/local/

wget https://raw.githubusercontent.com/grafana/loki/master/cmd/loki/loki-local-config.yaml
wget https://raw.githubusercontent.com/grafana/loki/main/clients/cmd/promtail/promtail-local-config.yaml

The first is loki Configuration file for , The second is promtail Configuration file for , Download the configuration files of both and modify them

loki The configuration file

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

promtail The configuration file

server:
  http_listen_port: 9080
  grpc_listen_port: 0

positions:
  filename: /tmp/positions.yaml
// This corresponds to loki Service address of , You need to change this address to the server address of the service 
clients:
  - url: http://localhost:3100/loki/api/v1/push

scrape_configs:
// This corresponds to grafana Tag name in the interface 
- job_name: system
  static_configs:
  - targets:
      - localhost
    labels:
      job: varlogs
      // This corresponds to the log storage path ,
      __path__: /var/log/*log

start-up

Save the configuration file of the previous step as yaml file , Put it under the corresponding installation path , Execute the following command

// It has to be executed first loki The start command of , because promtail  Startup time , Will start pushing logs , If loki Not activated , You're going to report a mistake 
./loki-linux-amd64 -config.file=loki.yaml 
./promtail-linux-amd64 --config.file=promtail-local-config.yaml

Grafana install

This installation uses yum Way to install

yum install grafana

After installation , Set power on self start

[root@localhost ~]# systemctl enable grafana-server
Created symlink /etc/systemd/system/multi-user.target.wants/grafana-server.service → /usr/lib/systemd/system/grafana-server.service.
[root@localhost ~]# systemctl start grafana-serve

After setting up , Restart the server , Enter this machine ip:3000
grafana Operation diagram
 Insert picture description here
Here we are ,grafana End of installation , Let's configure

grafana To configure

  1. Configure data sources

    Click on addDataSource , Input loki Make a selection
     Insert picture description here
    To configure url, Here url Build for you loki Server address of the service , Port default 3100
     Insert picture description here
    After configuration, click save & test
     Insert picture description here
    The prompt appears , Represents successful configuration .
     Insert picture description here
    The label here corresponds to promtail The label of the configuration file in
     Insert picture description here
    You can see , The log of the application server has been refreshed to loki in , thus , from Promtail + Loki + Grafana The log monitoring system has been set up , At present, the tutorial corresponds to a single application service , A tutorial on clustering will follow , What if you want to know what happened , Let's hear the decomposition next time
    Next time, there are already
    Basic configuration and implementation of log monitoring system of cluster nginx Load balancing configuration

版权声明
本文为[Autumnal equinox fishing fire]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231402334599.html

随机推荐