一、安裝hadoop集群,這里準備兩臺hadoop服務器,hd01,hd02
二、安裝MySQL數據庫
三、下載hive安裝包2.1.1
http://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.1.1/apache-hive-2.1.1-bin.tar.gz
四、將安裝包上傳至hd01服務器 /data/tools目錄下,并解壓至/data/hive目錄中。
五、創(chuàng)建hadoop用戶,已創(chuàng)建忽略此步驟。
root操作:
useradd hadoop
passwd hadoop
六、修改hive目錄權限
root操作
cd /data
chown -R hadoop hive
六、設置hive環(huán)境變量
切換到hadoop用戶:
vi ~/.bash_profile
添加 HIVE_HOME=/data/hive
PATH=$JAVA_HOME/bin:$HIVE_HOME/bin:$PATH:$HOME/bin
export PATH JAVA_HOME HIVE_HOME
保存退出
source ~/.bash_profile使環(huán)境變量生效
七、修改hive配置文件
1)準備配置文件
cd /data/hive/conf
cp hive-env.sh.template hive-env.sh
cp hive-default.xml.template hive-site.xml
cp hive-log4j2.properties.template hive-log4j2.properties
cp hive-exec-log4j2.properties.template hive-exec-log4j2.properties
2)修改hive-env.sh,在末尾添加:
export JAVA_HOME=/data/jdk1.8
export HADOOP_HOME=/data/hadoop/hadoop-2.7.4
export HIVE_HOME=/data/hive
export HIVE_CONF_DIR=$HIVE_HOME/conf
3)修改hive-site.xml,找到以下對應的property修改其value值
hive.exec.scratchdir
/tmp/hive-${user.name}
HDFS root scratch dir for Hive jobs which gets created with write all (733) permission. For each connecting user, an HDFS scratch dir: ${hive.exec.scratchdir}/<username> is created, with ${hive.scratch.dir.permission}.
hive.exec.local.scratchdir
/tmp/${user.name}
Local scratch space for Hive jobs
hive.downloaded.resources.dir
/tmp/hive/resources
Temporary local directory for added resources in the remote file system.
hive.querylog.location
/tmp/${user.name}
Location of Hive run time structured log file
hive.server2.logging.operation.log.location
/tmp/${user.name}/operation_logs
Top level directory where operation logs are stored if logging functionality is enabled
4)修改hadoop配置core-site.xml,加入以下配置,開啟hive訪問hdfs權限:
其中,hadoop.proxyuser.hadoop.hosts,紅色字符為需要訪問hdfs的系統(tǒng)用戶。
hadoop.proxyuser.hadoop.hosts
*
hadoop.proxyuser.hadoop.groups
*
5)配置hive元數據存儲,hive默認使用derby內嵌數據庫,生產環(huán)境一般采用mysql數據庫
將 mysql-connector-java-5.1.43-bin.jar 放入 $HIVE_HOME/lib 下。
在hive-site.xml中配置如下信息:
javax.jdo.option.ConnectionURL
jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&characterEncoding=UTF-8&useSSL=false
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName
hive
javax.jdo.option.ConnectionPassword
hive
6)為hive創(chuàng)建hdfs目錄
在 Hive 中創(chuàng)建表之前需要使用以下 HDFS 命令創(chuàng)建 /tmp 和 /user/hive/warehouse (hive-site.xml 配置文件中屬性項 hive.metastore.warehouse.dir 的默認值) 目錄并給它們賦寫權限。
確保hadoop的hdfs服務已啟動。
進入hadoophome的bin目錄,cd /data/hadoop/hadoop-2.7.4/bin
依次執(zhí)行以下命令:
./hdfs dfs -mkdir /tmp
./hdfs dfs -mkdir -p /user/hive/warehouse
./hdfs dfs -chmod g+w /tmp
./hdfs dfs -chmod g+w /user/hive/warehouse
7)給mysql創(chuàng)建hive用戶
mysql -u root -p,登錄mysql
mysql> CREATE USER 'hive'@'localhost' IDENTIFIED BY "hive";
mysql> grant all privileges on *.* to hive@localhost identified by 'hive';
8)運行hive
初始化hive,執(zhí)行 schematool -dbType mysql -initSchema
執(zhí)行hive命令,進入命令行,輸入show tables測試服務
9)修改log配置文件,將log輸出到指定目錄
vi hive-log4j2.properties
10)由于hiveserver2沒有后臺運行的腳本,將以下腳本復制到bin目錄下,并賦予當前用戶執(zhí)行權限。
然后執(zhí)行 hiveserver2.sh start
metastore.sh start
11)瀏覽器打開hiveserver webui
http://192.168.76.128:10002