(八)使用Ansible搭建分佈式大數據基礎環境-Hive客戶端搭建

“使用Ansible搭建分佈式大數據基礎環境”系列文章完整包含了如何使用Ansible這一分佈式運維利器,來幫我們快速搭建Hadoop2/Spark2/Hive2/ZooKeeper3/Flink1.7/ElasticSearch5等一整套大數據解決方案。本篇是系列文章的第八篇-Hive2安裝篇。更多後續文章敬請關注後續文章。

(一)使用Ansible搭建分佈式大數據基礎環境-環境準備
(二)使用Ansible搭建分佈式大數據基礎環境-Ansible項目創建
(三)使用Ansible搭建分佈式大數據基礎環境-編寫第一個playbook
(四)使用Ansible搭建分佈式大數據基礎環境-Ansible常用Module介紹
(五)使用Ansible搭建分佈式大數據基礎環境-ZooKeeper集羣模式搭建
(六)使用Ansible搭建分佈式大數據基礎環境-Hadoop高可用集羣搭建
(七)使用Ansible搭建分佈式大數據基礎環境-MySQL安裝
(八)使用Ansible搭建分佈式大數據基礎環境-Hive客戶端搭建


Hive是圍繞Hadoop的數據倉庫解決方案,將用戶輸入的Hive SQL解析之後自動生成MapReduce/Spark任務然後丟給Hadoop/Spark運行,是的使用者無需編寫複雜的mapreduce代碼,從而極大降低了使用者使用Hadoop/Spark的使用成本。
本篇我們安裝的Hive版本是最新的hive-2.3.5

1. 安裝Hive cluster配置

Hive原則上客戶端安裝,沒有集羣的概念,所有任務都會提交到遠程Hadoop/Spark集羣運行,這裏我們打開前面的production/hosts文件,Hive:

[cluster]
master1
master2
slave1

#以下爲mysql單獨創建
[mysqlcluster]
master2

#以下爲hive單獨創建
[mysqlcluster]
master2

2. 準備templates/hive-site.xml,設置mysql鏈接串和賬號密碼(mysql賬號:Hive,密碼:自定義,賬號/密碼提前準備好)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://master2:3306/hive?createDatabaseIfNotExist=true&amp;useSSL=false</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>
        <value>hive</value>
        <description>username to use against metastore database</description>
    </property>

    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>Password Here</value>
        <description>password to use against metastore database</description>
    </property>
</configuration>

3. 準備files/mysql-connector-java-5.1.41.jar

4. 編寫tasks/main.yaml,完成安裝工作

# 參考資料:https://blog.csdn.net/JENREY/article/details/79807418
---
- name: Create Hive Data Directory
  file: path={{data_base}}/hive state=directory

- name: Download Hive file
  get_url: url='{{download_server}}/{{path}}/{{appname}}-{{version}}/{{filename}}-{{version}}{{versionextra}}.{{suffix}}' dest="{{download_base}}/{{filename}}-{{version}}.{{suffix}}" remote_src=yes
  register: download_result

- name: Check whether registered
  stat:
    path: "{{app_base}}/{{filename}}-{{version}}{{versionextra}}"
  register: node_files

- debug:
    msg: "{{node_files.stat.exists}}"

# extract
- name: Extract hive archive
  unarchive: dest={{app_base}} src='{{download_base}}/{{filename}}-{{version}}.{{suffix}}' remote_src=yes
  when: download_result.state == 'file' and node_files.stat.exists == False

- name: Add hive soft link
  file: src="{{app_base}}/{{filename}}-{{version}}{{versionextra}}" dest={{app_base}}/{{appname}} state=link

# Add env HIVE_HOME
- name: Add ENV HIVE_HOME
  become: yes
  lineinfile: dest=/etc/profile.d/app_bin.sh line="export HIVE_HOME={{app_base}}/{{appname}}"

- name: Export Hive PATH
  become: yes
  lineinfile: dest=/etc/profile.d/app_bin.sh line="export PATH=$PATH:$HIVE_HOME/bin"

# copy templates files in directory $HIVE_HOME/conf to file name without .template suffix which hive needs.
- name: Copy hive-default.xml
  copy: src="{{app_base}}/{{appname}}/conf/hive-default.xml.template" dest="{{app_base}}/{{appname}}/conf/hive-default.xml" mode=0755 remote_src=yes

# copy templates/hive-site.xml to remote $HIVE_HOME/conf
- name: Copy hive-site.xml
  template: src=hive-site.xml dest="{{app_base}}/{{appname}}/conf/hive-site.xml" mode=0755

- name: Copy log4j2.properties
  copy: src={{app_base}}/{{appname}}/conf/hive-log4j2.properties.template dest="{{app_base}}/{{appname}}/conf/hive-log4j2.properties" mode=0755 remote_src=yes

- name: Copy hive-env.sh
  copy: src={{app_base}}/{{appname}}/conf/hive-env.sh.template dest="{{app_base}}/{{appname}}/conf/hive-env.sh" mode=0755 remote_src=yes

# copy files/mysql-connector-java-5.1.41.jar to remote $HIVE_HOME/lib
- name: Add mysql connector
  copy: src=mysql-connector-java-5.1.41.jar dest="{{app_base}}/{{appname}}/lib/mysql-connector-java-5.1.41.jar" mode=0755

# 使用schematool腳本初始化在mysql中創建Hive元數據信息,以下task只能運行一次
#- name: InitSchema
#  shell: "source /etc/profile && schematool -dbType mysql -initSchema"

- name: Test shell
  shell: "which hive"
  register: whichhive

- debug:
    msg: "{{whichhive}}"

5.創建hive.yaml,並運行playbook

---
- hosts: hivecluster
  remote_user: hadoop

  roles:
    - hive

$] ansible-playbook -i production/hosts hive.yaml
PLAY [hivecluster] *****************************************************************************************************************************************************************************
TASK [Gathering Facts] *************************************************************************************************************************************************************************
ok: [master2]

TASK [hive : debug] ****************************************************************************************************************************************************************************
ok: [adcz-dev-dt-team-1.vm.elenet.me] => {
“msg”: {
“changed”: true,
“cmd”: “which hive”,
“delta”: “0:00:00.010706”,
“end”: “2019-07-09 15:36:56.237045”,
“failed”: false,
“rc”: 0,
“start”: “2019-07-09 15:36:56.226339”,
“stderr”: “”,
“stderr_lines”: [],
“stdout”: “/data/bigdata/app/hive/bin/hive”,
“stdout_lines”: [
“/data/bigdata/app/hive/bin/hive”
]
}
}
PLAY RECAP *************************************************************************************************************************************************************************************
master2 : ok=15 changed=1 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0

安裝成功!

參考文檔

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