The telegraf Unauthorized to InfluxDB

Hi, friends:

I created telegraf in influx config:

[root@fastnetmon ~]# influx config list
Active	Name		URL			Org
	default		http://localhost:8086	demo.net
	influx		http://localhost:8086	demo.net
*	telegraf	http://localhost:8086	demo.net

this is my fragment of /etc/telegraf/telegraf.conf

[[outputs.influxdb]]
  urls = ["http://127.0.0.1:8086"]

  database = "telegraf"

  retention_policy = "influx_retention"
  username = "telegraf"
  password = "Ab123456#pwd"

when I start telegraf, but get below Unauthorized error:

[root@dele telegraf]# /usr/bin/telegraf --config /etc/telegraf/telegraf.conf 
2020-11-30T21:27:25Z I! Starting Telegraf 1.16.2
2020-11-30T21:27:25Z I! Loaded inputs: cpu disk diskio kernel mem processes swap system
2020-11-30T21:27:25Z I! Loaded aggregators: 
2020-11-30T21:27:25Z I! Loaded processors: 
2020-11-30T21:27:25Z I! Loaded outputs: influxdb
2020-11-30T21:27:25Z I! Tags enabled: host=fastnetmon
2020-11-30T21:27:25Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"fastnetmon", Flush Interval:10s
2020-11-30T21:27:25Z W! [outputs.influxdb] When writing to [http://localhost:8086]: database "telegraf" creation failed: 401 Unauthorized
2020-11-30T21:27:35Z E! [outputs.influxdb] When writing to [http://localhost:8086]: 401 Unauthorized
2020-11-30T21:27:35Z E! [agent] Error writing to outputs.influxdb: could not write any address
^C2020-11-30T21:27:40Z I! [agent] Hang on, flushing any cached metrics before shutdown
2020-11-30T21:27:40Z E! [outputs.influxdb] When writing to [http://localhost:8086]: 401 Unauthorized
2020-11-30T21:27:40Z E! [agent] Error writing to outputs.influxdb: could not write any address

I found the token is different from default token, because when create config there only can set token(can not password):

​influx config create -n telegraf \

-u http://localhost:8086 \

-o demo.net \

-t Ab123456#pwd \

-a
# more .influxdbv2/configs 
[default]
  url = "http://localhost:8086"
  token = "fPOiCsoJfAiHDH432nf1ButrsMuG-_MguGbgGL5y8rW0bAdFTOi4v5jzYZOBuQS0vokUfPhRRf232BTVdKKjQQ=="
  org = "demo.net"
  previous = true

[influx]
  url = "http://localhost:8086"
  token = "Ab123456#pwd"
  org = "demo.net"

[telegraf]
  url = "http://localhost:8086"
  token = "Ab123456#pwd"
  org = "demo.net"
  active = true

Hello @mark_123,
What are your token authorizations?
Can you try using an all access token?

@mark_123 influx CLI configs are only available to influx commands. They automatically populate the --host, --org, and --token flags required by most commands. telegraf cannot use the influx CLI configurations.

If you’re using Telegraf to write to InfluxDB Cloud or OSS 2.x, use the influxdb_v2 output plugin. Provide your InfluxDB 2.x host, token, and org in your telegraf.conf. You can either hardcode them or use environment variables:

Store credentials in environment variables
export INFLUX_HOST=http://localhost:8086
export INFLUX_TOKEN=YourInfluxDBAuthToken
export INFLUX_ORG=demo.net
Use the environment variables in your telegraf.conf
[[outputs.influxdb_v2]]
  urls = ["$INFLUX_HOST"]
  token = "$INFLUX_TOKEN"
  organization = "$INFLUX_ORG"
  bucket = "telegraf"