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
	influx		http://localhost:8086
*	telegraf	http://localhost:8086

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

  urls = [""]

  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 \

-t Ab123456#pwd \

# more .influxdbv2/configs 
  url = "http://localhost:8086"
  token = "fPOiCsoJfAiHDH432nf1ButrsMuG-_MguGbgGL5y8rW0bAdFTOi4v5jzYZOBuQS0vokUfPhRRf232BTVdKKjQQ=="
  org = ""
  previous = true

  url = "http://localhost:8086"
  token = "Ab123456#pwd"
  org = ""

  url = "http://localhost:8086"
  token = "Ab123456#pwd"
  org = ""
  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
Use the environment variables in your telegraf.conf
  urls = ["$INFLUX_HOST"]
  token = "$INFLUX_TOKEN"
  organization = "$INFLUX_ORG"
  bucket = "telegraf"