Centos 7.6部署安装Vector+loki+grafana日志收集

安装Vector

1、添加repo

curl -1sLf 'https://repositories.timber.io/public/vector/cfg/setup/bash.rpm.sh' \
  | sudo -E bash

2、 安装

sudo yum install vector

3、修改vector配置文件

#                                    __   __  __
#                                    \ \ / / / /
#                                     \ V / / /
#                                      \_/  \/
#
#                                    V E C T O R
#                                   Configuration
#
# ------------------------------------------------------------------------------
# Website: https://vector.dev
# Docs: https://vector.dev/docs
# Chat: https://chat.vector.dev
# ------------------------------------------------------------------------------

# Change this to use a non-default directory for Vector data storage:
# data_dir = "/var/lib/vector"

# Random Syslog-formatted logs
[sources.dummy_logs]
type = "demo_logs"
format = "syslog"
interval = 1

# Parse Syslog logs
# See the Vector Remap Language reference for more info: https://vrl.dev
[transforms.parse_logs]
type = "remap"
inputs = ["dummy_logs"]
source = '''
. = parse_syslog!(string!(.message))
'''

# Print parsed logs to stdout
#[sinks.print]
#type = "console"
#inputs = ["parse_logs"]
#encoding.codec = "json"
[sinks.save_file]
type = "loki"
inputs = [ "parse_logs" ]
endpoint = "http://192.168.70.201:3100"
compression = "none"

  [sinks.save_file.labels]
  forwarder = "vector"
  event = "{{ event_field }}"
  key = "value"
  "\"{{ event_field }}\"" = "{{ another_event_field }}"

  [sinks.save_file.encoding]
  codec = "json"
# Vector's GraphQL API (disabled by default)
# Uncomment to try it out with the `vector top` command or
# in your browser at http://localhost:8686
[api]
enabled = true
address = "127.0.0.1:8686"

4、启动vector

systemctl start vector

5、查看启动状态

[root@localhost ~]# systemctl status vector
● vector.service - Vector
   Loaded: loaded (/usr/lib/systemd/system/vector.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2022-06-17 16:06:08 CST; 15min ago
     Docs: https://vector.dev
  Process: 22497 ExecStartPre=/usr/bin/vector validate (code=exited, status=0/SUCCESS)
 Main PID: 22501 (vector)
   CGroup: /system.slice/vector.service
           └─22501 /usr/bin/vector

Jun 17 16:06:08 localhost.localdomain vector[22497]: √ Health check "save_file"
Jun 17 16:06:08 localhost.localdomain vector[22497]: ------------------------------------
Jun 17 16:06:08 localhost.localdomain vector[22497]: Validated
Jun 17 16:06:08 localhost.localdomain systemd[1]: Started Vector.
Jun 17 16:06:08 localhost.localdomain vector[22501]: 2022-06-17T08:06:08.226094Z  INFO vector::app: Log level is enabled. level="vector...e=info"
Jun 17 16:06:08 localhost.localdomain vector[22501]: 2022-06-17T08:06:08.226202Z  INFO vector::app: Loading configs. paths=["/etc/vecto....toml"]
Jun 17 16:06:08 localhost.localdomain vector[22501]: 2022-06-17T08:06:08.238185Z  INFO vector::topology::running: Running healthchecks.
Jun 17 16:06:08 localhost.localdomain vector[22501]: 2022-06-17T08:06:08.238336Z  INFO vector: Vector has started. debug="false" versio...-06-15"
Jun 17 16:06:08 localhost.localdomain vector[22501]: 2022-06-17T08:06:08.238354Z  INFO vector::internal_events::api: API server running...yground
Jun 17 16:06:08 localhost.localdomain vector[22501]: 2022-06-17T08:06:08.240581Z  INFO vector::topology::builder: Healthcheck: Passed.
Hint: Some lines were ellipsized, use -l to show in full.

安装loki

1、关闭selinux
2、安装docker

yum install docker -y

3、安装loki

# 下载配置文件
wget https://raw.githubusercontent.com/grafana/loki/v2.5.0/cmd/loki/loki-local-config.yaml -O loki-config.yaml

# docker启动
docker run --name loki -d -v $(pwd):/mnt/config -p 3100:3100 grafana/loki:2.5.0 -config.file=/mnt/config/loki-config.yaml

4、查看loki状态

[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
0b1763c45fb7        grafana/loki:2.5.0   "/usr/bin/loki -co..."   About an hour ago   Up 43 minutes       0.0.0.0:3100->3100/tcp   loki

安装grafana

1、安装

# 拉取镜像
docker pull grafana/grafana
# 开启容器
docker run -d -p 3000:3000 --name grafana grafana/grafana

2、配置

登录grafana地址导入loki数据源(填写loki容器内ip地址)即可看到日志信息

posted @ 2022-06-16 19:08  dqforgive-sudo  阅读(1989)  评论(0)    收藏  举报