素材巴巴 > 程序开发 >

利用 Ansible 部署 Tomcat

程序开发 2023-09-10 16:56:43

我们需要用到的文件jdk、tomcat

链接:https://pan.baidu.com/s/1b_QKA4dFaX-ELNe4XoBPqg 
提取码:1016

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

1.首先准备n台机器

ansible机器 :192.168.139.59

目标主机1:192.168.139.60

目标主机2:192.168.139.62

2、关闭防火墙和selinux

systemctl stop firewalld

setenforce 0

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

3、配置免密登录

ssh-keygen 

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

ssh-copy-id root@目标主机的IP

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

 4、安装ansible

yum -y install ansible

5、在ansible的配置文件中添加目标主机

vim /etc/ansible/hosts

[tomcat]

192.168.139.60

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

6、检查ansible与目标主机是否连通

ansible tomcat -m ping

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

7、上传我们开头的jdk、tomcat文件到ansible机器中

8、编写tomcat.yml

vim tomcat.yml

---
- hosts: tomcat
  tasks: 
      - name: 关闭防火墙
        shell: systemctl stop firewalld
      - name: 关闭selinux
        shell: setenforce 0
      - name: 推送jdk Java环境
        copy: src=jdk-8u131-linux-x64.rpm dest=/root
      - name: 创建文件夹
        file: path=/opt/tomcat state=directory
      - name: 推送tomcat的压缩包
        unarchive: src=apache-tomcat-8.5.35.tar.gz dest=/opt/tomcat
      - name: 安装jdk
        yum: name=jdk-8u131-linux-x64.rpm state=installed
      - name: 启动tomcat
        shell: nohup /opt/tomcat/apache-tomcat-8.5.35/bin/startup.sh

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

9、检查tomcat.yml 

ansible-playbook --syntax-check tomcat.yml

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

 10、执行tomcat.yml

ansible-playbook tomcat.yml

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

 11、验证成功

在浏览器输入目标主机IP:8080
例:192.168.139.60:8080

watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA54ix55Cz5YWI55Sf,size_20,color_FFFFFF,t_70,g_se,x_16

 OK完成!有帮助的点赞收藏吧!


标签:

素材巴巴 Copyright © 2013-2021 http://www.sucaibaba.com/. Some Rights Reserved. 备案号:备案中。