使用远程服务器 (别的服务器连接hive)beeline(踩坑日记)

首先 在hadoop集群的基础上部署 hive(这里hadoop集群和hive部署可以自己去搜索文章 很多)

hive要部署到hadoop的主机上 

hive部署完成后要确保 hive能正常使用 并 hadoop集群机器做了 免密ssh登录

首先使用 scp 传输到你要做beeline的机器上

#/opt/module/hive 主机器的hive目录 换成你的 
# a3 为你要传的机器名 如果你做了免密ssh就可以这样用 也可以用ip 
#/opt/module 接收存放目录
scp -r /opt/module/hive root@a3:/opt/module

为了防止出现以下错误

Error: Could not open client transport with JDBC 
Uri: jdbc:hive2://hadoop1:10000/default: Failed to open new session: java.lang.RuntimeException:
org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): 
User: root is not allowed to impersonate anonymous (state=08S01,code=0)

 找到你hadoop的core-site.xml文件

vi /hadoop/etc/hadoop/core-site.xml

在你的配置下 添加

<configuration> 
       <property>     
	        <name>hadoop.proxyuser.root.hosts</name>     
	        <value>*</value> 
        </property> 
        <property>     
	        <name>hadoop.proxyuser.root.groups</name>     
	        <value>*</value> 
        </property>
</configuration>

#!!!!注意 外面如果没有<configuration></configuration> 要加上哦
#不然会出现想不到的错误

 重启hadoop集群

然后进入到 hive目录下

bin/beeline

如果弹出

Cannot find hadoop installation: $HADOOP_HOME or $HADOOP_PREFIX must be set or hadoop must be in the path

找到 hive/conf文件cd到 conf下面

注意 我因为执行过

mv hive-env.sh.template hive-env.sh命令 

所以我的是 hive-env.sh 如果你没有改名 那么你 就 vim  hive-env.sh.template

vi也可以

vim hive-env.sh

然后使用 bin/beeline(要进入到hive目录下哦)

 在使用!connect jdbc:hive2://远程服务器ip:10000/default

然后输入主机器的用户名 密码就可以

注意 这里如果一直一直一直没有反应 

那么你需要去主服务器看一下 hiveserver2启动了没 

hiveserver2启动非常非常非常慢 所以要等很长时间

后台启动并打印日志

nohup ./bin/hiveserver2>> hiveserver2.log 2>&1 &

 查看服务是否启动

netstat -anp|grep 10000

如果出现就证明启动了

 然后进入 hive目录下

cd /hive(这是我的路径)
运行
bin/beeline
再使用
!connect jdbc:hive2://远程服务器ip:10000/default

出现

证明连接成功 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
以下是连接远程Hive服务器的步骤: 1.进入Hive目录,运行beeline命令: ```shell cd /hive bin/beeline ``` 2.使用以下命令连接远程Hive服务器: ```shell !connect jdbc:hive2://远程服务器ip:10000/default ``` 3.如果需要在远程服务器上启动Hive服务接口,可以使用以下命令: ```shell nohup hive --service hiveserver 10000 & ``` 4.如果需要在本地编写Java程序连接远程Hive服务器,可以使用以下示例程序: ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; public class Test { private static String driverName = "org.apache.hive.jdbc.HiveDriver"; private static String url = "jdbc:hive2://远程服务器ip:10000/default"; private static String user = "hive"; private static String password = ""; public static void main(String[] args) throws SQLException { try { Class.forName(driverName); } catch (ClassNotFoundException e) { e.printStackTrace(); System.exit(1); } Connection con = DriverManager.getConnection(url, user, password); Statement stmt = con.createStatement(); String tableName = "test"; stmt.execute("drop table if exists " + tableName); stmt.execute("create table " + tableName + " (key int, value string)"); System.out.println("Create table success!"); String sql = "show tables '" + tableName + "'"; System.out.println("Running: " + sql); ResultSet res = stmt.executeQuery(sql); if (res.next()) { System.out.println(res.getString(1)); } sql = "describe " + tableName; res = stmt.executeQuery(sql); while (res.next()) { System.out.println(res.getString(1) + "\t" + res.getString(2)); } sql = "select * from " + tableName; res = stmt.executeQuery(sql); while (res.next()) { System.out.println(String.valueOf(res.getInt(1)) + "\t" + res.getString(2)); } stmt.close(); con.close(); } } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值