summaryrefslogtreecommitdiff
path: root/parcels/roles/components/druid/tasks/install_druid.yml
blob: f3cd61ec474ba8998fcd1b9716b5c0a145f82529 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
- name: node_nums to ansible variable
  set_fact: node_nums="{{groups.druid|length}}"

- name: To terminate execution
  fail:
    msg: "Druid 集群最少需要配置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: copy mysql to /usr/bin/
  copy:
    src: '../files/mysql'
    dest: '/usr/bin/'
    force: true

- name: change mode
  shell: chmod +x /usr/bin/mysql
  
- block:
    - name: Check if the Druid service already exists
      shell: ps -ef |grep "org.apache.druid.cli.Main server" | grep -v grep | grep -v json | wc -l
      register: check_out
    - name: copy unload_druid.sh to {{ install_path }}/
      template: 
        src: 'unload_druid.sh.j2'
        dest: '{{ install_path }}/unload_druid.sh'
        force: true
        mode: 0755
      when: check_out.stdout >= '1'
    - name: unload kafka
      shell: cd {{ install_path }} && sh unload_druid.sh
      when: check_out.stdout >= '1'
    - name: check if {{ mariadb_druid_database }} exist
      shell: mysql -s -uroot -p{{ galaxy_mariadb_pin }} -P3306 -h{{ gateway_keepalive_host }} -e "select count(1) from information_schema.schemata where schema_name='{{ mariadb_druid_database }}'" |grep 1|wc -l
      register: has_druid_out
      run_once: true
      delegate_facts: true
      delegate_to: "127.0.0.1"
    - name: check database
      shell: mysql -s -uroot -p{{ galaxy_mariadb_pin }} -P3306 -h{{ gateway_keepalive_host }} -e "drop database {{ mariadb_druid_database }};"
      run_once: true
      delegate_facts: true
      delegate_to: "127.0.0.1"	  
      when: has_druid_out.stdout == '1'	  
    - name: Ansible delete {{ install_path }}/unload_druid.sh
      file:
        path: "{{ install_path }}/unload_druid.sh"
        state: absent
    - name: Check if the Druid service already exists
      shell: ps -ef |grep "org.apache.druid.cli.Main server" | grep -v grep | grep -v json | 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 Druid service already exists
      shell: ps -ef |grep "org.apache.druid.cli.Main server" | grep -v grep | grep -v json | wc -l
      register: check_out
    - name: To terminate execution
      fail:
       msg: "检测到目标集群内已有Druid请检查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 if {{ mariadb_druid_database }} exist
#  shell: mysql -s -uroot -p{{ galaxy_mariadb_pin }} -P3306 -h{{ gateway_keepalive_host }} -e "select count(1) from information_schema.schemata where schema_name='{{ mariadb_druid_database }}'" |grep 1|wc -l
#  register: has_druid_out
#  run_once: true
#  delegate_facts: true
#  delegate_to: "127.0.0.1"

#- name: check database
#  fail:
#    msg: "mariadb已经存在Druid数据库,请确认删除后再次执行安装"
#  when: has_druid_out.stdout == '1'

- 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: create druid package path:{{ install_path }}
  file:
    state: directory
    path: '{{ install_path }}'

- 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'

- name: Create a new database with name {{ mariadb_druid_database }}
  shell: mysql -uroot -p{{ galaxy_mariadb_pin }} -P3306 -h{{ gateway_keepalive_host }} -e "create database {{ mariadb_druid_database }} default character set utf8mb4 collate utf8mb4_general_ci;"
  run_once: true
  delegate_facts: true
  delegate_to: "127.0.0.1"

#复制tar到目标服务器
- name: copy {{ druid_version }}.tar.gz
  copy: 
    src: '{{ package_path }}/{{ druid_version }}.tar.gz'
    dest: '{{ install_path }}/'
    force: true
    backup: yes
    
#解压tar
- name: unpack {{ druid_version }}.tar.gz
  unarchive: 
    src: '{{ druid_version }}.tar.gz'
    dest: '{{ install_path }}/'

#拷贝druid 配置文件
- name: copy druid config files
  template: 
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
    backup: yes
  with_items:
    - { src: 'common.runtime.properties.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/_common/common.runtime.properties' }
    - { src: 'log4j2.xml.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/_common/log4j2.xml' }
    - { src: 'broker_runtime.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/query/broker/runtime.properties' }
    - { src: 'historical_runtime.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/data/historical/runtime.properties' }
    - { src: 'historical_jvm.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/data/historical/jvm.config' }
    - { src: 'middleManager_runtime.properties.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/data/middleManager/runtime.properties' }
    - { src: 'coordinator_jvm.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/master/coordinator-overlord/jvm.config' }
    - { src: 'broker_jvm.j2', dest: '{{ install_path }}/{{ druid_version }}/conf/druid/cluster/query/broker/jvm.config' }

#拷贝hadoop配置文件到 druid/conf
- name: copy hadoop-conf to {{ install_path }}/{{ druid_version }}/conf/druid/cluster/_common/
  shell: "scp root@{{ hadoop_ip }}:{{ data_path }}/hadoop-2.7.1/etc/hadoop/{{ item.filename }} {{ install_path }}/{{ druid_version }}/conf/druid/cluster/_common/"
  with_items:
    - { filename: 'hdfs-site.xml' }
    - { filename: 'core-site.xml' }
    - { filename: 'yarn-site.xml' }
    - { filename: 'mapred-site.xml.bak' }

- name: master_ip to ansible variable
  set_fact: master_ip="{{groups.druid[0]}}"

- name: slave1_ip to ansible variable
  set_fact: slave1_ip="{{groups.druid[1]}}"
 
#拷贝druid 守护脚本/开机自启
- name: copy Druid all start guardian/keep shell
  template: 
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
    mode: 0755
    backup: yes
  with_items:
    - { src: 'dae-druid-all.sh.j2', dest: '{{ install_path }}/{{ druid_version }}/bin/dae-druid-all.sh' }
    - { src: 'keepdruidall.j2', dest: '/etc/init.d/keepdruidall' }	
  when: node_nums <= cluster_limit
 
#拷贝druid 配置文件
- name: copy Druid query node guardian/keep shell for {{ master_ip }}
  template: 
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
    mode: 0755
    backup: yes
  run_once: true
  delegate_facts: true
  delegate_to: "{{ master_ip }}"
  with_items:
    - { src: 'dae-druid-query.sh.j2', dest: '{{ install_path }}/{{ druid_version }}/bin/dae-druid-query.sh' }
    - { src: 'keepdruidquery.j2', dest: '/etc/init.d/keepdruidquery' }	
  when: node_nums > cluster_limit

#拷贝druid 配置文件
- name: copy Druid query node guardian/keep shell for {{ slave1_ip }}
  template: 
    src: '{{ item.src }}'
    dest: '{{ item.dest }}'
    mode: 0755
    backup: yes
  run_once: true
  delegate_facts: true
  delegate_to: "{{ slave1_ip }}"
  with_items:
    - { src: 'dae-druid-query.sh.j2', dest: '{{ install_path }}/{{ druid_version }}/bin/dae-druid-query.sh' }
    - { src: 'keepdruidquery.j2', dest: '/etc/init.d/keepdruidquery' }	
  when: node_nums > cluster_limit
  
#拷贝druid 配置文件
- name: copy Druid data node guardian shell 
  template: 
    src: 'dae-druid-data.sh.j2'
    dest: '{{ install_path }}/{{ druid_version }}/bin/dae-druid-data.sh'
    mode: 0755
    backup: yes
  when: node_nums > cluster_limit and inventory_hostname != '{{master_ip}}' and inventory_hostname != '{{slave1_ip}}'
  
#拷贝druid 配置文件
- name: copy Druid data node keep shell
  template: 
    src: 'keepdruiddata.j2'
    dest: '/etc/init.d/keepdruiddata'
    mode: 0755
    backup: yes
  when: node_nums > cluster_limit and inventory_hostname != '{{master_ip}}' and inventory_hostname != '{{slave1_ip}}'

#拷贝set_druid_env.sh
- name: copy set_druid_env.sh
  template: 
    src: 'set_druid_env.sh.j2'
    dest: '{{ install_path }}/{{ druid_version }}/bin/set_druid_env.sh'
    mode: 0755
    backup: yes   
  
#配置druid环境变量
- name: set druid env
  shell: sh {{ install_path }}/{{ druid_version }}/bin/set_druid_env.sh
  
#拷贝druid 配置文件
- name: start druid query node
  shell: source /etc/profile && sh /etc/init.d/keepdruidquery 'start'
  run_once: true
  delegate_facts: true
  delegate_to: "{{ item.ip }}"
  with_items:
    - { ip: '{{ master_ip }}' }
    - { ip: '{{ slave1_ip }}' }
  when: node_nums > cluster_limit
  
#拷贝druid 配置文件
- name: start druid data node
  shell: source /etc/profile && sh /etc/init.d/keepdruiddata 'start'
  when: node_nums > cluster_limit and inventory_hostname != '{{master_ip}}' and inventory_hostname != '{{slave1_ip}}'
  
#拷贝druid 配置文件
- name: start druid all node
  shell: source /etc/profile && sh /etc/init.d/keepdruidall 'start'
  when: node_nums <= cluster_limit
  
- name: Ansible delete {{ druid_version }}.tar.gz
  file:
    path: "{{ install_path }}/{{ druid_version }}.tar.gz"
    state: absent