5.beeline的使用

beeline 的 使用

启动hiverserver2

$ hiveserver2

使用beeline连接hive

$ beeline -u jdbc:hive2://hdpcomprs:10000/db_comprs -n hadoop -p

这里写图片描述

参数解释:
-u:连接url,可以使用IP,也可以使用主机名,端口默认为10000
-n:连接的用户名(注:不是登录hive的用户名,是hive所在服务器登录用户名)
-p:密码,可以不用输入

可以使用如下命令来修改端口

hiveserver2 --hiveconf hive.server2.thrift.port=14000

如果不知道beeline怎么使用,可以使用如下命令来查看beeline的使用帮助

[hadoop@hdpcomprs ~]$ beeline --help
Usage: java org.apache.hive.cli.beeline.BeeLine 
   -u <database url>               the JDBC URL to connect to
   -r                              reconnect to last saved connect url (in conjunction with !save)
   -n <username>                   the username to connect as
   -p <password>                   the password to connect as
   -d <driver class>               the driver class to use
   -i <init file>                  script file for initialization
   -e <query>                      query that should be executed
   -f <exec file>                  script file that should be executed
   -w (or) --password-file <password file>  the password file to read password from
   --hiveconf property=value       Use value for given property
   --hivevar name=value            hive variable name and value
                                   This is Hive specific settings in which variables
                                   can be set at session level and referenced in Hive
                                   commands or queries.
   --property-file=<property-file> the file to read connection properties (url, driver, user, password) from
   --color=[true/false]            control whether color is used for display
   --showHeader=[true/false]       show column names in query results
   --headerInterval=ROWS;          the interval between which heades are displayed
   --fastConnect=[true/false]      skip building table/column list for tab-completion
   --autoCommit=[true/false]       enable/disable automatic transaction commit
   --verbose=[true/false]          show verbose error messages and debug info
   --showWarnings=[true/false]     display connection warnings
   --showDbInPrompt=[true/false]   display the current database name in the prompt
   --showNestedErrs=[true/false]   display nested errors
   --numberFormat=[pattern]        format numbers using DecimalFormat pattern
   --force=[true/false]            continue running script even after errors
   --maxWidth=MAXWIDTH             the maximum width of the terminal
   --maxColumnWidth=MAXCOLWIDTH    the maximum width to use when displaying columns
   --silent=[true/false]           be more silent
   --autosave=[true/false]         automatically save preferences
   --outputformat=[table/vertical/csv2/tsv2/dsv/csv/tsv]  format mode for result display
                                   Note that csv, and tsv are deprecated - use csv2, tsv2 instead
   --incremental=[true/false]      Defaults to false. When set to false, the entire result set
                                   is fetched and buffered before being displayed, yielding optimal
                                   display column sizing. When set to true, result rows are displayed
                                   immediately as they are fetched, yielding lower latency and
                                   memory usage at the price of extra display column padding.
                                   Setting --incremental=true is recommended if you encounter an OutOfMemory
                                   on the client side (due to the fetched result set size being large).
                                   Only applicable if --outputformat=table.
   --incrementalBufferRows=NUMROWS the number of rows to buffer when printing rows on stdout,
                                   defaults to 1000; only applicable if --incremental=true
                                   and --outputformat=table
   --truncateTable=[true/false]    truncate table column when it exceeds length
   --delimiterForDSV=DELIMITER     specify the delimiter for delimiter-separated values output format (default: |)
   --isolation=LEVEL               set the transaction isolation level
   --nullemptystring=[true/false]  set to true to get historic behavior of printing null as empty string
   --maxHistoryRows=MAXHISTORYROWS The maximum number of rows to store beeline history.
   --help                          display this message

   Example:
    1. Connect using simple authentication to HiveServer2 on localhost:10000
    $ beeline -u jdbc:hive2://localhost:10000 username password

    2. Connect using simple authentication to HiveServer2 on hs.local:10000 using -n for username and -p for password
    $ beeline -n username -p password -u jdbc:hive2://hs2.local:10012

    3. Connect using Kerberos authentication with hive/localhost@mydomain.com as HiveServer2 principal
    $ beeline -u "jdbc:hive2://hs2.local:10013/default;principal=hive/localhost@mydomain.com"

    4. Connect using SSL connection to HiveServer2 on localhost at 10000
    $ beeline "jdbc:hive2://localhost:10000/default;ssl=true;sslTrustStore=/usr/local/truststore;trustStorePassword=mytruststorepassword"

    5. Connect using LDAP authentication
    $ beeline -u jdbc:hive2://hs2.local:10013/default <ldap-username> <ldap-password>

如果使用beeline连接时报了如下错
hadoop is not allowed to impersonate hadoop (state=08S01,code=0)

原因:hiveserver2增加了权限控制,需要在hadoop的配置文件中配置
解决方法:在hadoop的core-site.xml中添加如下内容,然后重启hadoop,再使用beeline连接即可

配置

您可以使用属性 hadoop.proxyuser.$superuser.hosts 以及 hadoop.proxyuser.$superuser.组hadoop.proxyuser.$superuser.用户中的一个或两个来配置代理用户。

通过在核心站点.xml中指定如下,名为 super 的超级用户只能从 host1host2 进行连接,以模拟属于 group1group2 的用户

   <property>
     <name>hadoop.proxyuser.super.hosts</name>
     <value>host1,host2</value>
   </property>
   <property>
     <name>hadoop.proxyuser.super.groups</name>
     <value>group1,group2</value>
   </property>

如果这些配置不存在,则不允许模拟,并且连接将失败。

如果更喜欢更宽松的安全性,则可以使用通配符值 * 来允许来自任何主机或任何用户的模拟。例如,通过在核心站点.xml中指定如下,从任何主机访问名为 oozie 的用户可以模拟属于任何组的任何用户。

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

哈道普用户$superuser.主机接受 IP 地址列表、CIDR 格式的 IP 地址范围和/或主机名。例如,通过按如下方式指定,名为 super 的用户从 10.222.0.0-10.222.255.25510.113.221.221 范围内的主机访问可以模拟 user1user2

   <property>
     <name>hadoop.proxyuser.super.hosts</name>
     <value>10.222.0.0/16,10.113.221.221</value>
   </property>
   <property>
     <name>hadoop.proxyuser.super.users</name>
     <value>user1,user2</value>
   </property>

参考官网:
https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/Superusers.html

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

连接成功后,和执行hive后相同执行shell命令即可,如果想要退出连接使用 !q 或 !quit 命令

posted @ 2024-06-10 16:26  3088577529  阅读(110)  评论(0)    收藏  举报