Https://localhost:8221/ errored!


When installing elastic agent on remote servers It shows that it is successful and I can see logs in Kibana:

root@srv:~/elastic-agent-8.7.1-linux-x86_64# ./elastic-agent install --url=https://ip:port --fleet-server-es=https://ip:port --fleet-server-service-token=AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTE2ODQ4NTUwODY5NjM6ZDMtd3Vy.... --enrollment-token=QktyWlVvZ0I0TC16Q05jdFU0ZzM6d2VaYU...== --certificate-authorities=/etc/ssl/certs/elasticsearch-ca.pem
Elastic Agent will be installed at /opt/Elastic/Agent and will run as a service. Do you want to continue? [Y/n]:
{"log.level":"info","@timestamp":"2023-05-25T12:40:25.110Z","log.origin":{"":"cmd/enroll_cmd.go","file.line":407},"message":"Generating self-signed certificate for Fleet Server","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2023-05-25T12:40:27.853Z","log.origin":{"":"cmd/enroll_cmd.go","file.line":803},"message":"Fleet Server - Starting","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2023-05-25T12:40:31.854Z","log.origin":{"":"cmd/enroll_cmd.go","file.line":784},"message":"Fleet Server - Running on default policy with Fleet Server integration; missing config (expected during bootstrap process)","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2023-05-25T12:40:32.219Z","log.origin":{"":"cmd/enroll_cmd.go","file.line":475},"message":"Starting enrollment to URL: https://w1.connect:8220/","ecs.version":"1.6.0"}
{"log.level":"info","@timestamp":"2023-05-25T12:40:33.992Z","log.origin":{"":"cmd/enroll_cmd.go","file.line":273},"message":"Successfully triggered restart on running Elastic Agent.","ecs.version":"1.6.0"}
Successfully enrolled the Elastic Agent.
Elastic Agent has been successfully installed.

But after this In Kibana --> Fleet --> I can see the agent is updating then it goes offline. After checking status on agent I got this:

root@srv:~/elastic-agent-8.7.1-linux-x86_64# elastic-agent status
Message: Running
Fleet State: FAILED
Fleet Message: fail to checkin to fleet-server: all hosts failed: 1 error occurred:
	* requester 0/1 to host https://localhost:8221/ errored: Post "https://localhost:8221/api/fleet/agents/52bd17c2-4c48-4791-9054-...../checkin?": dial tcp [::1]:8221: connect: connection refused

  * http/metrics    (HEALTHY)
                    Healthy: communicating with pid '23443'
  * filestream      (HEALTHY)
                    Healthy: communicating with pid '23445'
  * beat/metrics    (HEALTHY)
                    Healthy: communicating with pid '23444'
  * log             (HEALTHY)
                    Healthy: communicating with pid '23437'
  * system/metrics  (HEALTHY)
                    Healthy: communicating with pid '23442'
  * nginx/metrics   (HEALTHY)
                    Healthy: communicating with pid '23462'

I've been struggling since days on this with not enough or such error after googling on this.

Please HELP!

By the args you give during installation looks like the agent you're installing should run fleet-server, but it does not appear in the components list.

Are you intending to run a local fleet-server process?
If so, please provide a diagnostics bundle so we can figure out what's killing the fleet-server process.
If not, try to re-install without the --fleet-server-* flags

I see that the discussion is going on in Fail to checkin to fleet-server, i'll post my comment there so we can have this discussion in the same thread.