Install Hive2.1.0
1. Preparation: Install JDK, Hadoop
2. Download and unzip Hive
wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.1.0/apache-hive-2.1.0-bin.tar.gz cp apache-hive-2.1.0-bin.tar.gz /usr/local tar -zxvf apache-hive-2.1.0-bin.tar.gz mv apache-hive-2.1.0-bin.tar.gz hive sudo chown -R hadoop:hadoop hive
3. Set Hive environment variables
vi ~ / .bashrc export HIVE_HOME=/usr/local/hive export PATH=$JAVA_HOME/bin:$PATH:$HADOOP_HOME/bin:$HIVE_HOME/bin source ~/.bashrc
4. Modify the Hive configuration file
cp conf/hive-default.xml.template hive-site.xml cp conf/hive-log4j.properties.template hive-log4j.properties cp conf/hive-exec-log4j.properties.template hive-exec-log4j.properties
5. Modify hive-site.xml
<property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://192.168.53.94:3306/hive_db?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=UTF-8</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>root</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> <description>password to use against metastore database</description> </property>
6. Modify hive-site.xml to replace ${system:java.io.tmpdir} and ${system:user.name} with /home/hadoop/hive/tmp/, otherwise the following error will be reported
Logging initialized using configuration in file:/usr/local/hive/conf/hive-log4j2.properties Async: true Exception in thread "main" java.lang.IllegalArgumentException: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D at org.apache.hadoop.fs.Path.initialize(Path.java:205) at org.apache.hadoop.fs.Path.<init>(Path.java:171) at org.apache.hadoop.hive.ql.session.SessionState.createSessionDirs(SessionState.java:631) at org.apache.hadoop.hive.ql.session.SessionState.start(SessionState.java:550) at org.apache.hadoop.hive.ql.session.SessionState.beginStart(SessionState.java:518) at org.apache.hadoop.hive.cli.CliDriver.run(CliDriver.java:705) at org.apache.hadoop.hive.cli.CliDriver.main(CliDriver.java:641) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.hadoop.util.RunJar.run(RunJar.java:221) at org.apache.hadoop.util.RunJar.main(RunJar.java:136) Caused by: java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7Bsystem:user.name%7D at java.net.URI.checkPath(URI.java:1823) at java.net.URI.<init>(URI.java:745) at org.apache.hadoop.fs.Path.initialize(Path.java:202) ... 12 more
7. Create a corresponding Mysql account for Hive and grant sufficient permissions
CREATE USER 'hive' IDENTIFIED BY '123456'; GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' WITH GRANT OPTION; flush privileges;
8. Put mysql-connector-java-5.1.30-bin.jar under $HIVE_HOME/lib
9. Start Hive
./bin/hive
10. Start Hive and report an error (if not, please ignore it)
Caused by: MetaException(message:Hive metastore database is not initialized. Please use schematool (e.g. ./schematool -initSchema -dbType ...) to create the schema. If needed, don't forget to include the option to auto-create the underlying database in your JDBC connection string (e.g. ?createDatabaseIfNotExist=true for mysql)) This is because the Hive metadata database is not initialized. By default, Hive metadata is stored in the embedded derby database. Execute the following command to ./bin/schematool -initSchema -dbType derby
11. Test Hive
create table table_name ( id int, dtDontQuery string, name string ); show tables;