如何在流浪者中获取IP地址?

时间:2022-01-15 02:57:29

I'm trying to configure a Hadoop cluster, but to do so I needed the ip address of the namenode. The cluster itself is being created by Vagrant, but I don't have the ip address until vagrant creates the instance in AWS. So, I have the following Vagrantfile:

我正在尝试配置一个Hadoop集群,但是要这样做,我需要namenode的ip地址。集群本身是由游民创建的,但是我没有ip地址,直到流浪创建AWS实例。所以,我有以下文件:

current_dir = File.dirname(__FILE__)

$master_script = <<SCRIPT
// will write a script to configure 
SCRIPT

Vagrant.configure("2") do |config|
  config.omnibus.chef_version = :latest

  config.vm.provider :aws do |aws, override|
    config.vm.box = "dummy"
    aws.access_key_id = "MY_KEY"
    aws.secret_access_key = "SECRET_KEY"
    aws.keypair_name = "my_key"
    aws.ami = "ami-7747d01e"
    override.ssh.username = "ubuntu"
    override.ssh.private_key_path = "#{current_dir}/my_key.pem"
  end

  config.vm.provider :virtualbox do |v|
      config.vm.box = "precise64"
      config.vm.box_url =  "https://vagrantcloud.com/chef/ubuntu-13.04/version/1/provider/virtualbox.box"
      v.customize ["modifyvm", :id, "--memory", "1024"]
  end

  config.vm.define :namenode do |namenode|
      namenode.vm.box = "dummy"
      namenode.vm.provision :chef_solo do |chef|
         chef.cookbooks_path = "cookbooks"
         chef.roles_path = "roles"
         chef.add_role "cluster"
      end
      namenode.vm.provision :hostmanager
      namenode.vm.provision "shell", :inline => $master_script
  end



config.vm.define :slave do |slave|
      slave.vm.box = "dummy"
      slave.vm.provision :chef_solo do |chef|
         chef.cookbooks_path = "cookbooks"
         chef.roles_path = "roles"
         chef.add_role "cluster"
      end
      slave.vm.provision :hostmanager
      slave.vm.provision "shell", :inline => $master_script
  end
end

I need to update the mapred-site.xml and core-site.xml files with the ip address of the namenode. How could I get the ip address of the namenode box so I can update the hadoop config files? Is there a better option in the cookbook that I can use to accomplish it? Suppose I have 1 namenode and 5 slaves, the mapred-site.xml.erb template will look like:

我需要更新mapredsite。xml和核心位点。具有namenode的ip地址的xml文件。如何获得namenode框的ip地址以便更新hadoop配置文件?在我的食谱中有更好的选择来完成它吗?假设我有一个namenode和5个从节点,即mapred-site.xml。erb模板如下:

<configuration>
   <property>
      <name>mapred.job.tracker</name>
      <value>hdfs://<%= node[:ipaddress] %>:8021</value>
   </property>
</configuration>

However, I needed that all the namenode and the slaves to have the ip address only of the namenode. How can I accomplish that in chef? Either way will work for me, even though I prefer the chef solution.

但是,我需要所有的namenode和从节点都只有namenode的ip地址。我怎样才能在厨师身上做到这一点呢?这两种方法都可以,尽管我更喜欢chef解决方案。

1 个解决方案

#1


2  

You could:

你可以:

1- Use the instance metadata service on the namenode instance to find out its own ip:

1-使用namenode实例上的实例元数据服务查找自己的ip:

curl http://169.254.169.254/latest/meta-data/local-ipv4

see: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

参见:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

2- Tag the namenode (ex: HADOOP_ROLE=NAMENODE) and use AWS CLI on any instance to find the local ip of the namenode:

2-标记namenode(例如:HADOOP_ROLE= namenode),并在任何实例上使用AWS CLI查找namenode的本地ip:

aws ec2 describe-instances \
  --region=us-east-1 \
  --filter "Name=tag:HADOOP_ROLE,Values=NAMENODE" \
  --query='Reservations[*].Instances[*].PrivateIpAddress' \
  --output=text

see: http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html

参见:http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html

#1


2  

You could:

你可以:

1- Use the instance metadata service on the namenode instance to find out its own ip:

1-使用namenode实例上的实例元数据服务查找自己的ip:

curl http://169.254.169.254/latest/meta-data/local-ipv4

see: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

参见:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html

2- Tag the namenode (ex: HADOOP_ROLE=NAMENODE) and use AWS CLI on any instance to find the local ip of the namenode:

2-标记namenode(例如:HADOOP_ROLE= namenode),并在任何实例上使用AWS CLI查找namenode的本地ip:

aws ec2 describe-instances \
  --region=us-east-1 \
  --filter "Name=tag:HADOOP_ROLE,Values=NAMENODE" \
  --query='Reservations[*].Instances[*].PrivateIpAddress' \
  --output=text

see: http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html

参见:http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html