大數據與人工智能入門到放棄(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包的版本號不一致導致的;只要刪除其中一個低版本的刪除後,保留高版本的並且複製給對方即可。一般報錯信息都會提示哪個包有問題的。

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