一.首先安裝MYSQL。html
在安裝Hive前,先安裝MySQL,以MySQL做爲元數據庫,默認的元數據庫是內嵌的Derby,但因其有單會話限制,因此選用MySQL。java
1.首先檢查系統中是否已經安裝了MySQL。mysql
在終端輸入:sudo netstat -tap | grep mysql sql
若是有反映,則表名已經安裝,若沒有,則顯示沒有。(個人這裏是已經安裝好的。。)數據庫
hadoop@master:~$ sudo netstat -tap | grep mysql tcp 0 0 *:mysql *:* LISTEN 1357/mysqld tcp 0 0 master:mysql 192.168.226.1:53663 ESTABLISHED 1357/mysqld tcp 0 0 master:mysql 192.168.226.1:52512 ESTABLISHED 1357/mysqld hadoop@master:~$
2.若沒有安裝,則開始安裝MySql,apache
在終端輸入:tcp
sudo apt-get updateide
sudo apt-get install mysql-server mysql-clientoop
注意: 在此安裝過程當中會讓你輸入root用戶密碼,按照要求輸入便可。(輸入密碼)spa
3. 可在終端如步驟1那樣檢測mysql的安裝,也可在終端輸入:
mysql -u root -p 而後輸入正確密碼。
4.在建立一個hive用戶,以下:
create user 'hive'@'%' identified by 'xujun';
5. 而後在mysql>這裏輸入:(賦予權限)
grant all on *.* to username@'%' identified by 'password;
注意:username是用戶名,password是要本身填寫的一個名字,例如:
grant all on *.* to hive@'%' identified by 'xujun';
flush privileges;
二:安裝Hive,以下:
1.官網下載Hive,地址連接:http://mirrors.hust.edu.cn/apache/hive/ (hive-2.0.0)
2.下載完成後,將該壓縮包解壓在 /mysoftware (Ubuntu)目錄下:
hadoop@master:/mysoftware$ ls apache-hive-2.0.0-bin hadoop-2.6.4 hbase-1.2.1 jdk1.7.0_80 zookeeper-3.4.8 hadoop@master:/mysoftware$ mv apache-hive-2.0.0-bin/ hive-2.0.0 hadoop@master:/mysoftware$ ls hadoop-2.6.4 hbase-1.2.1 hive-2.0.0 jdk1.7.0_80 zookeeper-3.4.8
3.進入hive-2.0.0/bin目錄下,
hadoop@master:/mysoftware/hive-2.0.0$ ls bin examples lib NOTICE RELEASE_NOTES.txt conf hcatalog LICENSE README.txt scripts hadoop@master:/mysoftware/hive-2.0.0$ cd bin/ hadoop@master:/mysoftware/hive-2.0.0/bin$ ls beeline ext hive.cmd hive-config.sh hplsql metatool beeline.cmd hive hive-config.cmd hiveserver2 hplsql.cmd schematool hadoop@master:/mysoftware/hive-2.0.0/bin$ sudo gedit hive-config.sh
修改hive-config.sh文件中內容,即在末尾添加以下內容:
export JAVA_HOME=/mysoftware/jdk1.7.0_80
export HIVE_HOME=/mysoftware/hive-2.0.0
export HADOOP_HOME=/mysoftware/hadoop-2.6.4
4. 添加環境變量etc/profile,在末尾添加以下內容:
export HIVE_HOME=/mysoftware/hive-2.0.0
export PATH=$HIVE_HOME/bin:$PATH
5. 修改hive-site.xml文件,操做以下:
hadoop@master:/mysoftware/hive-2.0.0/bin$ ls beeline hive hive-config.sh hplsql schematool beeline.cmd hive.cmd hive-config.sh~ hplsql.cmd ext hive-config.cmd hiveserver2 metatool hadoop@master:/mysoftware/hive-2.0.0/bin$ cd .. hadoop@master:/mysoftware/hive-2.0.0$ cd conf/ hadoop@master:/mysoftware/hive-2.0.0/conf$ ls beeline-log4j2.properties.template hive-log4j2.properties.template hive-default.xml.template ivysettings.xml hive-env.sh.template llap-daemon-log4j2.properties.template hive-exec-log4j2.properties.template hadoop@master:/mysoftware/hive-2.0.0/conf$ cp hive-default.xml.template hive-site.xml hadoop@master:/mysoftware/hive-2.0.0/conf$ ls beeline-log4j2.properties.template hive-log4j2.properties.template hive-default.xml.template hive-site.xml hive-env.sh.template ivysettings.xml hive-exec-log4j2.properties.template llap-daemon-log4j2.properties.template hadoop@master:/mysoftware/hive-2.0.0/conf$ sudo gedit hive-site.xml
操做完畢後會發現多了一個hive-site.xml,裏面的<configuration></configuration>中配置了不少不少不少屬性值。我直接而後修改爲了以下的內容即:
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/hive?createDatabaseInfoNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>xujun</value>
<description>password to use against metastore database</description>
</property>
</configuration>
6.下載mysql-connector-java-5.5-bin.jar文件驅動包,並放到$HIVE_HOME/lib目錄下
7.啓動Hive: (注意:在啓動HIve服務前,須要先開啓Hadoop服務)
hadoop@master:/mysoftware/hive-2.0.0$ bin/hive SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/mysoftware/hive-2.0.0/lib/hive-jdbc-2.0.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/mysoftware/hive-2.0.0/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/mysoftware/hadoop-2.6.4/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Logging initialized using configuration in jar:file:/mysoftware/hive-2.0.0/lib/hive-common-2.0.0.jar!/hive-log4j2.properties Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. tez, spark) or using Hive 1.X releases. hive> show tables; OK testhive Time taken: 1.041 seconds, Fetched: 1 row(s) hive>
注意:若是出現如下Error:
[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)
at jline.TerminalFactory.get(TerminalFactory.java:158)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:229)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:221)
at jline.console.ConsoleReader.<init>(ConsoleReader.java:209)
at org.apache.hadoop.hive.cli.CliDriver.getConsoleReader(CliDriver.java:773)
at org.apache.hadoop.hive.cli.CliDriver.executeDriver(CliDriver.java:715)
at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:675)
at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:615)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
若是報錯了,解決辦法:進入到hadoop安裝目錄下的share/hadoop/yarn/lib 下刪除 jline的jar文件。再啓動hive便可
個人是已經刪除了的,因此啓動無誤。