When HiveServer2 is deployed on multiple nodes of an E-MapReduce (EMR) cluster, use ZooKeeper or Server Load Balancer (SLB) to distribute client connections across HiveServer2 instances. The method you choose depends on whether Kerberos authentication is enabled for your cluster.
Prerequisites
Before you begin, ensure that you have:
-
A high-availability EMR cluster with High Service Availability turned on. For more information, see Create a cluster.

Choose a load balancing method
Select a method based on your cluster type and client requirements.
| Method | Kerberos cluster | Hue support | Notes |
|---|---|---|---|
| ZooKeeper | Supported | Not supported on Kerberos clusters | ZooKeeper is installed by default in high-availability clusters |
| SLB | Supported | Supported | Required for Hue on Kerberos clusters |
Common EMR clusters (Kerberos disabled)
Use ZooKeeper
ZooKeeper is installed by default in high-availability clusters. The beeline client uses ZooKeeper service discovery to automatically select and connect to an available HiveServer2 node.
-
Log on to your cluster in SSH mode. For more information, see Log on to a cluster.
-
Run the following command to connect to HiveServer2 through ZooKeeper:
Parameter Description master-1-1:2181,master-1-2:2181,master-1-3:2181ZooKeeper node addresses. Replace with the addresses of your ZooKeeper nodes. serviceDiscoveryMode=zooKeeperEnables ZooKeeper-based service discovery so the client automatically selects an available HiveServer2 node. zooKeeperNamespace=hiveserver2The ZooKeeper path where HiveServer2 registers itself. The default value is hiveserver2. Change this only if you have modified the default registration path in your HiveServer2 configuration.beeline -u 'jdbc:hive2://master-1-1:2181,master-1-2:2181,master-1-3:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2'The connection string uses the following parameters:
Connect Hue to HiveServer2 using ZooKeeper
To connect Hue to HiveServer2 using this method, add the following parameters on the hue tab of the Hue service page in the EMR console.
| Parameter | Value |
|---|---|
zookeeper.clusters.default.hostports |
ZooKeeper node addresses. For example, master-1-1:2181,master-1-2:2181,master-1-3:2181. |
beeswax.hive_discovery_hs2 |
true |
beeswax.hive_discovery_hiveserver2_znode |
/hiveserver2 |
Use SLB
-
Create an SLB instance. For more information, see Create and manage a CLB instance.
-
Add the Elastic Compute Service (ECS) instances on which HiveServer2 is deployed to the default server group and configure the backend server weights based on your requirements. For more information, see Add and manage backend servers in the default server group.

-
Set the listener protocol to TCP. Set Backend Protocol/Port to TCP:10000. Configure the frontend listening port and scheduling algorithm based on your requirements. For more information, see Add a TCP listener.
-
Log on to your cluster in SSH mode. For more information, see Log on to a cluster.
-
Run the following command to connect to HiveServer2 through the SLB instance:
Placeholder Description <slb_ip_or_host>The IP address of the SLB instance, or a hostname that resolves to that IP address. <slb_port>The frontend listening port of the SLB instance. beeline -u 'jdbc:hive2://<slb_ip_or_host>:<slb_port>'Replace the placeholders with your actual values:
Connect Hue to HiveServer2 using SLB
To connect Hue to HiveServer2 using this method, update the following parameters on the hue tab of the Hue service page in the EMR console.
| Parameter | Value |
|---|---|
hive_server2_host |
The IP address of the SLB instance, or a hostname that resolves to that IP address. |
hive_server2_port |
The frontend listening port of the SLB instance. |
EMR clusters with Kerberos authentication enabled
Hue cannot connect to HiveServer2 on a Kerberos cluster using ZooKeeper-based load balancing. To use Hue with a Kerberos cluster, use SLB instead.
Use ZooKeeper
-
Run the
kinitcommand to get a Ticket Granting Ticket (TGT). For more information, see Use Kerberos authentication to access a Hive client. -
Log on to your cluster in SSH mode. For more information, see Log on to a cluster.
-
Run the following command to connect to HiveServer2 through ZooKeeper:
beeline -u 'jdbc:hive2://master-1-1:2181,master-1-2:2181,master-1-3:2181/;serviceDiscoveryMode=zooKeeper;zooKeeperNamespace=hiveserver2'Replace
master-1-1:2181,master-1-2:2181,master-1-3:2181with the addresses of your ZooKeeper nodes.
Use SLB
Create and configure the SLB instance by following the steps in Use SLB under Common EMR clusters (Kerberos disabled). For Kerberos clusters, you must also create a Kerberos principal for the SLB IP address and update the Hive configuration.
The following example uses 121.40.. as the SLB IP address and 10000 as the frontend listening port. Replace these with your actual values.
-
Run the
kinitcommand to get a TGT. For more information, see Use Kerberos authentication to access a Hive client. -
Create a Hive principal for the SLB IP address and export it to a keytab file.
-
Log on to the master-1-1 node. For more information, see Log on to a cluster.
-
Run the following command to open the Kerberos administration tool:
kadmin.localNoteIf your cluster uses open source MIT Kerberos, connect to the Key Distribution Center (KDC) using
kadmin.localorkadmin. -
Run the following commands to create a principal and export it to
/tmp/slb.keytab:addprinc -randkey hive/121.40.**.** xst -k /tmp/slb.keytab hive/121.40.**.** exitImportantEach time you export a principal, previously generated keytab files for that principal become invalid. Delete the existing
/tmp/slb.keytabfile before re-exporting to make sure the file contains only the latest principal.
-
-
Transfer the
slb.keytabfile to all nodes where HiveServer2 is deployed, then merge its content into the Hive keytab on each node:ktutil rkt /tmp/slb.keytab wkt /etc/taihao-apps/hive-conf/keytab/hive.keytab quit -
Verify the keytab content:
klist -kt /etc/taihao-apps/hive-conf/keytab/hive.keytab
-
Update the Hive configuration. On the Configure tab of the Hive service page in the EMR console, search for
hive.server2.authentication.kerberos.principaland set its value to the principal created in step 2. In this example, the value ishive/121.40..@EMR.**.COM. Save the configuration and apply the changes.
-
Restart HiveServer2.
-
On the Status tab of the Hive service page in the EMR console, find HiveServer2 and click Restart in the Actions column.
-
In the dialog box that appears, enter the Execution Reason and click OK.
-
In the Confirm message, click OK.
-
-
Run the following command on the master-1-1 node to connect to HiveServer2:
beeline -u 'jdbc:hive2://121.40.**.**:10000/default;principal=hive/121.40.**.**@EMR.**.COM'