Skip to content

Commit ec40f6d

Browse files
committed
🚧 Ansible
1 parent 6b01f97 commit ec40f6d

File tree

2 files changed

+96
-12
lines changed

2 files changed

+96
-12
lines changed

markdown-file/Ansible-Install-And-Settings.md

Lines changed: 95 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,55 @@ PLAY RECAP *********************************************************************
168168

169169
## 更多 playbook 实战
170170

171+
172+
#### 禁用防火墙(CentOS 7.x)
173+
174+
175+
- 创建脚本文件:`vim /opt/disable-firewalld-playbook.yml`
176+
177+
```
178+
- hosts: all
179+
remote_user: root
180+
tasks:
181+
- name: Disable SELinux at next reboot
182+
selinux:
183+
state: disabled
184+
- name: disable firewalld
185+
command: "{{ item }}"
186+
with_items:
187+
- systemctl stop firewalld
188+
- systemctl disable firewalld
189+
- setenforce 0
190+
```
191+
192+
193+
- 执行命令:`ansible-playbook /opt/disable-firewalld-playbook.yml`
194+
195+
#### 修改 hosts
196+
197+
198+
- 创建脚本文件:`vim /opt/hosts-playbook.yml`
199+
200+
```
201+
- hosts: all
202+
remote_user: root
203+
tasks:
204+
- name: update hosts
205+
blockinfile:
206+
path: /etc/hosts
207+
block: |
208+
192.168.0.223 linux01
209+
192.168.0.223 linux02
210+
192.168.0.223 linux03
211+
192.168.0.223 linux04
212+
192.168.0.223 linux05
213+
```
214+
215+
216+
- 执行命令:`ansible-playbook /opt/hosts-playbook.yml`
217+
218+
219+
171220
#### 部署 JDK
172221

173222
- 创建脚本文件:`vim /opt/jdk8-playbook.yml`
@@ -184,7 +233,7 @@ PLAY RECAP *********************************************************************
184233
- name: tar jdk
185234
shell: chdir={{ java_install_folder }} tar zxf jdk-8u181-linux-x64.tar.gz
186235
187-
- name: Set JAVA_HOME
236+
- name: set JAVA_HOME
188237
blockinfile:
189238
path: /etc/profile
190239
marker: "#{mark} JDK ENV"
@@ -206,28 +255,62 @@ PLAY RECAP *********************************************************************
206255
- 执行命令:`ansible-playbook /opt/jdk8-playbook.yml`
207256

208257

209-
#### 修改 hosts
210258

259+
#### 部署 Hadoop 集群
211260

212-
- 创建脚本文件:`vim /opt/hosts-playbook.yml`
261+
- 创建脚本文件:`vim /opt/hadoop-playbook.yml`
213262

214263
```
215-
- hosts: all
264+
- hosts: hadoop-host
216265
remote_user: root
217266
tasks:
218-
- name: update hosts
267+
- name: Creates directory
268+
file:
269+
path: /data/hadoop/hdfs/name
270+
state: directory
271+
- name: Creates directory
272+
file:
273+
path: /data/hadoop/hdfs/data
274+
state: directory
275+
- name: Creates directory
276+
file:
277+
path: /data/hadoop/hdfs/tmp
278+
state: directory
279+
280+
- name: copy gz file
281+
copy: src=/opt/hadoop-2.6.5.tar.gz dest=/usr/local
282+
283+
- name: tar gz file
284+
command: cd /usr/local && tar zxf hadoop-2.6.5.tar.gz
285+
286+
- name: check folder existed
287+
stat: path=/usr/local/hadoop-2.6.5
288+
register: folder_existed
289+
290+
- name: rename folder
291+
command: mv /usr/local/hadoop-2.6.5 /usr/local/hadoop
292+
when: folder_existed.stat.exists == true
293+
294+
- name: set HADOOP_HOME
219295
blockinfile:
220-
path: /etc/hosts
296+
path: /etc/profile
297+
marker: "#{mark} HADOOP ENV"
221298
block: |
222-
192.168.0.223 linux01
223-
192.168.0.223 linux02
224-
192.168.0.223 linux03
225-
192.168.0.223 linux04
226-
192.168.0.223 linux05
299+
HADOOP_HOME=/usr/local/hadoop
300+
PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
301+
export HADOOP_HOME
302+
export PATH
303+
304+
- name: source profile
305+
shell: source /etc/profile
227306
```
228307

229308

230-
- 执行命令:`ansible-playbook /opt/hosts-playbook.yml`
309+
- 执行命令:`ansible-playbook /opt/jdk8-playbook.yml`
310+
311+
312+
313+
231314

232315
-------------------------------------------------------------------
233316

markdown-file/Wormhole-Install-And-Settings.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- Ansible 批量添加 hosts 请看:[点击我](Ansible-Install-And-Settings.md)
3838
- 必须(版本请不要随便用,而是按照如下说明来):
3939
- 一般情况下,我组件都是放在:`/usr/local`
40+
- 批量部署用的是:Ansible(linux01)
4041
- JDK(所有服务器):`1.8.0_181`
4142
- 批量添加 JDK 请看:[点击我](Ansible-Install-And-Settings.md)
4243
- Hadoop 集群(HDFS,YARN)(linux01、linux02、linux03):`2.6.5`

0 commit comments

Comments
 (0)