CentOS7使用Ansible发布多个Tomcat服务
1,使用ansible
2,比如发布两个tomcat
发布一个手机端,web的和admin的tomcat。 
tomcat-mobile 
tomcat-web 
tomcat-admin 
假设分别在 3个服务器上面 
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,创建一个通用的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然后创建 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.ymltomcat-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.ymltomcat-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.yml4,总结
执行部署: 
/usr/bin/ansible-playbook tomcat-mobile.yml。 
ansible 使用include的解决了脚本的重复编写问题。 
将变量设置,可以同时部署多个tomcat。并且根据hosts的分组配置。当tomcat-web部署多台之后,将ssh打通后配置即可。非常简单的就按组进行扩展部署了。
文章题目:CentOS7使用Ansible发布多个Tomcat服务
标题路径:http://jxruijie.cn/article/djdsedo.html

 
                