多个 Vagrant VM 之间的 SSH

多个 Vagrant VM 之间的 SSH

我正在尝试安装 HP Vertica 的本地 3 节点集群。Vertica 安装使用 SSH 在从任何一个节点触发时将 DB Server 软件安装到每个节点上。

我收到一条错误消息,提示“权限被拒绝(公钥)。我查阅了各种 StackOverflow 帖子,并得出了如下 VagrantFile:-

# -*- mode: ruby -*-
# vi: set ft=ruby :

BOX_IMAGE = "ubuntu/xenial64"
NODE_COUNT = 3

Vagrant.configure("2") do |config|
    (1..NODE_COUNT).each do|i|
      config.vm.define "vertica_node#{i}" do |subconfig|
        subconfig.vm.box = BOX_IMAGE
        subconfig.vm.hostname="verticaNode#{i}"

        if i == 1
          subconfig.vm.network "forwarded_port", guest: 5433, host: 5433, id: "Vertica DBEngine"
          subconfig.vm.network "forwarded_port", guest: 5450, host: 5450, id: "Vertica MC"
          subconfig.vm.network "forwarded_port", guest: 1527, host: 1527, id: "Vertica MCDatabase"
        end
        subconfig.vm.network "private_network", ip: "192.168.33.#{i + 10}"

        subconfig.vm.synced_folder "./data", "/vagrant/data", create: true

        subconfig.vm.provider "virtualbox" do |vb|
          vb.name = "VerticaUbuntu_Node#{i}"
          vb.memory = "2048"
        end

      end
    end
  config.ssh.forward_agent = true
  config.ssh.insert_key    = false
  config.ssh.private_key_path = ["~/.vagrant.d/insecure_private_key","~/.ssh/id_rsa"]
  config.vm.provision "shell", path: "bootstrap.sh"
  config.vm.provision "shell", privileged: false do |s|
    ssh_pub_key = File.readlines("#{Dir.home}/.ssh/id_rsa.pub").first.strip
    s.inline = <<-SHELL
    echo #{ssh_pub_key} >> /home/$USER/.ssh/authorized_keys
    sudo bash -c "echo #{ssh_pub_key} >> /root/.ssh/authorized_keys"
    SHELL
  end
end

所有 3 个虚拟机都启动了。我可以通过 SSH 从主机连接到每个客户机。在客户机上,我可以 ping 通其他客户机。

如果我尝试从一位客人通过 SSH 连接到另一位客人,我会收到一条消息

The authenticity of host '192.168.33.11 (192.168.33.11)' can't be established.
ECDSA key fingerprint is SHA256:kEdfmMkISpmDMKGGOw77zCLakujVWZYRQomCMYTWZ0E.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.33.11' (ECDSA) to the list of known hosts.
Permission denied (publickey).

我将非常感激任何帮助解决这个问题的帮助

答案1

我用Vagrant 触发器为了能够从一台机器 ssh 到另一台机器:

Vagrant.configure("2") do |config|
  config.vm.define "master", primary: true do |master|
    # something
  end

  config.vm.define "node" do |node|
    # something else
    node.trigger.after :up do |trigger|
      trigger.run = { inline: 
        "vagrant ssh master -- cp /vagrant/.vagrant/machines/node/virtualbox/private_key ~/.ssh/id_rsa"
      }
    end
  end
end

相关内容