目录
1.hive安装详细步骤
hive的安装
1 mysql数据 远程连接权限
1) mysql -uroot -proot (要把密码改为root 改密码方法:set password=PASSWORD ('root') ;
)
2) set global validate_password_policy=0;
3) set global validate_password_length=1; 这个两个设置以后 密码很简单不会报错
4) grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
5) flush privileges;
2 HDFS start-all.sh
3 hive 解压 配置 mysql的驱动包把 mysql-connector-java-5.1.39.jar 放到 /opt/apps/hive-3.1.2/lib下
(hive-3.1.2是改过名字的,改名为hive-3.1.2)
4 vi conf/hive-env.sh
export HADOOP_HOME=/opt/apps/hadoop-3.1.1/
export HIVE_CONF_DIR=/opt/apps/hive-3.1.2/conf5 vi hive-site.xml
<configuration>
<!-- 记录HIve中的元数据信息 记录在mysql中 -->
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://linux01:3306/hive?createDatabaseIfNotExist=true&useSSL=false</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<!-- mysql的用户名和密码 -->
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
</property><property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property><property>
<name>hive.exec.scratchdir</name>
<value>/user/hive/tmp</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/user/hive/log</value>
</property>
<!-- 客户端远程连接的端口 -->
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>0.0.0.0</value>
</property>
<property>
<name>hive.server2.webui.host</name>
<value>0.0.0.0</value>
</property>
<!-- hive服务的页面的端口 -->
<property>
<name>hive.server2.webui.port</name>
<value>10002</value>
</property>
<property>
<name>hive.server2.long.polling.timeout</name>
<value>5000</value>
</property>
<property>
<name>hive.server2.enable.doAs</name>
<value>true</value>
</property>
<property>
<name>datanucleus.autoCreateSchema</name>
<value>false</value>
</property>
<property>
<name>datanucleus.fixedDatastore</name>
<value>true</value>
</property><property>
<name>hive.execution.engine</name>
<value>mr</value>
</property>
<!-- 添加元数据服务配置 -->
<property>
<name>hive.metastore.local</name>
<value>false</value>
<description>controls whether to connect to remove metastore server or open a new metastore server in Hive Client JVM</description>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://linux01:9083</value>
</property>
</configuration>6 vi /opt/apps/hadoop-3.1.1/etc/hadoop/core-site.xml
<property>
<name>dfs.permissions.enabled</name>
<value>false</value>
</property><property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property><property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>7重启hadoop
stop-all.sh
start-all.sh
8 配置环境变量1)vi /etc/profile
2)G
4)source /etc/profile
9 初始化
bin/schematool -initSchema -dbType mysql配置环境变量后,可直接输入 schematool -initSchema -dbType mysql
10 开启元数据服务
hive --service metastore 前台启动*(此处命令最好不要复制,自己手打,有时候复制会报错)
hive --service metastore &
[root@linux01 ~]# netstat -nltp | grep 9083
tcp6 0 0 :::908311 启动测试(HDFS正常)
hive
2.远程连接hiveserver2
1.前台启动或后台启动
前台启动:hiveserver2
后台启动:hiveserver2 &
查看10000 端口是否使用(多等一些时间)
[root@linux01 ~]# netstat -nltp | grep 10000
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN 55020/java
2.进入beeline
1.beeline
[root@linux01 ~]# beeline
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apps/hive-2.3.1/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apps/hadoop-2.8.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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]
Beeline version 2.3.1 by Apache Hive
beeline> !connect jdbc:hive2://linux01:10000
Connecting to jdbc:hive2://linux01:10000
Enter username for jdbc:hive2://linux01:10000: root
Enter password for jdbc:hive2://linux01:10000: 回车
Connected to: Apache Hive (version 2.3.1)
Driver: Hive JDBC (version 2.3.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://linux01:10000> (不出的话,需要等待一定时间 ,再重新执行此块操作)
3.java中连接hiveserver2
1.创建Maven项目
2.在pom.xml文件中添加配置文件
<dependencies>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-jdbc</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
修改到本地配置