我正在尝试配置Hadoop
群集,但为此我需要namenode
的IP地址。
群集本身由Vagrant
创建,但在vagrant在AWS中创建实例之前,我没有ip地址。
所以,我有以下Vagrantfile
:
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
我需要使用namenode的mapred-site.xml and core-site.xml
更新ip address
个文件。我怎样才能获得namenode
框的IP地址,以便我可以更新hadoop配置文件?烹饪书中有更好的选择,我可以用它来完成它吗?
假设我有1 namenode
和5 slaves
,mapred-site.xml.erb
模板将如下所示:
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>hdfs://<%= node[:ipaddress] %>:8021</value>
</property>
</configuration>
但是,我需要所有namenode
和slaves
只拥有namenode
的IP地址。我怎样才能在chef
中实现这一目标?
无论哪种方式都适合我,即使我更喜欢chef
解决方案。
答案 0 :(得分:2)
你可以:
1-使用namenode实例上的实例元数据服务找出自己的ip:
curl http://169.254.169.254/latest/meta-data/local-ipv4
请参阅:http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AESDG-chapter-instancedata.html
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
请参阅:http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html