欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Mac上Hive安装配置

程序员文章站 2022-06-29 08:10:59
Mac上Hive安装配置 1、安装 下载hive,地址:http://mirror.bit.edu.cn/apache/hive/ 之前我配置了集群,tjt01、tjt02、tjt03,这里hive安装在tjt01机器上。 我下载的是“apache-hive-3.0.0-bin.tar.gz”,将h ......

mac上hive安装配置

 

1、安装

下载hive,地址:http://mirror.bit.edu.cn/apache/hive/
之前我配置了集群,tjt01、tjt02、tjt03,这里hive安装在tjt01机器上。
我下载的是“apache-hive-3.0.0-bin.tar.gz”,将hive 3.0版本上传到/opt目录,并解压到/usr/local下:
[root@tjt01 ~]# cd /opt
[root@tjt01 opt]# tar -zxvf apache-hive-3.0.0-bin.tar.gz -c /usr/local/

Mac上Hive安装配置

将目录重命名为hive目录:
[root@tjt01 opt]# cd /usr/local/
[root@tjt01 local]# mv apache-hive-3.0.0-bin hive
[root@tjt01 local]#
修改环境变量/etc/profile:
[root@tjt01 local]# vi /etc/profile

在profile文件中添加如下内容:

export hive_home=/usr/local/hive
export path=$path:$hive_home/bin

生效profile:

[root@tjt01 local]# vi /etc/profile
[root@tjt01 local]# source /etc/profile

执行 hive --version查看hive版本

[root@tjt01 local]# hive --version
slf4j: class path contains multiple slf4j bindings.
slf4j: found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/staticloggerbinder.class]
slf4j: found binding in [jar:file:/opt/hadoop-2.7.6/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]
hive 3.0.0
git git://vgargwork.local/users/vgarg/repos/hive.apache.master.latest -r ce61711a5fa54ab34fc74d86d521ecaeea6b072a
compiled by vgarg on fri may 18 11:38:33 pdt 2018
from source with checksum 81fcb93b608965ed7ac968bae1187fab
[root@tjt01 local]# 

Mac上Hive安装配置

2、安装mysql

我之前安装过了,mysql安装参考:

 启动mysql服务:

[root@tjt03 ~]# sudo service mysqld start

启动过程报错了下,简单解决如下:

[root@tjt03 ~]# /etc/init.d/mysqld start
starting mysqld (via systemctl):  job for mysqld.service failed because the control process exited with error code. see "systemctl status mysqld.service" and "journalctl -xe" for details.
                                                           [failed]
[root@tjt03 ~]# mkdir /var/run/mysqld/
[root@tjt03 ~]# chown mysql.mysql /var/run/mysqld/
[root@tjt03 ~]# sudo service mysqld start
starting mysqld (via systemctl):                           [  ok  ]
[root@tjt03 ~]# 

设置mysql开机启动:

[root@tjt03 ~]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
executing /sbin/chkconfig mysqld on
[root@tjt03 ~]# systemctl daemon-reload
[root@tjt03 ~]# 

Mac上Hive安装配置

3、配置

3.1 修改hive-site.xml

[root@tjt01 conf]# cd ~
[root@tjt01 ~]# cd /usr/local/hive/conf/
[root@tjt01 conf]# cp hive-default.xml.template hive-site.xml
[root@tjt01 conf]# vim hive-site.xml 

xml内容如下:

<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.connectionurl</name>
        <value>jdbc:mysql://172.16.114.132:3306/hive</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>tanjintao@520</value>
    </property>
    <property>
        <name>hive.metastore.schema.verification</name>
        <value>false</value>
    </property>
</configuration>

3.2 复制mysql的程序程序到hive/lib下

mysql-connector-java.jar

Mac上Hive安装配置

3.3 创建mysql下的hive数据库

mysql> create database hive;
query ok, 1 row affected (0.01 sec)
mysql>

3.4 在mysql中hive的schema创建

[root@tjt01 bin]# schematool -dbtype mysql -initschema
slf4j: class path contains multiple slf4j bindings.
slf4j: found binding in [jar:file:/usr/local/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/staticloggerbinder.class]
slf4j: found binding in [jar:file:/opt/hadoop-2.7.6/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]
metastore connection url:        jdbc:mysql://172.16.114.132:3306/hive
metastore connection driver :    com.mysql.jdbc.driver
metastore connection user:       root
starting metastore schema initialization to 3.0.0
initialization script hive-schema-3.0.0.mysql.sql


initialization script completed
schematool completed
[root@tjt01 bin]# 

4、测试

进入hive之前,开启hadoop,键入hive进入hive:

[root@tjt01 bin]# start-dfs.sh
starting namenodes on [tjt01]
tjt01: starting namenode, logging to /opt/hadoop-2.7.6/logs/hadoop-root-namenode-tjt01.out
tjt03: starting datanode, logging to /opt/hadoop-2.7.6/logs/hadoop-root-datanode-tjt03.out
tjt02: starting datanode, logging to /opt/hadoop-2.7.6/logs/hadoop-root-datanode-tjt02.out
tjt01: starting datanode, logging to /opt/hadoop-2.7.6/logs/hadoop-root-datanode-tjt01.out
starting secondary namenodes [tjt02]
tjt02: starting secondarynamenode, logging to /opt/hadoop-2.7.6/logs/hadoop-root-secondarynamenode-tjt02.out
[root@tjt01 bin]#hive

Mac上Hive安装配置

创建hive数据库:

hive> create database hive_1;
ok
time taken: 0.709 seconds
hive> show databases;
ok
default
hive_1
time taken: 0.238 seconds, fetched: 2 row(s)
hive> 

观察mysql下hive数据库的变化:

mysql> select * from dbs;

Mac上Hive安装配置

在hive_1下创建一个hive_01:

hive> use hive_1;
ok
time taken: 0.066 seconds
hive> create table hive_01 (id int, name string);
ok
time taken: 1.235 seconds
hive> 

再次观察mysql下hive数据库的变化:

mysql> select * from tbls;

Mac上Hive安装配置

 

到此为止,mac安装hive完美收官!