SaltStack部署配置Tomcat

Posted warren

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SaltStack部署配置Tomcat相关的知识,希望对你有一定的参考价值。

实验目标

简单部署tomcat及安装java环境

编写salt的状态模块

[[email protected] web]# pwd
/srv/salt/base/web
[[email protected]-node1 web]# cat tomcat.sls 
jdk-install:
  pkg.installed:
    - name: java-1.8.0-openjdk #rpm包安装不需要添加环境变量

tomcat-install:
  file.managed:
    - name: /usr/local/src/apache-tomcat-8.0.46.tar.gz
    - source: salt://web/files/apache-tomcat-8.0.46.tar.gz
    - user: root
    - group: root
    - mode: 755
  cmd.run:
    - name: cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat
    - unless: test -L /usr/local/tomcat && test -d /usr/local/apache-tomcat-8.0.46

上传apache-tomcat-8.0.46到salt的文件管理目录下

[[email protected] src]# ll /srv/salt/base/web/files/apache-tomcat-8.0.46.tar.gz 
-rw-r--r-- 1 root root 9352747 Oct 16  2017 /srv/salt/base/web/files/apache-tomcat-8.0.46.tar.gz

执行状态模块

技术分享
[[email protected] web]# salt "linux-node2*" state.sls web.tomcat
linux-node2.example.com:
----------
          ID: jdk-install
    Function: pkg.installed
        Name: java-1.8.0-openjdk
      Result: True
     Comment: The following packages were installed/updated: java-1.8.0-openjdk
     Started: 00:50:55.027164
    Duration: 46213.48 ms
     Changes:   
              ----------
              chkconfig:
                  ----------
                  new:
                      1.7.4-1.el7
                  old:
                      1.3.61-5.el7_2.1
              copy-jdk-configs:
                  ----------
                  new:
                      2.2-3.el7
                  old:
              giflib:
                  ----------
                  new:
                      4.1.6-9.el7
                  old:
              java-1.8.0-openjdk:
                  ----------
                  new:
                      1:1.8.0.144-0.b01.el7_4
                  old:
              java-1.8.0-openjdk-headless:
                  ----------
                  new:
                      1:1.8.0.144-0.b01.el7_4
                  old:
              javapackages-tools:
                  ----------
                  new:
                      3.4.1-11.el7
                  old:
              libICE:
                  ----------
                  new:
                      1.0.9-9.el7
                  old:
              libSM:
                  ----------
                  new:
                      1.2.2-2.el7
                  old:
              libXcomposite:
                  ----------
                  new:
                      0.4.4-4.1.el7
                  old:
              libXext:
                  ----------
                  new:
                      1.3.3-3.el7
                  old:
              libXfont:
                  ----------
                  new:
                      1.5.2-1.el7
                  old:
              libXi:
                  ----------
                  new:
                      1.7.9-1.el7
                  old:
              libXrender:
                  ----------
                  new:
                      0.9.10-1.el7
                  old:
              libXtst:
                  ----------
                  new:
                      1.2.3-1.el7
                  old:
              libfontenc:
                  ----------
                  new:
                      1.1.3-3.el7
                  old:
              lksctp-tools:
                  ----------
                  new:
                      1.0.17-2.el7
                  old:
              nspr:
                  ----------
                  new:
                      4.13.1-1.0.el7_3
                  old:
                      4.11.0-1.el7_2
              nss:
                  ----------
                  new:
                      3.28.4-12.el7_4
                  old:
                      3.21.0-9.el7_2
              nss-pem:
                  ----------
                  new:
                      1.0.3-4.el7
                  old:
              nss-softokn:
                  ----------
                  new:
                      3.28.3-8.el7_4
                  old:
                      3.16.2.3-14.2.el7_2
              nss-softokn-freebl:
                  ----------
                  new:
                      3.28.3-8.el7_4
                  old:
                      3.16.2.3-14.2.el7_2
              nss-sysinit:
                  ----------
                  new:
                      3.28.4-12.el7_4
                  old:
                      3.21.0-9.el7_2
              nss-tools:
                  ----------
                  new:
                      3.28.4-12.el7_4
                  old:
                      3.21.0-9.el7_2
              nss-util:
                  ----------
                  new:
                      3.28.4-3.el7
                  old:
                      3.21.0-2.2.el7_2
              python-javapackages:
                  ----------
                  new:
                      3.4.1-11.el7
                  old:
              python-lxml:
                  ----------
                  new:
                      3.2.1-4.el7
                  old:
              ttmkfdir:
                  ----------
                  new:
                      3.0.9-42.el7
                  old:
              tzdata-java:
                  ----------
                  new:
                      2017b-1.el7
                  old:
              xorg-x11-font-utils:
                  ----------
                  new:
                      1:7.5-20.el7
                  old:
              xorg-x11-fonts-Type1:
                  ----------
                  new:
                      7.5-9.el7
                  old:
----------
          ID: tomcat-install
    Function: file.managed
        Name: /usr/local/src/apache-tomcat-8.0.46.tar.gz
      Result: True
     Comment: File /usr/local/src/apache-tomcat-8.0.46.tar.gz updated
     Started: 00:51:41.243020
    Duration: 496.457 ms
     Changes:   
              ----------
              diff:
                  New file
              mode:
                  0755
----------
          ID: tomcat-install
    Function: cmd.run
        Name: cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat
      Result: True
     Comment: Command "cd /usr/local/src && tar zxf apache-tomcat-8.0.46.tar.gz && mv apache-tomcat-8.0.46 /usr/local/ && ln -s /usr/local/apache-tomcat-8.0.46 /usr/local/tomcat" run
     Started: 00:51:41.740160
    Duration: 1288.003 ms
     Changes:   
              ----------
              pid:
                  9742
              retcode:
                  0
              stderr:
              stdout:

Summary
------------
Succeeded: 3 (changed=3)
Failed:    0
------------
Total states run:     3
salt "linux-node2*" state.sls web.tomcat

 

以上是关于SaltStack部署配置Tomcat的主要内容,如果未能解决你的问题,请参考以下文章

Saltstack批量编译部署nginx(多模块)

zabbix监控tomcat主机,并自动部署新主机

SaltStack配置管理-3之安装tomcat状态

SaltStack实战之配置管理-LAMP自动化部署

saltstack部署LAMP架构

saltstack部署LAMP架构