hive的安装与配置 mysql安装 启动
三种模式
内嵌模式:元数据保持在内嵌的derby模式,只允许一个会话连接
本地独立模式:在本地安装Mysql,吧元数据放到mySql内
远程模式:元数据放置在远程的Mysql数据库
1、下载Hive安装包
http://hive.apache.org/downloads.html
2、将hive文件上传到HADOOP集群机器上,并解压
将文件上传到:/opt/
tar -zxvf apache-hive-1.2.1-bin.tar.gz -C /opt/
cd /opt
ln -s apache-hive-1.2.1-bin hive
(创建快捷方式)
3、配置环境变量,编辑/etc/profile
#set hive env
export HIVE_HOME=/opt/hive
export PATH=${HIVE_HOME}/bin:$PATH
#让环境变量生效
source /etc/profile
4、修改hive配置文件
进入配置文件的目录
cd /opt/hive/conf/
修改hive-env.sh文件
cp hive-env.sh.template hive-env.sh
将以下内容写入到hive-env.sh文件中
export JAVA_HOME=/export/servers/jdk
export HADOOP_HOME=/export/servers/hadoop
export HIVE_HOME=/opt/hive
修改log4j文件
cp hive-log4j.properties.template hive-log4j.properties
将EventCounter修改成org.apache.hadoop.log.metrics.EventCounter
#log4j.appender.EventCounter=org.apache.hadoop.hive.shims.HiveEventCounter
log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter
配置:
hive.log.dir=/usr/lib/hive/logs
并且创建该文件夹:sudo mkdir /usr/lib/hive/logs
配置远程登录模式
touch hive-site.xml
将以下信息写入到hive-site.xml文件中
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://h1:3306/hivedb?createDatabaseIfNotExist=true</value>
<description>the URL of the MySQL database,数据库安装的那台机器</description>
</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>
<description>用户名</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>root</value>
<description>密码</description>
</property>
</configuration>
5、安装mysql并配置hive数据库及权限
Step 1: Install and start MySQL if you have not
already done so
$ sudo yum install mysql-server
$ sudo yum install mysql
$ sudo service mysqld start
Step 2: Configure the MySQL Service and Connector
因为使用MySQL作为存储元数据的数据库,所以需要把连接MySQL的jar包放入或链接到$HIVE_HOME/lib目录下。
$ sudo yum install mysql-connector-java
$ ln -s /usr/share/java/mysql-connector-java.jar /usr/lib/hive/lib/mysql-connector-java.jar
To set the MySQL root password:
$ sudo /usr/bin/mysql_secure_installation
[...]
Enter current password for root (enter for none):
OK, successfully used password, moving on...
[...]
Set root password? [Y/n] y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
[...]
Disallow root login remotely? [Y/n] N
[...]
Remove test database and access to it [Y/n] Y
[...]
Reload privilege tables now? [Y/n] Y
All done!
To make sure the MySQL server starts at boot(设置mysql开机启动):
$ sudo /sbin/chkconfig mysqld on
$ sudo /sbin/chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
配置hive元数据库
mysql -u root -p
create database hivedb;
对hive元数据库进行赋权,开放远程连接,开放localhost连接
grant all privileges on *.* to root@"%" identified by "root" with grant option;
grant all privileges on *.* to root@"localhost" identified by "root" with grant option;
6、运行hive命令即可启动hive
sudo /opt/hive/bin/hive
在shell下可以进行sql操作,可以直接使用dfs命令查看hdfs文件(分号结束语句):
启动后进入mysql可以看大hive建立的meta表。
7、Hive thrift服务
启动方式,(假如是在hadoop01上):
启动为前台:bin/hiveserver2
启动为后台:nohup bin/hiveserver2 1>/var/log/hiveserver.log 2>/var/log/hiveserver.err &
启动成功后,可以在别的节点上用beeline去连接
方式(1)
hive/bin/beeline 回车,进入beeline的命令界面
输入命令连接hiveserver2
beeline> !connect jdbc:hive2://mini1:10000
(hadoop01是hiveserver2所启动的那台主机名,端口默认是10000)
方式(2)
或者启动就连接:
bin/beeline -u jdbc:hive2://mini1:10000 -n hadoop
附录1:如果报错Terminal initialization failed; falling back to unsupported
将/export/servers/hive/lib 里面的jline2.12替换了hadoop 中/export/servers/hadoop/hadoop-2.6.1/share/hadoop/yarn/lib/jline-0.09*.jar
启动hive的时候会加载hadoop的jar,包冲突时报错。
附录2:jdbc驱动类
附录3:异常信息
Logging initialized using configuration in jar:file:/export/servers/apache-hive-2.0.0-bin/lib/hive-common-2.0.0.jar!/hive-log4j2.properties
Exception in thread "main" java.lang.RuntimeException: 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)
处理方法:
schematool -dbType mysql -initSchema
常见问题:jar冲突,数据库密码未设置