hive安装,
Hive 2.1.0安装
环境
Hadoop2.6.4 jdk1.7
安装Hive
修改hadoop 配置文件 etc/hadoop/core-site.xml,加入如下配置项
<property>
<name>hadoop.proxyuser.hadoop.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.hadoop.groups</name>
<value>*</value>
</property>
1.上传到/home/Hadoop/software, 解压安装Hive:
tar -xzvf apache-hive-2.1.0-bin.tar.gz ##解压
ln -s apache-hive-2.1.0-bin hive ##创建软链接
2.设置 Hive环境变量。编辑 .bash_profile 文件, 在其中添加以下内容:
#cd
vi .bashrc
export HIVE_HOME=/home/hadoop/software/hive
export PATH=$PATH:$HIVE_HOME/bin
使环境变量生效:
. .bashrc
scp .bashrc slave1:~/
在slave1 . .bashrc
scp .bashrc slave2:~/
在slave2 . .bashrc
配置Hive
配置文件重命名。在运行 Hive 之前需要使用以下命令修改配置文件:
cd /home/hadoop/software/hive/conf
cp hive-env.sh.template hive-env.sh
cp hive-default.xml.template hive-site.xml
cp hive-log4j2.properties.template hive-log4j2.properties
cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
修改hive-env.sh
底部添加
export JAVA_HOME=/usr/java/jdk1.7.0_67/
export HADOOP_HOME=/home/hadoop/software/hadoop-2.6.4
export HIVE_HOME=/home/hadoop/software/hive
export HIVE_CONF_DIR=/home/hadoop/software/hive/conf
修改hive-site.xml。
/关键字 #查找
输入name的值,修改value的值
<property>
<name>hive.exec.scratchdir</name>
<value>/home/hadoop/software/hive/iotmpdir</value>
<description>HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.</description>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/home/hadoop/software/hive/iotmpdir</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/home/hadoop/software/hive/iotmpdir</value>
<description>Temporary local directory for added resources in the remote file system.</description>
</property>
<property>
<name>hive.querylog.location</name>
<value>/home/hadoop/software/hive/iotmpdir</value>
<description>Location of Hive run time structured log file</description>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/home/hadoop/software/hive/iotmpdir/operation_logs</value>
<description>Top level directory where operation logs are stored if logging functionality is enabled</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.6.252:3306/hive?=createDatabaseIfNotExsit=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
# 注意:192.168.6.252,mysql是安装在slave2上的
<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>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<!-- base hdfs path -->
<value>/user/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://slave1:9083</value>
</property>
拷贝驱动。
上传mysql驱动到/home/hadoop/software/hive/lib/
复制hive系统
$ scp -r apache-hive-2.1.0-bin slave1:~/software/
$ scp -r apache-hive-2.1.0-bin slave2:~/software/
scp .bashrc slave1:~/
scp .bashrc slave2:~/
分别在slave1,slave2上建hive的软链接
在slave2上。
这时候需要独立数据库,这里使用mysql
Mysql 安装(slave2里)
$su root
#yum install mysql-server -y
[root@slave2 mysql]# service mysqld start
通过命令mysql –u root 进入数据库
>create database hive;
>create user hive identified by '123456';
>grant all PRIVILEGES on *.* to hive@'%' identified by '123456';
>flush privileges;
在slave1上。
初始化数据库,生成元数据
cd /home/hadoop/software/hive/bin/
[hadoop@slave1 bin]$./schematool -initSchema -dbType mysql
在hdfs上创建hive.metastore.warehouse.dir目录,并修改权限
$[hadoop@master ~] hadoop fs -mkdir -p /user/hive/warehouse
$[hadoop@master ~] hadoop fs -chown -R hive:hive /user/hive
启动hive
在Slave1
启动命令
hive --service metastore
[hadoop@slave1 ~]$ hive --service metastore
效果图如下,此时是卡再这里,不往下进行
需要再xsheel另建一个slave1的连接 运行以下命令
查看是否成功启动,这里查如果没有结果,需要等待一会端口开启,之后再netstat
[hadoop@slave1 ~]$ netstat -nlpt | grep 9083
有端口通信,说明成功
等metastore启动成功以后在从master里面启动 hive-server
在Master中启动
[hadoop@master ~]$ hive --service hiveserver2
效果图如下,此时是卡再这里,不往下进行
需要再xsheel另建一个master的连接 运行以下命令
[hadoop@slave1 ~]$ netstat -nlpt | grep 10000
查看是否成功启动有端口通信,说明成功
Hive连接
[hadoop@master ~]$ hive
连接hive成功
hive常见的4种数据导入方式
(1)、从本地文件系统中导入数据到Hive表;
(2)、从HDFS上导入数据到Hive表;
(3)、从别的表中查询出相应的数据并导入到Hive表中;
(4)、在创建表的时候通过从别的表中查询出相应的记录并插入到所创建的表中。
8、在Hive中创建表,并将数据导入表中
创建表
create table users(id int, username string, sex int, nickname string) row format delimited fields terminated by ',';
从本地文件系统导入数据库到hive
load data local inpath '/home/hadoop/users.txt' overwrite into table users;
从hdfs导入数据到hive
load data inpath '/user/hive/users.txt' overwrite into table users;
/home/hadoop/users.txt表中的数据格式为:
1,zhangsan,1,张三
2,lisi,1,李四
当执行load data local inpath '/home/hadoop/users.txt' overwrite into table users后,/home/hadoop/users.txt里的数据就导入到了/user/hive/warehouse/users中去了。
load data local inpath 表示从本地文件系统选择导入文件
load data inpath 表示从hdfs上选择导入文件
overwrite into table users 表示数据会先清空表再插入
into table user 表示数据会插入到表
select * from users;
问题汇总
1.org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.security.authorize.AuthorizationException): User: hadoop is not allowed to impersonate hive 的问题
修改hadoop 配置文件 etc/hadoop/core-site.xml,加入如下配置项
1. <property>
2. <name>hadoop.proxyuser.hadoop.hosts</name>
3. <value>*</value>
4. </property>
5. <property>
6. <name>hadoop.proxyuser.hadoop.groups</name>
7. <value>*</value>
8. </property>
备注:
2.hadoop.proxyuser.XXX.hosts 与 hadoop.proxyuser.XXX.groups 中XXX为异常信息中User:* 中的用户名部分
1. <property>
2. <name>hadoop.proxyuser.xiaosi.hosts</name>
3. <value>*</value>
4. <description>The superuser can connect only from host1 and host2 to impersonate a user</description>
5. </property>
6. <property>
7. <name>hadoop.proxyuser.xiaosi.groups</name>
8. <value>*</value>
9. <description>Allow the superuser oozie to impersonate any members of the group group1 and group2</description>
10. </property>
3.java.net.ConnectException: Call From master/192.168.6.100 to master:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
解决:原因是没有启动hadoop集群.start-all.sh