@@ -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
0 commit comments