zoukankan      html  css  js  c++  java
  • 企业级自动化部署方案——ansible实现tomcat自动安装和配置

    共耗时10多个小时

    思路一

    总体设计

    在这里插入图片描述

    ansible-playbook目录结构

    [root@ansible ~]# tree /etc/ansible/roles/tomcat
    /etc/ansible/roles/tomcat
    ├── files
    │   ├── catalina.sh
    │   ├── context.xml
    │   └── setenv.sh
    ├── handlers
    │   └── main.yaml
    ├── tasks
    │   ├── install_jdk.yaml
    │   ├── install_tomcat.yaml
    │   └── main.yaml
    ├── templates
    │   ├── catalina.sh
    │   ├── server.xml
    │   ├── tomcat.service
    │   └── tomcat-users.xml
    └── vars
        └── main.yaml
    

    入口文件

    [root@ansible ~]# ll /etc/ansible/work_dir/tomcat.yaml
    -rw-r--r-- 1 root root 55 Mar 29 19:58 /etc/ansible/work_dir/tomcat.yaml
    

    执行与结果

    [root@ansible work_dir]# pwd
    /etc/ansible/work_dir
    [root@ansible work_dir]# ansible-playbook tomcat.yaml
    

    在这里插入图片描述在这里插入图片描述在这里插入图片描述

    实现过程问题记录

    tomcat应用程序是root用户启动的,root用户启动tomcat有一个严重的问题,那就是tomcat具有root权限,这意味着你的任何一个页面脚本(html/js)都具有root权限,所以可以轻易地用页面脚本修改整个硬盘里的文件,非常危险。

    [root@cilent apache-tomcat-8.5.53]# ll tomcat.pid
    -rw-r----- 1 root root 6 Mar 30 13:47 tomcat.pid
    

    尝试解决

    1.TOMCAT_USER=tomcat

    [root@cilent ~]# grep "&& TOMCAT_USER" /usr/local/apache-tomcat-8.5.53/bin/daemon.sh
    test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat
    

    搜索到的文章大多都是这样解决,但在CentOS7+Tomcat8上不适用

    2.重写startup.sh和shutdown.sh脚本
    思路:启动和关闭Tomcat应用程序的时候切换到tomcat用户执行
    报错如下:

    [tomcat@cilent ~]# systemctl restart nginx
    ==== AUTHENTICATING FOR org.freedesktop.systemdl.manage-units ===
    Authentication is required to manage system services or units.
    Authenticating as: root
    

    3.解决成功
    yum安装了tomcat,有系统标准启动方式,查看其配置文件找到了解决办法
    在tomcat.service添加个 User=tomcat 就好了

    [root@cilent apache-tomcat-8.5.53]# ll tomcat.pid
    -rw-r----- 1 tomcat tomcat 6 Mar 30 17:38 tomcat.pid
    

    其他问题记录

    1.linux下部署tomcat ,启动和停止分别使用startup.sh和shutdown.sh,它们都会调用catalina.sh,进而调用到setenv.sh
    2.配置管理用户conf/tomcat-users.xml

    <tomcat-users>
    <role rolename="manager-gui"/>
    <user username="tomcat" password="123456" roles="manager-gui" />
    </tomcat-users>
    

    3.访问Manager App 403 Access Denied
    搜索的文章都只提到了在tomcat-users.xml里添加上面的语句,无法解决
    通过403页面的官方文档,找到解决办法

    By default the Host Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager App's context.xml file

    #cat webapps/manager/META-INF/context.xml
    <Context antiResourceLocking="false" privileged="true" >
      <Valve className="org.apache.catalina.valves.RemoteAddrValve"
             allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1" />
    </Context>
    

    这段代码的作用是限制来访IP,127.d+.d+.d+|::1|0:0:0:0:0:0:0:1 是正则表达式,表示IPv4和IPv6的本机环回地址,所以其他主机无法访问

    修改为所有人都可以访问 allow="^.*$"allow="127.d+.d+.d+|::1|0:0:0:0:0:0:0:1|d+.d+.d+.d+"

    思路二(失败)

    yum安装了tomcat,需要配置JAVA变量,有系统标准启动方式,所以想能不能仿照其配置文件进行ansible自动安装配置

    配置了JAVA变量,复制了配置文件/etc/tomcat,/usr/libexec/tomcat目录(按实际情况配置)
    在这里插入图片描述报错如下:
    在这里插入图片描述猜测是漏了配置文件


    有时间再继续探索

  • 相关阅读:
    Java内存区域
    高并发
    集合框架
    面向对象基础概念
    java synchronized详解
    java使用DOM操作XML
    二、认识Xcode(第一个工程:Hello world)
    菜鸟手下的iOS开发笔记(swift)
    一、iOS开发环境搭建
    一个基于JRTPLIB的轻量级RTSP客户端(myRTSPClient)——实现篇:(十)使用JRTPLIB传输RTP数据
  • 原文地址:https://www.cnblogs.com/zhaoya2019/p/12600086.html
Copyright © 2011-2022 走看看