如何使 127.0.0.1:4646 在 vagrant 中可访问?

How to make 127.0.0.1:4646 accessible in vagrant?

当我尝试通过命令“vagrant up”在 docker 中构建一个 vagrant 时,显示以下错误消息:

default: Error submitting job: Put http://127.0.0.1:4646/v1/jobs?region=global: dial tcp 127.0.0.1:4646: connect: connection refused
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.

我尝试了几种方法,但都无法使 127.0.0.1:4646 可访问。我接下来想做的是运行“vagrant ssh”然后运行在其中游牧,但这个问题使这成为不可能。

以下是我试过的方法:

  1. 更新游牧至 1.2.3;
  2. 使用intel芯片版本的docker(我用的是Apple m1芯片,之前试过m1芯片版本);
  3. 导出 VAGRANT_ADDR http://127.0.0.1:4646 或 http://localhost:4646.

那么我该如何解决这个问题呢?或者我有其他方法让游牧工作吗?

--------首先编辑-----

vagrant ssh 之后,我使用 nomad agent -dev 正如 @OneCricketeer 所说,下面显示的消息,

vagrant@example-app-host:~$ nomad agent -dev
==> No configuration files loaded
==> Starting Nomad agent...
==> Error starting agent: client setup failed: fingerprinting failed: cannot detect cpu total compute. CPU compute must be set manually using the client config option "cpu_total_compute"
    2021-12-24T04:28:25.552Z [DEBUG] agent.plugin_loader.docker: using client connection initialized from environment: plugin_dir=
    2021-12-24T04:28:25.555Z [DEBUG] agent.plugin_loader.docker: using client connection initialized from environment: plugin_dir=
    2021-12-24T04:28:25.559Z [INFO ] agent: detected plugin: name=qemu type=driver plugin_version=0.1.0
    2021-12-24T04:28:25.560Z [INFO ] agent: detected plugin: name=java type=driver plugin_version=0.1.0
    2021-12-24T04:28:25.560Z [INFO ] agent: detected plugin: name=docker type=driver plugin_version=0.1.0
    2021-12-24T04:28:25.560Z [INFO ] agent: detected plugin: name=rkt type=driver plugin_version=0.1.0
    2021-12-24T04:28:25.560Z [INFO ] agent: detected plugin: name=raw_exec type=driver plugin_version=0.1.0
    2021-12-24T04:28:25.560Z [INFO ] agent: detected plugin: name=exec type=driver plugin_version=0.1.0
    2021-12-24T04:28:25.560Z [INFO ] agent: detected plugin: name=nvidia-gpu type=device plugin_version=0.1.0
    2021-12-24T04:28:25.579Z [INFO ] nomad: raft: Initial configuration (index=1): [{Suffrage:Voter ID:127.0.0.1:4647 Address:127.0.0.1:4647}]
    2021-12-24T04:28:25.581Z [INFO ] nomad: raft: Node at 127.0.0.1:4647 [Follower] entering Follower state (Leader: "")
    2021-12-24T04:28:25.596Z [INFO ] nomad: serf: EventMemberJoin: seller-app-host.global 127.0.0.1
    2021-12-24T04:28:25.598Z [INFO ] nomad: starting scheduling worker(s): num_workers=4 schedulers="[service batch system _core]"
    2021-12-24T04:28:25.605Z [DEBUG] nomad: lost contact with Nomad quorum, falling back to Consul for server list
    2021-12-24T04:28:25.606Z [INFO ] nomad: adding server: server="seller-app-host.global (Addr: 127.0.0.1:4647) (DC: dc1)"
    2021-12-24T04:28:25.615Z [INFO ] client: using state directory: state_dir=/tmp/NomadClient853050605
    2021-12-24T04:28:25.616Z [INFO ] client: using alloc directory: alloc_dir=/tmp/NomadClient128700264
    2021-12-24T04:28:25.623Z [DEBUG] nomad: memberlist: Failed to join 172.17.0.2: dial tcp 172.17.0.2:4648: connect: connection refused
    2021-12-24T04:28:25.624Z [ERROR] nomad: error looking up Nomad servers in Consul: error="contacted 0 Nomad Servers: 1 error(s) occurred:

* Failed to join 172.17.0.2: dial tcp 172.17.0.2:4648: connect: connection refused"
    2021-12-24T04:28:25.645Z [DEBUG] client.fingerprint_mgr: built-in fingerprints: fingerprinters="[arch cgroup consul cpu host memory network nomad signal storage vault env_aws env_gce]"
    2021-12-24T04:28:25.647Z [DEBUG] client.fingerprint_mgr: fingerprinting periodically: fingerprinter=cgroup period=15s
    2021-12-24T04:28:25.659Z [INFO ] client.fingerprint_mgr.consul: consul agent is available
    2021-12-24T04:28:25.663Z [DEBUG] client.fingerprint_mgr: fingerprinting periodically: fingerprinter=consul period=15s
    2021-12-24T04:28:25.665Z [DEBUG] client.fingerprint_mgr.cpu: detected core count: cores=4

nomad 似乎无法正常工作。

然后 nomad status,错误仍然存​​在

vagrant@example-app-host:~$ nomad status
Error querying jobs: Get http://127.0.0.1:4646/v1/jobs?region=global: dial tcp 127.0.0.1:4646: connect: connection refused

我该如何处理?

您似乎试图在 Nomad 启动之前提交一份 Nomad 工作。

"What I wanna do next is [run nomad]".

如果 nomad 尚未 运行ning,则端口 4646 不可访问。 Forwarding a port is already written in the Vagrant documentation,与 VAGRANT_ADDR 不同,您应该取消设置该变量。

您不需要端口 4646 即可使用 vagrant ssh


关于配置 Nomad 集群,我建议研究 Ansible 而不是在 Docker 中使用 vagrant 做事;相反 Docker 将安装在 Vagrant 盒子中,默认情况下 运行 使用 Virtualbox


或者您可以 运行 nomad agent -dev 在您的主机上而不使用任何 VM