Support Questions
Find answers, ask questions, and share your expertise

How to determine hiveserver2 automatically?

Expert Contributor

I am writing a shell script that needs to identify the hiveserver2 host. I have four clusters and the script can be run in any of the cluster by the user and I don't want them to enter the hiveserver2 host manually as a parameter. How can I get the hiveserver2 ip automatically? Assume that I am running the script in staging and the hiveserver2 ip is 10.258.1.87 and my script should be able to get this ip automatically by some command or method or whatever the best way. Can someone help?

20 REPLIES 20

Re: How to determine hiveserver2 automatically?

@Alex Raj

Can you elaborate your business Objective here please?

Re: How to determine hiveserver2 automatically?

Expert Contributor

I need to create hive table from existing tables and I am using beeline for this. As I have four clusters, the users can run the shell script in any of the cluster and I dont want them to pass the hiverserver2 ip as an argument to the shell script. I though of identifying the hiveserver2 host of the cluster where it runs. For instance, assume that my script is run in prod cluster and the script should be capable of getting the hiveserver2 ip automatically. How can I get it done automatically? Any API call that can be used to get it? I am using CDH 5.5.

Re: How to determine hiveserver2 automatically?

@Alex Raj

interesting question.

Based on my knowledge, check with your Network team for creating DNS Name and ask them to add your four cluster's HS2 IPs under DNS in either round robin or load balance based on you requirement.

then pass just DSN name and 10000 port for users to submit their jobs/Shell Scripts

I hope this will fix your problem.

Re: How to determine hiveserver2 automatically?

Expert Contributor

We still need to pass DNS name. Do we?

Re: How to determine hiveserver2 automatically?

yes, we have to Pass DNS Name.

Re: How to determine hiveserver2 automatically?

Expert Contributor

I do not want to pass anything to the script. Everything should be automatic. Btw, I was looking through some api call to read the hostname but no luck. Let me know if you can help me in that.

Re: How to determine hiveserver2 automatically?

you can try this in shell script for getting host name:

host=`hostname -f`

Re: How to determine hiveserver2 automatically?

Expert Contributor

It displays the edge node's host ip with the command. I am looking for the Hiveserver2 ip.

Re: How to determine hiveserver2 automatically?

Hi @Alex Raj

I would utilize the Ambari API (since Ambari has your HiveServer2 information). Try calling the following API:

curl -H "X-Requested-By: ambari" -X GET -u admin:admin localhost:8080/api/v1/clusters/{yourclustername}/services/HIVE/components/HIVE_SERVER

This will output Json that you can parse, including "host_components" containing the "host_name". Call this on all four of your clusters to get the exact host_name of your HiveServer2.