Chapter 7. Using Custom and Private Hostnames
The Ambari Server relies on the host names of Ambari Agent to communicate to operators which hosts are members of the cluster.
Ambari Agents can be configured to register with the Ambari Server using custom hostnames and public hostnames. Ambari uses the hostname of the agent to name and refer to that host in the Ambari web UI, for example in the Hosts list. The public hostname, if configured, is used as an alias for the host when referenced in configuration and is used in Quick Links URLs.
To determine whether to use a custom hostname or public hostname, consider the following scenarios:
Scenario | Configuration |
---|---|
If you have a host with the host name revo1.hortonworks.local, but you want it to show up in Ambari web UI as c1r1.hortonworks.local, you should configure a custom hostname. | Configure a Custom Host Name |
If you have a host with the host name revo1.hortonworks.local and want to use a DNS CNAME of nn1.hortonworks.local to be used for Quick Links and as a configuration alias, you should configure a public hostname. | Configure a Public Host Name |
Configure a Custom Host Name
It is recommended to not customize the hostname of an Ambari Agent after components have already been deployed to that host. Customizing the hostname for the Ambari Agent will result in a new agent being registered with the custom hostname, not the hostname of an existing agent being updated.
If you have not yet deployed components to the Ambari Agent, use the following steps to configure a custom hostname:
Edit the contents of the
/var/lib/ambari-agent/hostname.sh
script to return the hostname that you want the Ambari Agent to register with. Make sure that you chmod the script so it is executable by the user running the Ambari Agent. For most installations, 0755 is the sufficient permission to use.As an example, the following script could be used to have the Ambari Agent register with the ‘c1r1.hortonworks.local’ hostname.
#!/bin/sh echo ‘c1r1.hortonworks.local’
To configure the Ambari Agent to use this script, edit the /etc/ambari-agent/conf/ambari-agent.ini using a text editor.
Add the following property to the
[agent]
section:hostname_script=/var/lib/ambari-agent/hostname.sh
In this case, Ambari Agent will use the
/var/lib/ambari-agent/hostname.sh
script to determine the hostname that it will use to register with the Ambari Server.Restart the agent to ensure that it registers with the custom hostname:
ambari-agent restart
Configure a Public Host Name
It is common in large cluster deployments to use DNS aliases for specific hosts, so that configuration files mentioning those hosts do not need to be changed when the services on that host are moved to another physical machine. For example, if you have multiple deployed applications that write to HDFS, using a DNS alias instead of a physical hostname to refer to the HDFS NameNode allows you to move the NameNode to other physical machines without having to change those deployed application’s HDFS client configuration.
In Ambari, individual hosts can be configured to use a public hostname when referencing individual hosts in configuration files or in Quick Links. For example, if you have a physical host with a FQDN of revo1.hortonworks.local, and you have a DNS CNAME that also points to that host using nn1.hortonworks.local, it is possible to configure Ambari to use nn1.hortonworks.local for Quick Links associated with that host, and whenever nn1.hortonworks.local is used in configuration, Ambari will understand that it is associated with the revo1.hortonworks.local host. That way if you need to move the NameNode to revo4.hortonworks.local, you can configure that new host to use nn1.hortonworks.local for its public hostname without having to make client configuration changes.
Note | |
---|---|
You still have to modify the specific configuration properties that reference revo1.hortonworks.local and update them with the alias which you have chosen to use, nn1.hortonworks.local in this case, in order for this feature to work as expected. |
To get started, follow the steps below for each host that you would like to configure with a public hostname:
Edit the contents of the
/var/lib/ambari-agent/public_hostname.sh
script to return the public hostname that you want the Ambari Agent to be configured with. Make sure that you chmod the script so it is executable by the user running the Ambari Agent. For most installations, 0755 is the sufficient permission to use.As an example, the following script could be used to configure the Ambari Agent to use ‘nn1.hortonworks.local’ as the public hostname.
#!/bin/sh echo ‘nn1.hortonworks.local’
To configure the Ambari Agent to use this script, edit the
/etc/ambari-agent/conf/ambari-agent.ini
using a text editor.Add the following property to the
[agent]
section:public_hostname_script=/var/lib/ambari-agent/public_hostname.sh
In this case, Ambari Agent will use the
/var/lib/ambari-agent/public_hostname.sh
script to determine the hostname that it will use as the public hostname in the Ambari Server.Restart the agent for these changes to take effect.
ambari-agent restart
Public Hostname Limitations
This capability is currently available on the host level, and not the host-component level; that is, if you have a host which has a NameNode and ResourceManager on it, that host's public hostname will be used in the configuration for both the NameNode and the ResourceManager. It is not possible to specify a public hostname for just the NameNode or just the ResourceManager; instead it’s only possible to specify the public hostname for the physical host that is running both components.
Checking if Public Hostnames Are Correctly Configured
You can use the Ambari REST API to double-check that Ambari has associated the public hostname configured for the Agent.
After logging in to Ambari, open a new tab and use the following URL to look at what has been configured for a specific host:
http://ambari.server:8080/api/v1/hosts/your.hosts.fqdn
Look for ‘public_host_name’ in the JSON returned from that request to ensure that the correct public hostname has been configured for the host in question.