229 lines
7.9 KiB
YAML
229 lines
7.9 KiB
YAML
- name: node_nums to ansible variable
|
||
set_fact: node_nums="{{groups.hbase|length}}"
|
||
|
||
- name: To terminate execution
|
||
fail:
|
||
msg: "hbase 集群最少需要配置3个节点,请修改configurations/hosts内对应IP列表。"
|
||
when: node_nums < '3'
|
||
|
||
- name: check jdk 1.8_73
|
||
shell: source /etc/profile && java -version 2>&1 | grep 1.8.0_73 | wc -l
|
||
ignore_errors: false
|
||
register: jdk_out
|
||
|
||
- name: To terminate execution
|
||
fail:
|
||
msg: "检测到目标集群内存在JDK未安装节点,请检查"
|
||
when: jdk_out.stdout != '2'
|
||
run_once: true
|
||
delegate_to: 127.0.0.1
|
||
|
||
- name: create hbase package path:{{ install_path }}
|
||
file:
|
||
state: directory
|
||
path: '{{ install_path }}'
|
||
|
||
- block:
|
||
- name: Check if the HBase service already exists
|
||
shell: source /etc/profile && jps -l | egrep "org.apache.hadoop.hbase.regionserver.HRegionServer|org.apache.hadoop.hbase.master.HMaster" | wc -l
|
||
register: check_out
|
||
- name: copy unload_hbase.sh to {{ install_path }}/
|
||
template:
|
||
src: 'unload_hbase.sh.j2'
|
||
dest: '{{ install_path }}/unload_hbase.sh'
|
||
force: true
|
||
mode: 0755
|
||
when: check_out.stdout >= '1'
|
||
- name: unload hbase
|
||
shell: cd {{ install_path }} && sh unload_hbase.sh
|
||
when: check_out.stdout >= '1'
|
||
- name: Ansible delete {{ install_path }}/unload_hbase.sh
|
||
file:
|
||
path: "{{ install_path }}/unload_hbase.sh"
|
||
state: absent
|
||
- name: Check if the HBase service already exists
|
||
shell: source /etc/profile && jps -l | egrep "org.apache.hadoop.hbase.regionserver.HRegionServer|org.apache.hadoop.hbase.master.HMaster" | wc -l
|
||
register: check_out
|
||
- name: To terminate execution
|
||
fail:
|
||
msg: "卸载失败,组件可能非本安装部署,请联系开发确认或手动卸载后继续安装"
|
||
run_once: true
|
||
delegate_to: 127.0.0.1
|
||
when: check_out.stdout >= '1'
|
||
when: (allowed_unload) == "yes"
|
||
|
||
- block:
|
||
- name: Check if the HBase service already exists
|
||
shell: source /etc/profile && jps -l | egrep "org.apache.hadoop.hbase.regionserver.HRegionServer|org.apache.hadoop.hbase.master.HMaster" | wc -l
|
||
register: check_out
|
||
- name: To terminate execution
|
||
fail:
|
||
msg: "检测到目标集群内已有HBase请检查IP是否正确或停止/卸载已启动的组件"
|
||
run_once: true
|
||
delegate_to: 127.0.0.1
|
||
when: check_out.stdout >= '1'
|
||
when: (allowed_unload) == "no"
|
||
|
||
- name: hadoop_ip to ansible variable
|
||
set_fact: hadoop_ip="{{groups.hadoop[0]}}"
|
||
|
||
- name: check hadoop datanode num ,If the service cannot ,Time out after 60 seconds
|
||
shell: source /etc/profile && hadoop dfsadmin -report | grep "Live datanodes" | grep -E -o "[0-9]"
|
||
async: 60
|
||
register: datanode_out
|
||
run_once: true
|
||
delegate_facts: true
|
||
delegate_to: "{{ hadoop_ip }}"
|
||
|
||
- name: check hadoop namenode num ,If the service cannot ,Time out after 60 seconds
|
||
shell: source /etc/profile && hadoop dfsadmin -report |grep 50010 | wc -l
|
||
async: 60
|
||
register: namenode_out
|
||
run_once: true
|
||
delegate_facts: true
|
||
delegate_to: "{{ hadoop_ip }}"
|
||
|
||
- fail:
|
||
msg: "Hadoop 服务节点启动检测异常,请检查服务或是否已做免密登录"
|
||
when: datanode_out.stdout <= '1' and namenode_out.stdout <= '1'
|
||
|
||
- name: get zookeeper_servers to ansible variable
|
||
set_fact: zookeeper_servers="{{groups.zookeeper[0]}}:2181,{{groups.zookeeper[1]}}:2181,{{groups.zookeeper[2]}}:2181"
|
||
when: '(groups.zookeeper|length) == 3'
|
||
|
||
- name: get zookeeper_servers to ansible variable
|
||
set_fact: zookeeper_servers="{{groups.zookeeper[0]}}:2181,{{groups.zookeeper[1]}}:2181,{{groups.zookeeper[2]}}:2181,{{groups.zookeeper[3]}}:2181,{{groups.zookeeper[4]}}:2181"
|
||
when: '(groups.zookeeper|length) >= 5'
|
||
|
||
#复制tar到目标服务器
|
||
- name: copy {{ hbase_version }}.tar.gz
|
||
copy:
|
||
src: '{{ package_path }}/{{ hbase_version }}.tar.gz'
|
||
dest: '{{ install_path }}/'
|
||
force: true
|
||
backup: yes
|
||
|
||
#解压tar
|
||
- name: unpack {{ hbase_version }}.tar.gz
|
||
unarchive:
|
||
src: '{{ hbase_version }}.tar.gz'
|
||
dest: '{{ install_path }}/'
|
||
|
||
#获取 regionservers 列表
|
||
- name: get regionservers to:{{ install_path }}/{{ hbase_version }}/conf/regionservers
|
||
shell: echo "{{ ansible_play_hosts_all }}" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+" > {{ install_path }}/{{ hbase_version }}/conf/regionservers
|
||
|
||
- name: get master_ip
|
||
shell: sed -n '1,1p' {{ install_path }}/{{ hbase_version }}/conf/regionservers
|
||
register: master_out
|
||
|
||
- name: master_ip to ansible variable
|
||
set_fact: master_ip="{{master_out.stdout}}"
|
||
|
||
- name: get slave1_ip
|
||
shell: sed -n '2,2p' {{ install_path }}/{{ hbase_version }}/conf/regionservers
|
||
register: slave1_out
|
||
|
||
- name: slave1_ip to ansible variable
|
||
set_fact: slave1_ip="{{slave1_out.stdout}}"
|
||
|
||
- name: get slave2_ip
|
||
shell: sed -n '3,3p' {{ install_path }}/{{ hbase_version }}/conf/regionservers
|
||
register: slave2_out
|
||
|
||
- name: slave2_ip to ansible variable
|
||
set_fact: slave2_ip="{{slave2_out.stdout}}"
|
||
|
||
- name: get regionservers to:{{ install_path }}/{{ hbase_version }}/conf/backup-masters
|
||
shell: "echo {{ slave1_ip }} > {{ install_path }}/{{ hbase_version }}/conf/backup-masters && echo {{ slave2_ip }} >> {{ install_path }}/{{ hbase_version }}/conf/backup-masters"
|
||
|
||
#拷贝hbase 配置文件
|
||
- name: copy hbase config files
|
||
template:
|
||
src: '{{ item.src }}'
|
||
dest: '{{ item.dest }}'
|
||
backup: yes
|
||
with_items:
|
||
- { src: 'hbase-env.sh.j2', dest: '{{ install_path }}/{{ hbase_version }}/conf/hbase-env.sh' }
|
||
- { src: 'hbase-site.xml.j2', dest: '{{ install_path }}/{{ hbase_version }}/conf/hbase-site.xml' }
|
||
|
||
#拷贝hbase hmaster守护脚本
|
||
- name: copy hbase Hmaster shell
|
||
template:
|
||
src: 'dae-hmaster.sh.j2'
|
||
dest: '{{ install_path }}/{{ hbase_version }}/bin/dae-hmaster.sh'
|
||
backup: yes
|
||
mode: 0755
|
||
run_once: true
|
||
delegate_facts: true
|
||
delegate_to: "{{ item.ip }}"
|
||
with_items:
|
||
- { ip: '{{ master_ip }}' }
|
||
- { ip: '{{ slave1_ip }}' }
|
||
- { ip: '{{ slave2_ip }}' }
|
||
|
||
#拷贝hbase hmaster开机自启
|
||
- name: copy hbase Hmaster keep
|
||
template:
|
||
src: 'keephbasemaster.j2'
|
||
dest: '/etc/init.d/keephbasemaster'
|
||
backup: yes
|
||
mode: 0755
|
||
run_once: true
|
||
delegate_facts: true
|
||
delegate_to: "{{ item.ip }}"
|
||
with_items:
|
||
- { ip: '{{ master_ip }}' }
|
||
- { ip: '{{ slave1_ip }}' }
|
||
- { ip: '{{ slave2_ip }}' }
|
||
|
||
#拷贝hbase region 守护进程和开机自启
|
||
- name: copy hbase region files
|
||
template:
|
||
src: '{{ item.src }}'
|
||
dest: '{{ item.dest }}'
|
||
mode: 0755
|
||
backup: yes
|
||
with_items:
|
||
- { src: 'dae-hregion.sh.j2', dest: '{{ install_path }}/{{ hbase_version }}/bin/dae-hregion.sh' }
|
||
- { src: 'keephbaseregion.j2', dest: '/etc/init.d/keephbaseregion' }
|
||
|
||
#拷贝hadoop配置文件到 hbase/conf
|
||
- name: copy hadoop-conf to {{ install_path }}/{{ hbase_version }}/conf/
|
||
shell: "scp root@{{ hadoop_ip }}:{{ install_path }}/hadoop-2.7.1/etc/hadoop/{{ item.filename }} {{ install_path }}/{{ hbase_version }}/conf/"
|
||
with_items:
|
||
- { filename: 'hdfs-site.xml' }
|
||
- { filename: 'core-site.xml' }
|
||
- { filename: 'yarn-site.xml' }
|
||
- { filename: 'mapred-site.xml.bak' }
|
||
|
||
#拷贝 设置环境变量脚本
|
||
- name: copy set_hbase_env.sh path:{{ install_path }}/{{ hbase_version }}/bin/
|
||
template:
|
||
src: 'set_hbase_env.sh.j2'
|
||
dest: '{{ install_path }}/{{ hbase_version }}/bin/set_hbase_env.sh'
|
||
mode: 0755
|
||
backup: yes
|
||
|
||
#配置环境变量
|
||
- name: set hbase env
|
||
shell: cd {{ install_path }}/{{ hbase_version }}/bin/ && sh set_hbase_env.sh
|
||
|
||
- name: start hbase master
|
||
shell: source /etc/profile && sh /etc/init.d/keephbasemaster 'start'
|
||
run_once: true
|
||
delegate_facts: true
|
||
delegate_to: "{{ item.ip }}"
|
||
with_items:
|
||
- { ip: '{{ master_ip }}' }
|
||
- { ip: '{{ slave1_ip }}' }
|
||
- { ip: '{{ slave2_ip }}' }
|
||
|
||
- name: start hbase region
|
||
shell: source /etc/profile && sh /etc/init.d/keephbaseregion 'start'
|
||
|
||
- name: Ansible delete {{ install_path }}/{{ hbase_version }}.tar.gz
|
||
file:
|
||
path: "{{ install_path }}/{{ hbase_version }}.tar.gz"
|
||
state: absent
|