Reputation: 10961
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
:
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:
<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.
Upvotes: 4
Views: 3093
Reputation: 13501
You could:
1- Use the instance metadata service on the namenode instance to find out its own 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
2- Tag the namenode (ex: HADOOP_ROLE=NAMENODE) and use AWS CLI on any instance to find the local ip of the namenode:
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
Upvotes: 2