Hive能作什麼?html
爲何要使用Hive?java
Hive與傳統數據庫對比mysql
Hive | RDBMS | |
查詢語言 | HQL | SQL |
數據存儲 | HDFS | Raw Device or Local FS |
執行 | MapReduce | Excutor |
執行延遲 | 高 | 低 |
處理數據規模 | 大 | 小 |
數據類型 | 所有數據(歷史和在線---分析) | 在線數據 |
冗餘程度 | 高冗餘 | 低冗餘(經過範式) |
... | ... | ... |
... | ... | ...sql |
Hive的架構數據庫
Hive相關概念apache
protectedList<Operator<?extendsSerializable>>childOperators; protectedList<Operator<?extendsSerializable>>parentOperators; protectedbooleandone;// 初始化值爲false
Hive的三種模式瀏覽器
1.本地 derby 這種方式是最簡單的存儲方式,只須要在 hive-site.xml 作以下配置即可 <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:derby:;databaseName=metastore_db;create=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>org.apache.derby.jdbc.EmbeddedDriver</value> </property> <property> <name>hive.metastore.local</name> <value>true</value> </property> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> </property> </configuration> 注:使用 derby 存儲方式時,運行 hive 會在當前目錄生成一個 derby 文件和一個 metastore_db 目錄。這種存儲方式的弊端是在同一個目錄下同時只能有一個 hive 客戶端能使用數據庫,不然會提示以下錯誤 [html] view plaincopyprint? hive> show tables; FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metast ore_db', see the next exception for details. NestedThrowables: java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask hive> show tables; FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metastore_db', see the next exception for details. NestedThrowables: java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details. FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask 2.本地 mysql 這種存儲方式須要在本地運行一個 mysql 服務器,並做以下配置(須要將 mysql 的驅動 jar 包拷貝到$HIVE_HOME/lib 目錄下)。 # /opt/hive-1.2.1/conf/hive-site.xml <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive_remote/warehouse</value> </property> <property> <name>hive.metastore.local</name> <value>true</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost/hive_remote?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>password</value> </property> </configuration> 附: 安裝 mysql Yum install mysql-server -y 啓動服務 service mysqld start mysql 修改 mysql 權限: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION; flush privileges; delete from user where Host != '%'; 刪除多餘會對權限形成影響的數據刷新權限 [ERROR] Terminal initialization failed; falling back to unsupported java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected at jline.TerminalFactory.create(TerminalFactory.java:101) 錯誤的緣由: Hadoop jline 版本和 hive 的 jline 不一致 3.遠端 mysql 3.1.remote 一體 這種存儲方式須要在遠端服務器運行一個 mysql 服務器,而且須要在 Hive 服務器啓動 meta 服務。 這裏用 mysql 的測試服務器,ip 位 192.168.1.214,新建 hive_remote 數據庫,字符集位 latine1 <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.57.6:3306/hive?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>hive</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>password</value> </property> <property> <name>hive.metastore.local</name> <value>false</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://192.168.1.188:9083</value> </property> </configuration> 注:這裏把 hive 的服務端和客戶端都放在同一臺服務器上了。服務端和客戶端能夠拆開, 3.2.Remote 分開 將 hive-site.xml 配置文件拆爲以下兩部分 -服務端配置文件 啓動:hive --service metastore <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> </property> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.57.6:3306/hive?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> </property> </configuration> -客戶端配置文件 啓動:hive <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>hive.metastore.warehouse.dir</name> <value>/user/hive/warehouse</value> </property> <property> <name>hive.metastore.local</name> <value>false</value> <property> <name>hive.metastore.uris</name> <value>thrift://slave2:9083</value> </property> </configuration>