要想使用Hive先要有hadoop集群的支持,使用本地把元数据存储在mysql中。
mysql要可以远程连接:
可以设置user表,把localhost改为%,所有可连接。记住删除root其他用户,不然可能会有影响
update user set host=‘%‘ where host=‘localhost‘;
Hive的安装部署:
1、解压tar文件
2、修改文件:
修改conf/下面的文件:
cp hive-env.sh.tempalte hive-env.sh
配置hive-env.sh文件:
1、配置HIVE_HOME路径
2、配置HIVE_CONF_DIR路径
在hdfs中新建
/user/hive/warehouse
/tmp 连个文件夹,并修改权限为同组可写
hdfs dfs -chmod g+w /tmp
hdfs dfs -chmod g+w /user/hive/warehouse
配置元数据到mysql中:
需要mysql的驱动jar包
cp mysql-connector-java-5.1.27-bin.jar /hive/bin
在hive/conf目录中创建一个hive-site.xml文件,更改红色部分:
<?xml version="1.0"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration><property><name>javax.jdo.option.ConnectionURL</name><value>jdbc:mysql://hadoop102:3306/metastore?createDatabaseIfNotExist=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>root</value><description>username to use against metastore database</description></property><property><name>javax.jdo.option.ConnectionPassword</name><value>root</value><description>password to use against metastore database</description></property><property><name>hive.cli.print.current.db</name><value>true</value> <description>Whether to include the current database in the Hive prompt.</description></property><property><name>hive.cli.print.header</name><value>false</value><description>Whether to print the names of the columns in query output.</description></property></configuration>
-------------------------------------
更改默认数据仓库位置:
hive默认的数据仓库位置在:/user/hive/warehouse路径下面, 在仓库目录下,没有对默认的数据库 default 创建文件夹。如果某张表属于 default数据库,直接在数据仓库目录下创建一个文件夹。
可以修改配置文件更改位置:红色部分,切记修改路径的权限为同组可写,配置文件hive-site.xml
<property><name>hive.metastore.warehouse.dir</name><value>/user/hive/warehouse</value><description>location of default database for the warehouse</description></property>
配置表头显示、数据显示:配置文件hive-site.xml
<property><name>hive.cli.print.header</name><value>true</value></property><property><name>hive.cli.print.current.db</name><value>true</value></property>
Hive运行日志配置:
Hive 的 log 默认存放在/tmp/hadoop/hive.log 目录下(当前用户名下)
修改 hive 的 log 存放日志到/opt/module/hive/logs
修改/opt/module/hive/conf/hive-log4j.properties.template 文件名称为 hive-log4j.properties
在 hive-log4j.properties 文件中修改 log 存放位置
hive.log.dir=/opt/module/hive/logs