1. 程式人生 > >hive完全分散式部署

hive完全分散式部署

前言

關於hadoop完全分散式部署,我在https://blog.csdn.net/zisefeizhu/article/details/84317520已經有詳細步驟

https://blog.csdn.net/zisefeizhu/article/details/84317520繼續部署hbase分散式

關於有關原理請關注這個大佬https://blog.csdn.net/ForgetThatNight/article/details/79632364

環境和此連結一致,在這連結出現的內容在此不在宣告https://www.cnblogs.com/edisonchou/p/4440107.html

關於hbase完全分散式部署,我在已經有詳細步驟

https://blog.csdn.net/zisefeizhu/article/details/84635440

本次所需軟體:apache-hive-2.3.4-bin.tar.gz    mysql-connector-java-5.1.46.zip

網盤分享:

連結:https://pan.baidu.com/s/1aZv8G-YucFfEf0KSN6xXng 
提取碼:h3a0 

環境檢查

[[email protected] hadoop]$ sbin/start-all.sh

[[email protected] lib]$ jps

2002 SecondaryNameNode

5726 Jps

1800 NameNode

2157 ResourceManager

注意

hdfs在啟動開始時會進入安全模式,這時檔案系統中的內容不允許修改也不允許刪除,直到安全模式結束。安全模式主要是為了系統啟動的時候檢查各個DataNode上資料塊的有效性,同時根據策略必要的複製或者刪除部分資料塊。執行期通過命令也可以進入安全模式。在實踐過程中,系統啟動的時候去修改和刪除檔案也會有安全模式不允許修改的出錯提示,只需要等待一會兒即可。

如 hadoop fs -mkdir -p /user/hive/warehouse

mkdir: Cannot create directory /user/hive/warehouse. Name node is in safe mo

解決

可以等待其自動退出安全模式,也可以使用手動命令來離開安全模式:

hadoop fs -mkdir -p /user/hive/warehouse

開始部署

以下操作在root下進行

安裝資料庫【在這裡我以最簡單的方式安裝】

因為Centos預設支援的資料庫是Mariadb,所以需求先解除安裝Mariadb

rpm -qa | grep maria*

解除安裝資料庫:

yum -y remove mari*

刪除資料庫檔案:

 rm -rf /var/lib/mysql/*

又因為Centos 7 預設沒有Mysql源 不過我在這裡給你提供了rpm源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-server
rpm -qi mysql-community-server
systemctl start mysqld.service  啟動資料庫
cat /var/log/mysqld.log|grep 'A temporary password'
mysql
mysqladmin -u root password '1'   設定資料庫密碼
mysql -u root -p
systemctl enable  mysqld.service

以下操作在hadoop使用者下進行

mysql - uroot -p 驗證普通使用者下也能登陸

rz 上傳 你下載的hive包到/home/hadoop 下

tar xf apache-hive-2.3.4-bin.tar.gz 解壓

ln -s apache-hive-2.3.4-bin hive 設定軟連結

設定環境變數

[[email protected] ~]$ vim ~/.bash_profile

#新增

#hive

export HIVE_HOME=/home/hadoop/hive

export PATH=$PATH:${HIVE_HOME}/bin

生效配置檔案

source ~/.bash_profile

檢視

hive --version

Hive 2.3.4

Git git://daijymacpro-2.local/Users/daijy/commit/hive -r 56acdd2120b9ce6790185c679223b8b5e884aaf2

Compiled by daijy on Wed Oct 31 14:20:50 PDT 2018

From source with checksum 9f2d17b212f3a05297ac7dd40b65bab0

對HIVE進行配置

建立hive庫並設定相應許可權

mysql -uroot -p

Enter password:

#建立hive資料庫,為下邊做準備

mysql> create database hive;

Query OK, 1 row affected (0.00 sec)

mysql> create user 'hive'@'hadoop01' identified by 'hive';

#授權,其中MASTER為本地主機名,已在hosts中做域名解析

mysql> grant all privileges on *.* to 'hive'@'hadoop01' identified by 'hive';

mysql> flush privileges;

Query OK, 0 rows affected (0.01 sec)

exit

對hive進行配置

進入[[email protected] ~]$ cd hive/conf/ 下 拷貝 hive-default.xml.template為 hive-site.xml

[[email protected] conf]$ cp hive-default.xml.template hive-site.xml

編輯hive-site.xml

[[email protected] conf]$ vim hive-site.xml

#更改hive-site.xml為以下內容

<?xml version="1.0"?>

<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<configuration>

<!--url-->

<property>

<name>javax.jdo.option.ConnectionURL</name>

<value>jdbc:mysql://hadoop01:3306/hive?createDatabaseIfNotExist=true</value>

<description>JDBC connect string for a JDBC metastore</description>

</property>

<!--mysql使用者名稱-->

<property>

<name>javax.jdo.option.ConnectionUserName</name>

<value>hive</value>

<description>username to use against metastore database</description>

</property>

<!--mysql中hive使用者密碼-->

<property>

<name>javax.jdo.option.ConnectionPassword</name>

<value>hive</value>

<description>password to use against metastore database</description>

</property>

<!--mysql驅動-->

<property>

<name>javax.jdo.option.ConnectionDriverName</name>

<value>com.mysql.jdbc.Driver</value>

</property>

<property

<name>hive.downloaded.resources.dir</name>

<value>/home/hadoop/hive/tmp/${hive.session.id}_resources</value>

</property>

編輯hive-env.sh

[[email protected] conf]$ cp hive-env.sh.template hive-env.sh

[[email protected] conf]$ vim hive-env.sh

#在文末新增,java,hadoop,hive環境變數

export JAVA_HOME=/home/hadoop/java

export HADOOP_HOME=/home/hadoop/hadoop

export HIVE_HOME=/home/hadoop/hive

將Mysql驅動包上床到lib目錄,並解壓,並刪除原有包,只保留mysql-connector-java-5.1.46-bin.jar

[[email protected] lib]$ ls | grep mysql-

mysql-connector-java-5.1.46-bin.jar

mysql-metadata-storage-0.9.2.jar

對資料庫進行初始化

[[email protected] lib]$ schematool -dbType mysql -initSchema

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/home/hadoop/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]

SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.7.7/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://localhost:3306/hive?createDatabaseIfNotExist=true

Metastore Connection Driver : com.mysql.jdbc.Driver

Metastore connection User: hive

Starting metastore schema initialization to 2.3.0

Initialization script hive-schema-2.3.0.mysql.sql

Initialization script completed

schemaTool completed

執行hive

[[email protected] ~]$ hive 【注意等待時間過長 但正常 原理自行百度】

SLF4J: Class path contains multiple SLF4J bindings.

SLF4J: Found binding in [jar:file:/home/hadoop/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/

SLF4J: Found binding in [jar:file:/home/hadoop/hadoop-2.7.7/share/hadoop/common/lib/slf4j-log4s]

SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.

SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]

Logging initialized using configuration in jar:file:/home/hadoop/hive/lib/hive-common-2.3.4.ja

Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider u using Hive 1.X releases.

hive>create database hive_2; 建立hive_2資料庫

OK 顯示OK 表明hive 在主節點配置完成

hive>show databases; 檢視建立的資料庫

hive> show databases;

OK

default

hive_2

Time taken: 18.034 seconds, Fetched: 2 row(s)

當然了也可以在瀏覽器檢視

 

Hive客戶端配置

把hive檔案複製到從節點

[[email protected] ~]$ scp -r hive [email protected]:/home/hadoop

[[email protected] ~]$ scp -r hive [email protected]:/home/hadoop

把環境變數複製到從節點

[[email protected] ~]$ scp ~/.bash_profile [email protected]2:~
[[email protected] ~]$ scp ~/.bash_profile [email protected]:~

在從節點生效環境變數

source ~/.bash_profile

修改從節點的hive-site-xml

#hadoop01為Hive伺服器主機名,hadoop02和hadoop03都需要修改

[[email protected] ~]$ vim hive/conf/hive-site.xml

<configuration>

<property>

<name>hive.metastore.uris</name>

<value>thrift://hadoop01:9083</value>

</property>

</configuration>

[[email protected] ~]$ vim hive/conf/hive-site.xml

<configuration>

<property>

<name>hive.metastore.uris</name>

<value>thrift://hadoop01:9083</value>

</property>

</configuration>

啟動Hive服務端

#在後臺啟動 不然一直出現資訊提示

[[email protected] ~]$ hive --service metastore &

檢視jps程序

[[email protected] hadoop]$ jps

2002 SecondaryNameNode

6021 Jps

4006 RunJar

1800 NameNode

2157 ResourceManager

 

OK 至此hive完全分散式部署完成