Hive2.1.1集群搭建


軟件環境:

linux系統: CentOS6.7
Hadoop版本: 2.6.5
zookeeper版本: 3.4.8

##主機配置: ######一共m1, m2, m3這五部機, 每部主機的用戶名都為centos ``` 192.168.179.201: m1 192.168.179.202: m2 192.168.179.203: m3

m1: Zookeeper, Namenode, DataNode, ResourceManager, NodeManager, Master, Worker
m2: Zookeeper, Namenode, DataNode, ResourceManager, NodeManager, Worker
m3: Zookeeper, DataNode, NodeManager, Worker



---
<br>
##集群搭建 (注:Hive只需在一個節點上安裝)
####1.下載Hive2.1.1安裝包

http://www.apache.org/dyn/closer.cgi/hive/


---
####2.解壓

tar -zxvf hive-0.9.0.tar.gz -C /home/hadoop/soft


---
####3.配置環境變量

vi /etc/profile

Hive

export HIVE_HOME=/home/centos/soft/hive
export HIVE_CONF_DIR=$HIVE_HOME/conf
export CLASSPATH=$CLASSPATH:$HIVE_HOME/lib
export PATH=$PATH:$HIVE_HOMW/bin

source /etc/profile



---
####4.配置MySQL(注:切換到root用戶)
1. 卸載CentOS自帶的MySQL

rpm -qa | grep mysql

rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps

yum -y install mysql-server

2. 初始化MySQL
(1)修改mysql的密碼(```root```權限執行)

cd /usr/bin

./mysql_secure_installation

(2)輸入當前MySQL數據庫的密碼為``root``, 初始時root是沒有密碼的, 所以直接回車

Enter current password for root (enter for none):

(3)設置MySQL中``root``用戶的密碼(應與下面Hive配置一致,下面設置為```123456```)

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

(4)刪除匿名用戶

Remove anonymous users? [Y/n] Y
... Success!

(5)是否不允許用戶遠程連接,選擇``N``

Disallow root login remotely? [Y/n] N
... Success!

(6)刪除test數據庫

Remove test database and access to it? [Y/n] Y
Dropping test database...
... Success!
Removing privileges on test database...
... Success!

(7)重裝

Reload privilege tables now? [Y/n] Y
... Success!

(8)完成

All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

(9)登陸```mysql```

mysql -uroot -p

GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;
FLUSH PRIVILEGES;

exit;

<br>
**至此MySQL配置完成**





---
<br>
<br>
<br>
####5.配置Hive
####1. 編輯``hive-env.xml``文件
將```hive-env.sh.template```文件復制為```hive-env.sh```, 編輯``hive-env.xml``文件

JAVA_HOME=/home/centos/soft/jdk
HADOOP_HOME=/home/centos/soft/hadoop
HIVE_HOME=/home/centos/soft/hive
export HIVE_CONF_DIR=$HIVE_HOME/conf
export HIVE_AUX_JARS_PATH=$SPARK_HOME/lib/spark-assembly-1.6.0-hadoop2.6.0.jar
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib:$HADOOP_HOME/lib:$HIVE_HOME/lib
export HADOOP_OPTS="-Dorg.xerial.snappy.tempdir=/tmp -Dorg.xerial.snappy.lib.name=libsnappyjava.jnilib $HADOOP_OPTS"


---
<br>
####2. 編輯hive-site.xml文件
配置```hive-site.xml```文件, 將```hive-default.xml.template```文件拷貝為```hive-default.xml```, 並編輯```hive-site.xml```文件(刪除所有內容,只留一個```<configuration></configuration>```)

配置項參考:
hive.server2.thrift.port– TCP 的監聽端口,默認為10000。
hive.server2.thrift.bind.host– TCP綁定的主機,默認為localhost
hive.server2.thrift.min.worker.threads– 最小工作線程數,默認為5。
hive.server2.thrift.max.worker.threads – 最小工作線程數,默認為500。

hive.server2.transport.mode – 默認值為binary(TCP),可選值HTTP。
hive.server2.thrift.http.port– HTTP的監聽端口,默認值為10001。
hive.server2.thrift.http.path – 服務的端點名稱,默認為 cliservice。
hive.server2.thrift.http.min.worker.threads– 服務池中的最小工作線程,默認為5。
hive.server2.thrift.http.max.worker.threads– 服務池中的最小工作線程,默認為500。

javax.jdo.option.ConnectionURL jdbc:mysql://m1:3306/hive?createDatabaseIfNotExist=true JDBC connect string for a JDBC metastore javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver Driver class name for a JDBC metastore javax.jdo.option.ConnectionUserName root username to use against metastore database javax.jdo.option.ConnectionPassword 123 password to use against metastore database datanucleus.autoCreateSchema true datanucleus.autoCreateTables true datanucleus.autoCreateColumns true hive.metastore.warehouse.dir /hive location of default database for the warehouse hive.downloaded.resources.dir /home/centos/soft/hive/tmp/resources Temporary local directory for added resources in the remote file system. hive.exec.dynamic.partition true hive.exec.dynamic.partition.mode nonstrict hive.exec.local.scratchdir /home/centos/soft/hive/tmp/HiveJobsLog Local scratch space for Hive jobs hive.downloaded.resources.dir /home/centos/soft/hive/tmp/ResourcesLog Temporary local directory for added resources in the remote file system. hive.querylog.location /home/centos/soft/hive/tmp/HiveRunLog Location of Hive run time structured log file hive.server2.logging.operation.log.location /home/centos/soft/hive/tmp/OpertitionLog Top level directory where operation tmp are stored if logging functionality is enabled hive.hwi.war.file /home/centos/soft/hive/lib/hive-hwi-2.1.1.jar This sets the path to the HWI war file, relative to ${HIVE_HOME}. hive.hwi.listen.host m1 This is the host address the Hive Web Interface will listen on hive.hwi.listen.port 9999 This is the port the Hive Web Interface will listen on hive.server2.thrift.bind.host m1 hive.server2.thrift.port 10000 hive.server2.thrift.http.port 10001 hive.server2.thrift.http.path cliservice hive.server2.webui.host m1 hive.server2.webui.port 10002 hive.scratch.dir.permission 755 hive.aux.jars.path file:///home/centos/soft/spark/lib/spark-assembly-1.6.0-hadoop2.6.0.jar hive.server2.enable.doAs false hive.auto.convert.join false spark.dynamicAllocation.enabled true 動態分配資源 spark.driver.extraJavaOptions -XX:PermSize=128M -XX:MaxPermSize=512M ```
####3. 配置日志地址, 修改```hive-log4j.properties```文件 ``` cp hive-log4j.properties.template hive-log4j.properties ``` ``` vi hive-log4j.properties ``` ``` hive.log.dir=/home/centos/soft/hive/tmp ## 將hive.log日志的位置改為${HIVE_HOME}/tmp目錄下 ``` ``` mkdir ${HIVE_HOME}/tmp ```

####4. 配置hive-config.sh文件 配置```$HIVE_HOME/conf/hive-config.sh```文件 ``` ## 增加以下三行 export JAVA_HOME=/home/centos/soft/java export HIVE_HOME=/home/centos/soft/hive export HADOOP_HOME=/home/centos/soft/hadoop ## 修改下列該行 HIVE_CONF_DIR=$HIVE_HOME/conf ```

#####5. 拷貝JDBC包 將JDBC的jar包放入```$HIVE_HOME/lib```目錄下 ``` cp /home/centos/soft/tar.gz/mysql-connector-java-5.1.6-bin.jar /home/centos/soft/hive/lib/ ```

####6. 拷貝jline擴展包 將`$HIVE_HOME/lib`目錄下的`jline-2.12.jar`包拷貝到`$HADOOP_HOME/share/hadoop/yarn/lib`目錄下,並刪除`$HADOOP_HOME/share/hadoop/yarn/lib`目錄下舊版本的`jline`包

####7. 拷貝tools.jar包 復制```$JAVA_HOME/lib```目錄下的```tools.jar```到```$HIVE_HOME/lib```下 ``` cp $JAVA_HOME/lib/tools.jar ${HIVE_HOME}/lib ```

####8. 執行初始化```Hive```操作 選用`MySQLysql`和`Derby`二者之一為元數據庫 注意:先查看`MySQL`中是否有殘留的`Hive`元數據,若有,需先刪除 ``` schematool -dbType mysql -initSchema ## MySQL作為元數據庫 ``` 其中`mysql`表示用`mysql`做為存儲`hive`元數據的數據庫, 若不用`mysql`做為元數據庫, 則執行 ``` schematool -dbType derby -initSchema ## Derby作為元數據庫 ``` 腳本`hive-schema-1.2.1.mysql.sql`會在配置的`Hive`元數據庫中初始化創建表

####9.啟動Metastore服務 執行```Hive```前, 須先啟動```metastore```服務, 否則會報錯 ``` ./hive --service metastore ``` 然后打開另一個終端窗口,之后再啟動```Hive```進程

####10.測試 ``` hive ``` ``` show databases; show tables; create table book (id bigint, name string) row format delimited fields terminated by '\t'; select * from book; select count(*) from book; ```




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM