Hive(八) Hive 运行方式
Hive 运行方式
1. 命令行方式 cli:控制台模式 !!
2. 脚本运行方式(实际生产环境中用最多)!!!
3. JDBC 方式:hiveserver2 !!!
4. web GUI 接口 (hwi、hue 等)
1 命令行方式 cli:控制台模式
与 hdfs 交互:(了解)
执行执行 dfs 命令
dfs –ls /; dfs -cat /user/hive_remote/warehouse/person/person01.txt; |
与 Linux 交互
!开头
!pwd; !ls /root; |
2 Hive 脚本运行方式:
[[email protected] ~]# hive --service cli --help usage: hive -d,--define <key=value> 定义变量 --database <databasename> Specify the database to use -e <quoted-query-string> 从命令行中输入 sql 预计 -f <filename> 从文件中执行 sql 语句。 -H,--help Print help information --hiveconf <property=value> Use value for given property --hivevar <key=value> Variable subsitution to apply to hive commands. e.g. --hivevar A=B -i <filename> 初始化的 sql 文件 -S,--silent 静默模式(不显示 ok 和 Time taken 提示信息) -v,--verbose Verbose mode (echo executed SQL to the console) |
hive -e "select * from person" hive -e "select * from person">he.log hive -S -e "select * from person">hse.log |
hive -f file
[[email protected] ~]# vim hive.sh hive -e "select * from person" [[email protected] ~]# chmod +x hive.sh [[email protected] ~]# ./hive.sh [[email protected] ~]# vim hivef.sh select * from person [[email protected] ~]# chmod +x hive.sh [[email protected] ~]# hive -f hivef.sh |
hive -i init.sql (进入 hive 命令模式)
[[email protected] ~]# vim init.sql select * from person; [[email protected] ~]# hive -i init.sql |
hive> source file (在 hive cli 中运行)
hive> source init.sql; |
3 Web GUI 接口 (hwi、hue 等)
web 界面安装:
1. 下载源码包 apache-hive-*-src.tar.gz
2. 打开 PowerShell
3. 进入到指定目录
cd D:\devsoft\src\apache-hive-1.2.1-src\hwi\web |
4. 打包:jar -cvf hive-hwi.war *
5. 将 hive-hwi.war 放在 node3 的$HIVE_HOME/lib/
6. 复制 tools.jar(在 jdk 的 lib 目录下)到 node3 的$HIVE_HOME/lib 下
[[email protected] ~]# cd /opt/hive-1.2.1/lib/ [[email protected] lib]# pwd /opt/hive-1.2.1/lib [[email protected] lib]# cp /usr/java/jdk1.8.0_221-amd64/lib/tools.jar ./ |
7. 修改 hive 配置文件 hive-site.xml 添加以下配置内容:
<property> <name>hive.hwi.listen.host</name> <value>0.0.0.0</value> </property> <property> <name>hive.hwi.listen.port</name> <value>9999</value> </property> <property> <name>hive.hwi.war.file</name> <value>lib/hive-hwi.war</value> </property> |
修改前记得备份一下该配置文件。
8. Ctrl+C 关闭
[[email protected] ~]# hive --service metastore Starting Hive Metastore Server |
9. 启动 hwi 服务(端口号 9999)
hive --service hwi
10. 浏览器通过以下链接来访问
http://node3:9999/hwi/
User 输入 test 或者 root(随便写),都可以验证成功。
11. 查看数据库、表相关信息
12. 查看