title: How to start hiveserver2 as service
body: <p>Hi all I have setup multi node cluster (i.e 5 node) in my network which working fine.
  now I wanted to insert and retrieve data from cluster using hive thus I have setup hive latest release <strong>apache-hive-0.14.0-bin.tar.gz</strong>  (i.e. <strong>0.14.0</strong> from <a href="http://apache.osuosl.org/hive/hive-0.14.0/" rel="noreferrer"><strong><em>here</em></strong></a> ) on my master node as given in <strong><em><a href="http://tecadmin.net/install-apache-hive-on-centos-rhel/" rel="noreferrer">this</a></em></strong> article.</p>
  
  <p>also I have written a java client class which will make jdbc connection to hive and insert the data into HDFS using hive.</p>
  
  <p><strong><em>HiveJdbcClient.Java</em></strong></p>
  
  <pre><code>public class HiveJdbcClient {
  
  private static final String DRIVER_NAME = "org.apache.hive.jdbc.HiveDriver";
      private static final String HIVE_URL = "jdbc:hive2://x.x.x.x:10000/default";
      private static final String HIVE_UNAME = "";
      private static final String HIVE_PWD = "";
      private static Connection con;
  
      private HiveJdbcClient() {}
  
      public static Connection getConnection() {
          try {
              if (con == null) {
                  synchronized (HiveJdbcClient.class) {
                      if (con == null) {
                          Class.forName(DRIVER_NAME);
                          con = DriverManager.getConnection(HIVE_URL,
                                  HIVE_UNAME, HIVE_PWD);
                          System.out.println("Successfuly Connected to database...!");
                      }
                  }// End of synchronized block.
              }// End of if block.
          } catch (SQLException e) {
              System.out.println("Can Not able to connect to database pls check your settings \n" + e);
          } catch (ClassNotFoundException e) {
              System.out.println("Can Not able to connect to database pls check your settings \n" + e);
          }// End of try-catch block. 
          return con;
      }// End of getConnection() Method.
  
      public static ResultSet executeQuery(String sql) {
          ResultSet set = null;
          try {
              if (sql != null) {
                  set = getConnection().createStatement().executeQuery(sql);
              }
          } catch (SQLException e) {
              System.out.println("Error while executing query " + e);
          }// End of try-catch block.
          return set;
      }// End of executeQuery() Method.
  
      public static void main(String[] args) throws ParseException, SQLException {
          ResultSet res = executeQuery("SELECT * FROM mytable");
          while (res.next()) {
              System.out.println(String.valueOf(res.getString(1)) + '\t'
                      + String.valueOf(res.getFloat(2)) + '\t'
                      + String.valueOf(res.getString(3)));
          }
      }
  }//End of HiveJdbcClient Class.
  </code></pre>
  
  <p>my application able to connect to server when I run following command in terminal</p>
  
  <pre><code>$HIVE_HOME/bin/hiveserver2
  SLF4J: Class path contains multiple SLF4J bindings.
  SLF4J: Found binding in [jar:file:/opt/hadoop-2.6.0/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  SLF4J: Found binding in [jar:file:/opt/apache-hive-0.14.0-bin/lib/hive-jdbc-0.14.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
  OK 
  </code></pre>
  
  <p><strong><em>but when I close this terminal then my application gives following error</em></strong> </p>
  
  <p><strong><em>ERROR</em></strong></p>
  
  <pre><code>java.sql.SQLException: Could not open client transport with JDBC Uri: jdbc:hive2://X.X.X.X:10000/default: java.net.ConnectException: Connection refused
  </code></pre>
  
  <p>that means I have to run hiveserver2 as a service on my master node.</p>
  
  <p>can any one help me to run this hiveserver2 as service. or any link which will help me to run hiveserver2 as service.</p>