1、前提条件:
只需要选择一台服务器即可,这里选择安装在namenode上;安装用户为cloud-user
2、安装包:
sudo yum install -y hive hive-metastore hive-server2
3、安装mysql:
sudo yum install -y mysql-server
sudo service mysqld start
sudo yum install -y mysql-connector-java
sudo ln -s /usr/share/java/mysql-connector-java.jar /usr/lib/hive/lib/mysql-connector-java.jar
sudo /usr/bin/mysql_secure_installation (YYNYY)
创建数据库:
mysql -u root -p
Enter password:
mysql> CREATE DATABASE metastore;
mysql> USE metastore;
mysql> SOURCE /usr/lib/hive/scripts/metastore/upgrade/mysql/hive-schema-0.10.0.mysql.sql;
mysql> CREATE USER 'hive'@'10.0.0.2' IDENTIFIED BY 'mypassword';
mysql> REVOKE ALL PRIVILEGES, GRANT OPTION FROM 'hive'@'10.0.0.2';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,LOCK TABLES,EXECUTE ON metastore.* TO 'hive'@'10.0.0.2';
mysql> FLUSH PRIVILEGES;
mysql> quit;
4、配置hive-site.xml:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://10.0.0.2/metastore</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>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>mypassword</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>false</value>
</property>
<property>
<name>datanucleus.fixedDatastore</name>
<value>true</value>
</property>
<property>
<name>datanucleus.autoStartMechanism</name>
<value>SchemaTable</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://10.0.0.2:9083</value>
<description>IP address (or fully-qualified domain name) and port of the metastore host</description>
</property>
<property>
<name>hive.support.concurrency</name>
<description>Enable Hive's Table Lock Manager Service</description>
<value>true</value>
</property>
<property>
<name>hive.zookeeper.quorum</name>
<description>Zookeeper quorum used by Hive's Table Lock Manager</description>
<value>10.0.0.4,10.0.0.6,10.0.0.11</value>
</property>
<property>
<name>hive.zookeeper.client.port</name>
<value>2181</value>
<description>The port at which the clients will connect.</description>
</property>
<property>
<name>hive.server2.thrift.port</name>
<value>10001</value>
<description>TCP port number to listen on, default 10000</description>
</property>
<property>
<name>hive.aux.jars.path</name>
59 <value>file:////usr/lib/hbase/hbase.jar,file:///usr/lib/hive/lib/zookeeper.jar,file:///usr/lib/hive/lib/hive-hbase-handler-0.10.0-cdh4.6.0.jar,file:///usr/lib/hive/lib/guava-11.0.2.jar</value>
60 </property>
5、配置yarn:
export HADOOP_MAPRED_HOME=/usr/lib/hadoop-mapreduce
6、配置hdfs目录:
sudo -u hdfs hadoop fs -chmod 777 /user
sudo -u hdfs hadoop fs -mkdir /user/history
sudo -u hdfs hadoop fs -chmod -R 1777 /user/history
sudo -u hdfs hadoop fs -chown mapred:hadoop /user/history
sudo -u hdfs hadoop fs -mkdir /var/log/hadoop-yarn
sudo -u hdfs hadoop fs -chown yarn:mapred /var/log/hadoop-yarn
sudo -u hdfs hadoop fs -mkdir /tmp
sudo -u hdfs hadoop fs -chmod -R 1777 /tmp
sudo -u hdfs hadoop fs -mkdir /user/hive
sudo -u hdfs hadoop fs -mkdir /user/hive/warehouse
sudo -u hdfs hadoop fs -chown -R hive /user/hive
sudo -u hdfs hadoop fs -chmod -R 1777 /user/hive/warehouse
sudo -u hdfs hadoop fs -mkdir /user/hive/warehouse
sudo -u hdfs hadoop fs -chown -R hive /user/hive
sudo -u hdfs hadoop fs -chmod -R 1777 /user/hive/warehouse
sudo -u hdfs hadoop fs -mkdir /tmp/hadoop-mapred
sudo -u hdfs hadoop fs -mkdir /tmp/hive-hive
sudo -u hdfs hadoop fs -chmod -R 777 /tmp/hadoop-mapred
sudo -u hdfs hadoop fs -chmod -R 777 /tmp/hive-hive
sudo -u hdfs hadoop fs -chmod -R 777 /tmp/hive-hive
sudo chown -R hive:hive /var/lib/hive/.hivehistory
sudo -u hdfs hadoop fs -mkdir /user/cloud-user
sudo -u hdfs hadoop fs -chown cloud-user:cloud-user /user/cloud-user
7、服务启动:
sudo service hive-metastore start
sudo service hive-server2 start
8、测试:
sudo /usr/lib/hive/bin/beeline
beeline> !connect jdbc:hive2://10.0.0.2:10001 hive mypassword org.apache.hive.jdbc.HiveDriver
0: jdbc:hive2://10.0.0.2:10001> SHOW TABLES;
show tables;
+-----------+
| tab_name |
+-----------+
+-----------+
No rows selected (0.238 seconds)
0: jdbc:hive2://10.0.0.2:10001>!quit