一.首先安装MYSQL。
在安装Hive前,先安装MySQL,以MySQL作为元数据库,默认的元数据库是内嵌的Derby,但因其有单会话限制,所以选用MySQL。
1.首先检查系统中是否已经安装了MySQL。
在终端输入:sudo netstat -tap | grep mysql
如果有反映,则表名已经安装,若没有,则显示没有。(我的这里是已经安装好的。。)
hadoop@master:~$ sudo netstat -tap | grep mysqltcp 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,
在终端输入:
sudo apt-get update
sudo apt-get install mysql-server mysql-client
注意: 在此安装过程中会让你输入root用户密码,按照要求输入即可。(输入密码)
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,地址链接: (hive-2.0.0)
2.下载完成后,将该压缩包解压在 /mysoftware (Ubuntu)目录下:
hadoop@master:/mysoftware$ lsapache-hive-2.0.0-bin hadoop-2.6.4 hbase-1.2.1 jdk1.7.0_80 zookeeper-3.4.8hadoop@master:/mysoftware$ mv apache-hive-2.0.0-bin/ hive-2.0.0hadoop@master:/mysoftware$ lshadoop-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$ lsbin examples lib NOTICE RELEASE_NOTES.txtconf hcatalog LICENSE README.txt scriptshadoop@master:/mysoftware/hive-2.0.0$ cd bin/hadoop@master:/mysoftware/hive-2.0.0/bin$ lsbeeline ext hive.cmd hive-config.sh hplsql metatoolbeeline.cmd hive hive-config.cmd hiveserver2 hplsql.cmd schematoolhadoop@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.44. 添加环境变量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$ lsbeeline hive hive-config.sh hplsql schematoolbeeline.cmd hive.cmd hive-config.sh~ hplsql.cmdext hive-config.cmd hiveserver2 metatoolhadoop@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$ lsbeeline-log4j2.properties.template hive-log4j2.properties.templatehive-default.xml.template ivysettings.xmlhive-env.sh.template llap-daemon-log4j2.properties.templatehive-exec-log4j2.properties.templatehadoop@master:/mysoftware/hive-2.0.0/conf$ cp hive-default.xml.template hive-site.xmlhadoop@master:/mysoftware/hive-2.0.0/conf$ lsbeeline-log4j2.properties.template hive-log4j2.properties.templatehive-default.xml.template hive-site.xmlhive-env.sh.template ivysettings.xmlhive-exec-log4j2.properties.template llap-daemon-log4j2.properties.templatehadoop@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/hiveSLF4J: 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.propertiesHive-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;OKtesthiveTime 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即可我的是已经删除了的,所以启动无误。