Hadoop叢集之Hive HA 安裝配置
Hive是基於Hadoop構建的一套資料倉庫分析系統,它提供了豐富的SQL查詢方式來分析儲存在Hadoop 分散式檔案系統中的資料。其在Hadoop的架構體系中承擔了一個SQL解析的過程,它提供了對外的入口來獲取使用者的指令然後對指令進行分析,解析出一個 MapReduce程式組成可執行計劃,並按照該計劃生成對應的MapReduce任務提交給Hadoop叢集處理,獲取最終的結果。元資料——如表模式 ——儲存在名為metastore的資料庫中。
1. 安裝mysql
① 解除安裝系統自帶的mysql相關安裝包,僅解除安裝mysql開頭的包
[[email protected] hadoop]# rpm -qa|grep mysql
mysql-libs-5.1.73-3.el6_5.x86_64
[[email protected] hadoop]# rpm
rpm rpmdb rpmquery rpmverify
rpm2cpio rpmdumpheader rpmsign
[[email protected] hadoop]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64
② 安裝依賴包
[[email protected] hadoop]#yum install gcc gcc-c++ ncurses-devel -y
③ 安裝cmake
下載cmake安裝包
[[email protected] cmake-2.8.12]$ tar zxvf cmake-2.8.12.tar.gz
[[email protected] cmake-2.8.12]$ cd cmake-2.8.12
[[email protected] cmake-2.8.12]$ ./bootstrap
[[email protected] hadoop]# make && make install
④ 建立mysql使用者的相應目錄
[[email protected] ~]# groupadd mysql;useradd -g mysql mysql
[[email protected] ~]# su - hadoop
[[email protected] cmake-2.8.12]$ mkdir -p /opt/mysql
[[email protected] cmake-2.8.12]$ mkdir -p /opt/mysql/data
[[email protected] cmake-2.8.12]$ mkdir -p /opt/mysql/log
⑤ 修改目錄許可權
[[email protected] ~]$ chmod +w /opt/hadoop/mysql-5.6.25
[[email protected] ~]$ chmod 756 /opt/hadoop/mysql-5.6.25/
⑥ 獲取MySQL安裝包並安裝
wget http://dev.mysql.com/get/downloads/mysql/mysql-5.6.25.tar.gz
[[email protected] hadoop]]$ tar zxvf mysql-5.6.25.tar.gz
[[email protected] hadoop]]$ cd mysql-5.6.25
[[email protected] hadoop]]$ mkdir data
[[email protected] mysql-5.6.25]$ cmake -DCMAKE_INSTALL_PREFIX=/opt/hadoop/mysql-5.6.25 -DMYSQL_UNIX_ADDR=/opt/hadoop/mysql-5.6.25/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/opt/hadoop/mysql-5.6.25/data/ -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1-DENABLE_DOWNLOADS=1
若提示cmake命名不能執行,之後執行如下即可
export PATH=/opt/hadoop/cmake-2.8.12/bin/:$PATH
[[email protected] mysql-5.6.25]# make && make install
注意
DMYSQL_UNIX_ADDR=/opt/hadoop/mysql-5.6.25/mysql.sock 必須目錄有寫的許可權,chmod 756 /opt/hadoop/mysql-5.6.25/
或者-DMYSQL_UNIX_ADDR=/tmp/mysql.sock 只需/tmp有寫的許可權即可 chmod 756 /tmp
Chown mysql:mysql /tmp 因此DMYSQL_UNIX_ADDR最好配置/tmp/mysql.scok
⑦ 建立軟連線
[[email protected] ~]# ln -s /opt/hadoop/mysql-5.6.25/libmysql/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
[[email protected] ~]# chown hadoop:hadoop /usr/lib/libmysqlclient.so.18
⑧ 修改配置檔案
[[email protected] mysql-5.6.25]# cp support-files/my-default.cnf /etc/my.cnf
[[email protected] mysql-5.6.25]# chown hadoop:hadoop /etc/my.cnf
[[email protected] mysql-5.6.25]$ vi /etc/my.cnf
datadir=/opt/hadoop/mysql-5.6.25/data
log-error=/opt/hadoop/mysql-5.6.25/mysql_error.log
pid-file=/opt/hadoop/mysql-5.6.25/data/mysql.pid
socket=/opt/hadoop/mysql-5.6.25/mysql.sock
user=mysql
⑨ 初始化資料庫
[[email protected] ~]$ chmod 756 /opt/hadoop/mysql-5.6.25/scripts/mysql_install_db
[[[email protected]]$/opt/hadoop/mysql-5.6.25/scripts/mysql_install_db --user=mysql --basedir=/opt/hadoop/mysql-5.6.25 --datadir=/opt/hadoop/mysql-5.6.25/data/ --defaults-file=/etc/my.cnf --basedir=/opt/hadoop/mysql-5.6.25
⑩ 建立啟動檔案
[[email protected] ~]# cp /opt/hadoop/mysql-5.6.25/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# chown hadoop:hadoop /etc/init.d/mysqld ;chmod 756 /etc/init.d/mysqld
[[email protected] mysql-5.6.25]# mysqld -uroot -h127.0.0.1 -p
bash: mysqld: command not found
解決方法如下:
ln -s /opt/hadoop/mysql-5.6.25/bin/mysql /usr/bin/mysql
11 啟動MySQL服務
[[email protected] mysql-5.6.25]# service mysqld start
Starting MySQL. SUCCESS!
chkconfig --level 2345 mysqld on
12 初始化密碼
[[email protected] ~]$ mysql -uroot -h127.0.0.1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.6.25 Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> set PASSWORD=PASSWORD('123456');
Query OK, 0 rows affected (0.00 sec)
13 建立Hive使用者
mysql> CREATE USER 'hive' IDENTIFIED BY 'hive';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES on *.* TO 'hive'@'masternode1' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
14 Hive使用者登入
[[email protected] ~]$ mysql -h masternode1 -uhive
mysql> set PASSWORD = PASSWORD('hive');
15 建立Hive資料庫
mysql> create database hive;
Query OK, 1 row affected (0.00 sec)
2. 解壓hive軟體包
[[email protected] hadoop]# tar -zxf apache-hive-2.0.0-bin.tar.gz
[[email protected] hadoop]# mv apache-hive-2.0.0-bin hive-2.0.0
① Hive環境變數設定
[[email protected] hadoop]# cat /etc/profile|tail
#set hive
export HIVE_HOME=/opt/hadoop/hive-2.0.0
export PATH=$PATH:$HIVE_HOME/bin
vi ~/.bash_profile
#set hive
export HIVE_HOME=/opt/hadoop/hive-2.0.0
export PATH=$PATH:$HIVE_HOME/bin
② 配置引數檔案
[[email protected] hadoop$cd hive-2.0.0/conf/
[[email protected] conf]$ cp hive-env.sh.template hive-env.sh
[[email protected] conf]$ vi hive-env.sh
export HADOOP_HOME=/opt/hadoop/hadoop-2.7.2
export HIVE_HOME=/opt/hadoop/hive-2.0.0
[[email protected] conf]$ cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
[[email protected] conf]$ cp hive-log4j2.properties.template hive-log4j2.properties
[[email protected] conf]$ cp hive-default.xml.template hive-site.xml
[[email protected] conf]# vi hive-site.xml
<configuration>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>hdfs://cluster-ha/hive/warehouse</value>
<description>location of default database for the warehouse</description>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>hdfs://cluster-ha/hive/scratchdir</value>
<description>Scratch space for Hive jobs</description>
</property>
<property>
<name>hive.querylog.location</name>
<value>/opt/hadoop/hive-2.0.0/logs</value>
<description>
Location of Hive run time structured log file
</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://masternode1:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<!--mysql資料庫使用者名稱-->
<value>hive</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<!--mysql資料庫密碼-->
<value>hive</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.exec.local.scratchdir</name>
<value>/opt/hadoop/hive-2.0.0/local/hive</value>
<description>Local scratch space for Hive jobs</description>
</property>
<property>
<name>hive.downloaded.resources.dir</name>
<value>/opt/hadoop/hive-2.0.0/local/${hive.session.id}_resources</value>
<description>Temporary local directory for added resources in theremote file system.</description>
</property>
<property>
<name>hive.server2.logging.operation.log.location</name>
<value>/opt/hadoop/hive-2.0.0/local/logs/operation_logs</value>
<description>Top leveldirectory where operation logs are stored if logging functionality isenabled</description>
</property>
<property>
<name>hive.hwi.war.file</name>
<value>lib/hive-hwi-2.0.1.war</value>
</property>
<property>
<name>hive.hwi.listen.host</name>
<value>192.168.237.231</value>
<description>This is the host address the Hive Web Interface will listen on</description>
</property>
<property>
<name>hive.hwi.listen.port</name>
<value>9999</value>
<description>This is the port the Hive Web Interface will listen on</description>
</property>
</configuration>
cp hive-exec-log4j.properties.template hive-exec-log4j.properties
vi hive-exec-log4j.properties
hive.log.dir=/opt/hadoop/hive-2.0.0/logs
log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter
cp hive-log4j.properties.template hive-log4j.properties
vi hive-log4j.properties
hive.log.dir=/opt/hadoop/hive-2.0.0/logs
log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter
③ 建立臨時目錄
[[email protected] conf]$ mkdir /opt/hadoop/hive-2.0.0/local/hive
[[email protected] hive-2.0.0]$ mkdir local
[[email protected] hive-2.0.0]$mkdir /opt/hadoop/hive-2.0.0/logs
[[email protected] ~$mkdir /opt/hadoop/hive-2.0.0/local/logs/operation_logs
④ 拷貝MySQL驅動檔案
下載地址:
wget http://ftp.nchu.edu.tw/Unix/Database/MySQL/Downloads/Connector-J/mysql-connector-java-5.1.36.tar.gz
[[email protected] conf]# cp /home/centos/mysql-connector-java-5.1.36.tar.gz /opt/hadoop/
[[email protected] conf]# cd /opt/hadoop/
[[email protected] hadoop]# tar zxvf mysql-connector-java-5.1.36.tar.gz
[[email protected] hadoop]# cd mysql-connector-java-5.1.36
[[email protected] mysql-connector-java-5.1.36]# ls
build.xml CHANGES COPYING docs mysql-connector-java-5.1.36-bin.jar README README.txt src
[[email protected] mysql-connector-java-5.1.36]# cp mysql-connector-java-5.1.36-bin.jar $HIVE_HOME/lib/
[[email protected] mysql-connector-java-5.1.36]# cd $HIVE_HOME/conf
⑤ 拷貝到其他機器上
[[email protected] hadoop]# for i in {31,32,33,34,35,36};do scp -r hive-2.0.0/ [email protected]$i:/opt/hadoop/ ; done
⑥ 配置7臺客戶端hive-site.xml
[[email protected] conf]# cat hive-site.xml
<configuration>
<property>
<name>hive.metastore.uris</name>
<value>thrift://masternode1:9083,thrift://masternode2:9083</value>
</property>
</configuration>
⑦ 初始化 db
[[email protected] bin]# schematool -initSchema -dbType mysql
Metastore connection URL: jdbc:mysql://slavenode1:3306/hive_local_meta?createDatabaseIfNotExist=true
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: hive
Starting metastore schema initialization to 2.0.0
Initialization script hive-schema-2.0.0.mysql.sql
Initialization script completed
schemaTool completed
檢查防火牆,不需要得話就關了防火牆,需要得話就把埠放開,比如9083,9000,9001,50070等然後測試,切換到hive主目錄,輸入一下命令
[[email protected] hive-2.0.0]# bin/hive --service metastore &
Starting Hive Metastore Server
⑧ 啟動hive
$HIVE_HOME/bin/hive
[[email protected] hadoop-2.7.2]# $HIVE_HOME/bin/hive
SLF4J: Class path contains multiple SLF4J bindings.
file:/opt/hadoop/hive-2.0.0/conf/hive-log4j2.properties
Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. tez, spark) or using Hive 1.X releases.
hive> show databases;
OK
hive> create table studentinfo (id int,name string, age int,tel string)
> row format delimited fields terminated by '\t'
> stored as textfile;
OK
Time taken: 0.439 seconds
hive> load data local inpath '/tmp/stdentInfo.txt' into table studentinfo;
Loading data to table default.studentinfo
OK
Time taken: 1.313 seconds
hive> select * from studentinfo;
OK
1 a 26 110
2 b 29 120
hive> show tables;
OK
studentinfo
Time taken: 1.008 seconds, Fetched: 1 row(s)
hive> create table tb(id int,name string);
OK
Time taken: 0.427 seconds
[email protected] bin]# hive --service hwi
[[email protected]slavenode1
~]$ /opt/hadoop/hive-2.0.0/bin/hive --service hwihive --service hwils: cannot access /opt/hadoop/hive-2.0.0/lib/hive-hwi-*.war: No such file or directory
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hadoop/hive-2.0.0/lib/hive-jdbc-2.0.0-standalone.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/hive-2.0.0/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/spark/lib/spark-assembly-1.6.1-hadoop2.6.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop/hadoop-2.7.2/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]
解決方法手動構建war包
注意:報錯誤的原因是,Hive目前的發行包裡沒有hwi的war包檔案,沒有這個war包就不能啟動hwi服務。
解決辦法:從原始碼手動build出這個war包,具體過程如第二步。
wget http://mirror.bit.edu.cn/apache/hive/hive-2.0.0/apache-hive-2.0.0-src.tar.gz
[[email protected] hive-2.0.0]$ tar xf apache-hive-2.0.0-src.tar.gz
[[email protected] hive-2.0.0]$ cd apache-hive-2.0.0-src
構建war包
[[email protected] hwi]$ jar cvfM0 hive-hwi-2.0.0.war -C web/ .
[[email protected] hive-2.0.0]$ cp hive-hwi-2.0.0.war /opt/hadoop/hive-2.0.0/lib/hive-hwi-2.0.0.war
[email protected]slavenode1 bin]# hive --service hwi
如有下報錯:Problem accessing /hwi/. Reason: Unable to find a javac compiler;com.sun.tools.javac.Main is not on the classpath.Perhaps JAVA_HOME does not point to the JDK.It is currently set to "/usr/java/jdk1.7.0_65/jre"
解決辦法:
cp /usr/java/jdk1.7.0_65/lib/tools.jar /opt/hadoop/hive-2.0.0/lib/
hive --service hwi 重啟即可。