1. ansible-playbook安装tomcat
  1) 编写playbook的tomcat安装配置

 1 [root@test-1 bin]# vim /ansible/tomcat/bin/tomcat.yaml
2 [root@test-1 bin]# cat /ansible/tomcat/bin/tomcat.yaml
3 ---
4 - hosts: web1
5 remote_user: root
6 vars:
7 tomcat_version: 8.5.38
8 tomcat_install_dir: /opt/
9
10 tasks:
11 - name: Install jdk1.8
12 yum:
13 name: java-1.8.0-openjdk
14 state: present
15 - name: Download tomcat
16 get_url:
17 url: http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v{{tomcat_version}}/bin/apache-tomcat-{{tomcat_version}}.tar.gz
18 dest: /tmp
19 - name: Unarchive tomcat
20 unarchive:
21 src: /tmp/apache-tomcat-{{tomcat_version}}.tar.gz
22 dest: "{{tomcat_install_dir}}/"
23 copy: no
24 - name: Start tomcat
25 shell: cd {{tomcat_install_dir}} && mv apache-tomcat-{{tomcat_version}} tomcat8 && cd tomcat8/bin && nohup ./startup.sh &

2)配置文件检查

1 [root@test-1 bin]# ansible-playbook  --syntax-check tomcat.yaml
2
3 playbook: tomcat.yaml

3) 执行playbook的tomcat安装文件

 1 [root@test-1 bin]# ansible-playbook   tomcat.yaml
2
3 PLAY [web1] ******************************************************************************************************************************************************************************************************************************************************************
4
5 TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************************************************
6 ok: [192.168.200.132]
7 ok: [192.168.200.133]
8
9 TASK [Install jdk1.8] ********************************************************************************************************************************************************************************************************************************************************
10 changed: [192.168.200.132]
11 changed: [192.168.200.133]
12
13 TASK [Download tomcat] *******************************************************************************************************************************************************************************************************************************************************
14 ok: [192.168.200.133]
15 ok: [192.168.200.132]
16
17 TASK [Unarchive tomcat] ******************************************************************************************************************************************************************************************************************************************************
18 changed: [192.168.200.133]
19 changed: [192.168.200.132]
20
21 TASK [Start tomcat] **********************************************************************************************************************************************************************************************************************************************************
22 changed: [192.168.200.133]
23 changed: [192.168.200.132]
24
25 PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************
26 192.168.200.132 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
27 192.168.200.133 : ok=5 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

2. 验证playbook的tomcat验证是否正常
  1)验证端口和进程是否存在

 1 [root@test-1 bin]# ansible web1 -m shell -a " ps -ef |grep java "
2 192.168.200.132 | CHANGED | rc=0 >>
3 root 24559 24558 0 19:18 ? 00:00:08 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat8 -Dcatalina.home=/opt/tomcat8 -Djava.io.tmpdir=/opt/tomcat8/temp org.apache.catalina.startup.Bootstrap start
4 root 25207 25202 0 19:53 pts/1 00:00:00 /bin/sh -c ps -ef |grep java
5 root 25209 25207 0 19:53 pts/1 00:00:00 grep java
6
7 192.168.200.133 | CHANGED | rc=0 >>
8 root 24457 24456 0 19:18 ? 00:00:08 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /opt/tomcat8/bin/bootstrap.jar:/opt/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat8 -Dcatalina.home=/opt/tomcat8 -Djava.io.tmpdir=/opt/tomcat8/temp org.apache.catalina.startup.Bootstrap start
9 root 25103 25098 0 19:53 pts/1 00:00:00 /bin/sh -c ps -ef |grep java
10 root 25105 25103 0 19:53 pts/1 00:00:00 grep java
11
12 [root@test-1 bin]# ansible web1 -m shell -a " netstat -lntup |grep 8080"
13 192.168.200.132 | CHANGED | rc=0 >>
14 tcp6 0 0 :::8080 :::* LISTEN 24559/java
15
16 192.168.200.133 | CHANGED | rc=0 >>
17 tcp6 0 0 :::8080 :::* LISTEN 24457/java

2)curl 模拟浏览器请求是否正常访问

 1 [root@test-1 bin]# curl -I http://192.168.200.132:8080/
2 HTTP/1.1 200
3 Content-Type: text/html;charset=UTF-8
4 Transfer-Encoding: chunked
5 Date: Thu, 22 Aug 2019 11:55:39 GMT
6
7 [root@test-1 bin]# curl -I http://192.168.200.133:8080/
8 HTTP/1.1 200
9 Content-Type: text/html;charset=UTF-8
10 Transfer-Encoding: chunked
11 Date: Thu, 22 Aug 2019 11:55:44 GMT

ansible-playbook安装tomcat的更多相关文章

  1. ansible playbook 安装docker

    1.新增host配置到/etc/ansible/hosts文件中 [docker] 192.168.43.95 2.配置无密码登录 # 配置ssh,默认rsa加密,保存目录(公钥)~/.ssh/id_ ...

  2. Vagrant Ansible Playbook 安装一群虚拟机

    https://docs.ansible.com/ https://favoorr.github.io/2017/01/06/vagrant-virtualbox-vagrantfile-config ...

  3. ansible自动安装rabbitmq

    ansible playbook 安装rabbitmq单机版,以下脚本在CentOS6.7服务器测试通过. 需要配置本机的yum源,用于安装socat软件. rabbitmq版本和Erlang版本需要 ...

  4. ansible批量部署tomcat

    1.1 构建目录结构 此操作是安装nginx+mysql+tomcat+db的目录结构,可以参考一下,不错~ mkdir -p /ansible/roles/{nginx,mysql,tomcat,d ...

  5. ansible离线安装

    目录 1. ansible离线安装 2. ansible配置文件 3. ansible常用的命令: 1. ansible离线安装 最近要在内网部署一台ansible服务器,只能手动离线安装ansibl ...

  6. ansible笔记(10):初识ansible playbook

    ansible笔记():初识ansible playbook 假设,我们想要在test70主机上安装nginx并启动,我们可以在ansible主机中执行如下3条命令 ansible test70 -m ...

  7. Ansible playbook 批量修改服务器密码 先普通后root用户

    fsckzy   Ansible playbook 批量修改服务器密码 客户的需求:修改所有服务器密码,密码规则为Rfv5%+主机名后3位 背景:服务器有CentOS6.7,SuSE9.10.11,r ...

  8. 写Ansible playbook添加zabbix被监控的对象

    本主题达到的效果是能通过编写Ansible Playbook,创建zabbix主机组,把被监控的对象加入到zabbix监控系统中,同时链接到对象的模板. 1.准备工作 在zabbix服务器上面,我们需 ...

  9. 利用ansible来做tomcat应用的持续交付

    https://www.jianshu.com/p/fca8f91ae223 在做持续交付这件事,想必大家都是用jenkins这款程序来做基石.当然,我们这次也是用jenkins作为承载工具,jenk ...

随机推荐

  1. LAMP环境之编译安装httpd服务

    “Apache HTTP Server”是开源软件项目的杰出代表,它基于标准的 HTTP 网络协议提供网页浏览服务. 在配置 Apache 网站服务之前,需要正确安装好 httpd 服务器软件.htt ...

  2. npm 报错 cb.apply is not a function

    解决方法1 目录C:\Users(your username)\AppData\Roaming 有个npm文件夹 删除如果没有 npm cache文件cmd下运行 npm clean cache —f ...

  3. 在Apache服务器上安装SSL证书

    参考:链接 前提条件 1.您的Apache服务器上已经开启了443端口(HTTPS服务的默认端口) // 开通443端口 firewall-cmd --zone=public --add-port=4 ...

  4. markdown基本语法说明

    作为一个java程序员,要接触的东西很多,时不时 就要学习,最近写文档的时候发现,markdown很有意思,就记录下来,作为一个简单的说明和学习 :    1.标题 # 这是一级标题 ## 这是二级标 ...

  5. python3 if

    if-else python中特有if-elif-else语句

  6. 乔悟空-CTF-i春秋-Web-SQL

    2020.09.05 是不是有些题已经不能做了--费了半天,到最后发现做不出来,和网上大神的方法一样也不行,最搞笑的有个站好像是别人运营中的,bug好像被修复了-- 做题 题目 题目地址 做题 尝试简 ...

  7. [剑指Offer]33-根据后序序列判断是否能组成BST

    题目 如题. 题解 从序列第一个大于根节点的值往后都是右子树,判断右子树是否都大于根节点. 然后递归判断左右子树是否是BST 代码 class TreeNode { int val = 0; Tree ...

  8. 阿里云服务器外网IP无法访问网站

    1.添加IIS时添加了127.0.0.1的IP监听导致无法访问外网IP 添加IP监听:netsh http add iplisten 127.0.0.1显示IP监听:netsh http show i ...

  9. mariadb 2

    mariadb第二章-增删改   MariaDB 数据类型 MariaDB数据类型可以分为数字,日期和时间以及字符串值. 使用数据类型的原则:够用就行, 尽量使用范围小的,而不用大的 常用的数据类型 ...

  10. Windows10数字权利永久激活教程

    很多人用Windows10系统,但是没有办法激活,这个教程一定会让你永久激活windows10系统(并非ksm)   打开设置,查看是否激活   如果激活的话,先退掉秘钥,在Windows power ...