大数据与人工智能入门到放弃(07 回顾篇 Hive单节点环境搭建与mysql)

记:

最近空闲时间都在刷算法题,所以没怎么更新,这次趁着周末,安排一波

搭建Hive需要先做什么?

用一台服务器作为mysql服务器,因为hive的元数据会存储在mysql中,所以下面就是选我的机器node2作为mysql服务。

在这台机器上安装mysql,输入命令yum install mysql-server即可。安装完成后输入mysql,会出现如图7-1,说明未启动mysql服务。输入service mysqld start这条启动命令即可。

图7-1

再次输入mysql进入数据库,这样进库是违背常规的,而且别的机器也访问不了,所以要对库进行一定的配置,以下是我进库之后的一波操作,说明一下,里面有一句grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;,grant是授权的意思,all privileges是所有权限的意思,第一个*是代表所有库,第二个*是代表所有表,root身份登录,%代表其他机器也可以访问,即是远程的意思,后面的操作是设置一个密码,密码为root。delete from user where host!='%';是删除了默认的免密登录方式。

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql>use mysql;
mysql>grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
mysql>delete from user where host!='%';
mysql>flush privileges;

准备好hive和mysql驱动包

这里我的hive为apache-hive-1.2.2-bin.tar.gz,mysql的驱动包在网上就可以随便找。

1)上传hive到机器master,进行解压,之后把名字改短,一波操作如图7-2.

图7-2

 2)配置hive环境变量,vi进入/etc/profile文件,在末尾编辑,编辑完成后source一下就OK了


export JAVA_HOME=/usr/java/jdk1.8.0_191
export HADOOP_HOME=/opt/xige/hadoop-2.7.5
export ZOOKEEPER_HOME=/opt/xige/zookeeper-3.4.12
export HIVE_HOME=/root/app/hive
PATH=$PATH:$JAVA_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$ZOOKEEPER_HOME/bin:$HIVE_HOME/bin

3)根据http://hive.apache.org/,修改hive配置文件,进入conf文件夹,改名字mv hive-default.xml.template hive-default.xml,完事之后进入这个文件,在命令模式下输入括号的内容(.,$-1d),目的是为了删除<configuration>标签里面的东西,删除是把光标放在<configuration>,然后再输入这条命令。所以hive-default.xml文件内容最后如下:

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?><!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<configuration>
    <property>
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive_remote/warehouse</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://node2/hive_remote?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>root</value>
    </property>
</configuration>

4)将mysql驱动包放到hive的lib目录下

5)之后就是启动zkServer.sh和hadoop集群,之后输入hive即可成功。

启动时有可能会报错,一般看报错信息,有可能时hadoop的share/hadoop/yarn/lib目录下的某些jar包的版本跟hive中lib目录下的jar包的版本号不一致导致的;只要删除其中一个低版本的删除后,保留高版本的并且复制给对方即可。一般报错信息都会提示哪个包有问题的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章