我已阅读文档页面,但不知道如何设置环境变量。我知道在配置文件中,我需要使用类似
${SOURCE_TOKEN}
或 $SOURCE_TOKEN
的东西。但我该在哪里设置呢?
我尝试过以下方法:
export SOURCE_TOKEN=value
我还将
export SOURCE_TOKEN=value
名称放入 .bashrc
文件中,并使用 source .bashrc
重新加载文件。似乎没什么作用。
当我运行 Vector 时得到这个:
2024-04-10T08:42:16.548863Z INFO vector::app: Log level is enabled. level="info"
2024-04-10T08:42:16.549869Z INFO vector::app: Loading configs. paths=["/etc/vector/vector.yaml"]
2024-04-10T08:42:16.550374Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550390Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550399Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550408Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550412Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550420Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550426Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
2024-04-10T08:42:16.550433Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
你可能只是错过了一些东西。一切都应该工作正常。这是一个例子:
$ vector --version
vector 0.37.0 (x86_64-unknown-linux-gnu c1da408 2024-03-26 13:41:34.870460047)
# config
$ cat /tmp/vector.yaml
sources:
generate_syslog:
type: "demo_logs"
format: "syslog"
count: 100
transforms:
remap_syslog:
inputs:
- "generate_syslog"
type: "remap"
source: |
structured = parse_syslog!(.message)
. = merge(., structured)
sinks:
emit_syslog:
inputs:
- "remap_syslog"
type: "console"
encoding:
codec: ${SOURCE_TOKEN}
# run without SOURCE_TOKEN
vector -c vector.yaml
# ...
# 2024-04-16T20:19:56.180478Z ERROR vector::cli: Configuration error. error=Missing environment variable in config. name = "SOURCE_TOKEN"
# let's try with text
export SOURCE_TOKEN=text
vector -c vector.yaml
# ...
# We're gonna need a bigger boat
# There's a breach in the warp core, captain
# ...
# let's try with json
export SOURCE_TOKEN=json
vector -c vector.yaml
# ...
# {"appname":"b0rnc0nfused","facility":"daemon","hostname":"for.kosher","message":"Great Scott! We're never gonna reach 88 mph with the flux capacitor in its current state!","msgid":"ID619","procid":3582,"service":"vector","severity":"alert","source_type":"demo_logs","timestamp":"2024-04-16T20:24:48.993Z","version":2}
# {"appname":"KarimMove","facility":"uucp","hostname":"for.chrome","message":"A bug was encountered but not in Vector, which doesn't have bugs","msgid":"ID31","procid":1211,"service":"vector","severity":"alert","source_type":"demo_logs","timestamp":"2024-04-16T20:24:49.993Z","version":2}
# ...
Docker 容器示例(JFYI:您可以使用 --env-file 参数):
docker run -e SOURCE_TOKEN=json -v /tmp/vector.yaml:/etc/vector/vector.yaml timberio/vector:0.37.1-alpine