Hive搭建
- 前提
需要安装hadoop和MySQL数据库
- 安装步骤
- 解压初始化环境变量
tar -zxvf apache-hive-2.3.4-bin.tar.gz -C /app/
export HIVE_HOME=/app/apache-hive-2.3.4-bin
export PATH=$PATH:$HIVE_HOME/bin - 将JDBC驱动移动到Hive的lib目录下
cp /app/softwares/mysql-connector-java-5.1.46.jar /app/apache-hive-2.3.4-bin/lib/
- 修改配置
# 设置hadoop的路径 vim hive-env.sh
HADOOP_HOME=/app/hadoop-2.7.5 - 新建hive-site.xml文件
<configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://hadoop01:3306/hive?createDatabaseIfNotExist=true</value> </property> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>root</value> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>123456</value> </property> <property> <name>hive.metastore.schema.verification</name> <value>false</value> </property> <property> <name>datanucleus.schema.autoCreateAll</name> <value>true</value> </property> <property> <name>hive.server2.thrift.bind.host</name> <value>master</value> </property> <property> <name>hive.metastore.uris</name> <value>thrift://master:9083</value> </property> </configuration>
- 启动hive,并启动hive serve2和metastore
schematool -dbType mysql -initSchema nohup hive --service metastore > /tmp/log/metastore.log 2>&1 &
nohup hiveserver2 > /tmp/log/hiveserver2.log 2>&1 &
- 启动
git clone git@github.com:big-data-europe/docker-hive.git cd docker_hive docker-compose up -d
# 进入容器
docker-compose exec hive-server bash - 自带的测试用例
create table pokes(foo int, bar string); load data local inpath '/opt/hive/examples/files/kv1.txt' overwrite into table pokes;
- Hive Cli常用参数设置
# cli查询时显示字段名称 set hive.cli.print.header=true
# cli显示当前数据库
set hive.cli.print.current.db=true
# 尽可能的使用本地模式(对于小数据量能提高效率)
set hive.exec.mode.local.auto=true
# 启用严格模式
set hive.mapred.mode=strict