新聞中心
1,使用ansible
2,比如發(fā)布兩個tomcat
發(fā)布一個手機端,web的和admin的tomcat。
tomcat-mobile
tomcat-web
tomcat-admin
假設(shè)分別在 3個服務(wù)器上面
192.168.100.101
192.168.100.102
192.168.100.103
tomcat 線上的目錄是:
/data/tomcat-mobile
/data/tomcat-web
/data/tomcat-admin

配置/etc/ansible/hosts
[tomcat-mobile]
tomcat-mobile-01 ansible_ssh_host=192.168.100.101 ansible_ssh_port=22 ansible_ssh_user=root
[tomcat-web]
tomcat-web-01 ansible_ssh_host=192.168.100.101 ansible_ssh_port=22 ansible_ssh_user=root
[tomcat-admin]
tomcat-admin-01 ansible_ssh_host=192.168.100.101 ansible_ssh_port=22 ansible_ssh_user=root
3,創(chuàng)建一個通用的tomcat.yml
tomcat部署模板。其中tomcat_root 和 war_file是變量。
在每一個類型的部署yml中定義。
- name: stop tomcat. command: /bin/sh {{ tomcat_root }}/../../bin/catalina.sh stop -force ignore_errors: yes async: 10 - name: rm ROOT. file: state: absent dest: "{{ tomcat_root }}" - name: mkdir ROOT. file: state: directory dest: "{{ tomcat_root }}" - name: unzip war. unarchive: src: "{{ war_file }}" dest: "{{ tomcat_root }}" copy: yes - name: rm war. file: state: absent dest: "{{ war_file }}" - name: start tomcat. command: /bin/sh {{ tomcat_root }}/../../bin/catalina.sh start ignore_errors: yes async: 10
然后創(chuàng)建 3 個yml
tomcat-mobile.yml
---
- name: install tomcat-mobile
hosts: tomcat-mobile
sudo: False
vars:
war_file: /data/build/tomcat-mobile.war
tomcat_root: /data/tomcat-mobile/webapps/ROOT
tasks:
- name: Include local facts tasks
include: tomcat.yml
tomcat-web.yml:
---
- name: install tomcat-web
hosts: tomcat-web
sudo: False
vars:
war_file: /data/build/tomcat-web.war
tomcat_root: /data/tomcat-web/webapps/ROOT
tasks:
- name: Include local facts tasks
include: tomcat.yml
tomcat-admin.yml:
---
- name: install tomcat-admin
hosts: tomcat-admin
sudo: False
vars:
war_file: /data/build/tomcat-admin.war
tomcat_root: /data/tomcat-admin/webapps/ROOT
tasks:
- name: Include local facts tasks
include: tomcat.yml
4,總結(jié)
執(zhí)行部署:
/usr/bin/ansible-playbook tomcat-mobile.yml。
ansible 使用include的解決了腳本的重復(fù)編寫問題。
將變量設(shè)置,可以同時部署多個tomcat。并且根據(jù)hosts的分組配置。當(dāng)tomcat-web部署多臺之后,將ssh打通后配置即可。非常簡單的就按組進行擴展部署了。
網(wǎng)站標(biāo)題:CentOS7使用Ansible發(fā)布多個Tomcat服務(wù)
瀏覽路徑:http://www.dlmjj.cn/article/djdsedo.html


咨詢
建站咨詢
