[hadoop]hive的管理(十一)

来源:互联网 发布:51单片机指令集ppt 编辑:程序博客网 时间:2024/03/29 17:55
一、Hive的启动方式
  1. CLI(命令行)方式
    - 直接输入 #<HIVE_HOME>/bin/hive的执行程序
    - 或输入 #hive --service cli

    常用CLI命令
        - 清屏 Ctrl + L 或者 !clear
    查看数据仓库中的表
        - show tables;
    查看数据仓库中内置的函数
        - show functions;
    查看表结构
        - desc 表名
    查看HDFS上的文件
       -dfs -ls目录(递归查看 -lsr)
    执行linux命令
        -! 比如查看当前目录 !pwd;
    执行HQL语句
        - select * from *;
    执行SQL语句
        -source 比如 source /root/my.sql;
        my.sql文件内容:select * from test1;
    静默模式
        -hive -S (启动hive的命令)
    执行直接hive查询
        -hive [-S] -e 'select * from test1';

  2. Web界面方式
    - 端口号9999
    - 启动方式:#hive -service hwi &
    - 通过浏览器来访问:http://<IP地址>:9999/hwi/

    启动
    - 执行命令:hive --service hwi &
    发现报错:
    [root@node1 bin]# hive --service hwi &[1] 18292[root@node1 bin]# ls: 无法访问/home/hive/lib/hive-hwi-*.war: 没有那目录16/06/01 07:11:38 INFO hwi.HWIServer: HWI is starting up16/06/01 07:11:43 INFO mortbay.log: Logging to org.slf4j.impl.Log4pter(org.mortbay.log) via org.mortbay.log.Slf4jLog16/06/01 07:11:43 INFO mortbay.log: jetty-6.1.2616/06/01 07:11:45 INFO mortbay.log: Started SocketConnector@0.0.0
    原因是/hive-hwi-*.war包是不存在的,下面开始安装/hive-hwi-*.war包
    -需要apache-hive-1.2.1-src.tar.gz,并解压tar zxvf apache-hive-1.2.1-src.tar.gz
    -进入解压后目录cd apache-hive-1.2.1-src/hwi,执行命令:jar cvfM0 hive-hwi-1.2.1.war -C web/ .
    -拷贝到hive/lib目录,cp hive-hwi-1.2.1.war /home/hive/lib/
    -修改hive-site.xml配置文件,修改内容参考文档:https://cwiki.apache.org/confluence/display/Hive/HiveWebInterface
    <property>  <name>hive.hwi.listen.host</name>  <value>0.0.0.0</value>  <description>This is the host address the Hive Web Interface will listen on</description></property><property>  <name>hive.hwi.listen.port</name>  <value>9999</value>  <description>This is the port the Hive Web Interface will listen on</description></property><property>  <name>hive.hwi.war.file</name>  <value>lib/hive-hwi-1.2.1.war</value>  <description>This is the WAR file with the jsp content for Hive Web Interface</description></property>
    -拷贝/jdk中tool.jar包到hive/lib目录,命令:cp /usr/java/jdk1.7.0_79lib/tools.jar /home/hive/lib/
    -启动命令,hive --service hwi 显示下面代码表示启动成功
    [root@node1 home]# hive --service hwi16/06/01 09:39:21 INFO hwi.HWIServer: HWI is starting up16/06/01 09:39:25 INFO mortbay.log: Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog16/06/01 09:39:25 INFO mortbay.log: jetty-6.1.2616/06/01 09:39:26 INFO mortbay.log: Extract /home/hive/lib/hive-hwi-1.2.1.war to /tmp/Jetty_0_0_0_0_9999_hive.hwi.1.2.1.war__hwi__vrqy3t/webapp16/06/01 09:39:27 INFO mortbay.log: Started SocketConnector@0.0.0.0:9999
    访问web地址:http://node1:9999/hwi/,成功显示下面页面:




  3. 远程服务启动方式
    - 端口号10000
    -启动方式:#hive --service hiveserver
    -查看进程:netstat -nptl | grep 10000
    [root@node1 ~]# netstat -nptl | grep 10000tcp        0      0 0.0.0.0:10000           0.0.0.0:*               LISTEN      19928/java          [2]+  退出 255              hive --service hiveserver2
    -本地连接测试:bin/beeline
    [root@node1 bin]# ./beeline Beeline version 1.2.1 by Apache Hivebeeline> !connect jdbc:hive2://node1:10000Connecting to jdbc:hive2://node1:10000Enter username for jdbc:hive2://node1:10000: rootEnter password for jdbc:hive2://node1:10000: Connected to: Apache Hive (version 1.2.1)Driver: Hive JDBC (version 1.2.1)Transaction isolation: TRANSACTION_REPEATABLE_READ0: jdbc:hive2://node1:10000> use defdefault      deferrable   deferred 0: jdbc:hive2://node1:10000> show databases;OK+----------------+--+| database_name  |+----------------+--+| default        || hive           |+----------------+--+2 rows selected (2.837 seconds)



1 0
原创粉丝点击