繁体   English   中英

带p的tomcat数据库连接字符串(aco / tomcat模块)

[英]tomcat database connection string with puppet (aco/tomcat module)

我正在使用aco / tomcat模块和以下.pp文件:

class somevariable::base {

class { '::tomcat':
    install_from         => 'package',
    package_ensure       => 'latest',
    systemd_service_type => undef,
    service_ensure       => 'stopped',
    service_enable       => false,
  }

  $mydefaults = {
    admin_webapps        => true,
    create_default_admin => true,
    java_opts            => ['-server', '-Xmx1024m', '-Xms256m']
  }

  $myinstances = hiera('somevariable::base::instances')
  create_resources('::tomcat::instance', $myinstances, $mydefaults)

  $mywars = hiera('somevariable::app::wars', {})
  create_resources('file', $mywars)

}

我使用实例设置实例并使用hiera部署战争:

variable::base::instances:
  instance1:
    server_control_port :  '8001'
    http_port           :  '8011'
    ajp_port            :  '8111'
    ajp_params          :  
        tomcatAuthentication : 'false'
    manage_firewall     :  true
  instance2:
    server_control_port :  '8002'
    http_port           :  '8022'
    ajp_port            :  '8222'
    manage_firewall     :  true
variable::app::wars:
   instance1_app:
     path:                 '/var/lib/tomcats/instance1/webapps/sample.war'
     owner:                tomcat
     group:                root
     source:               '/usr/local/src/sample.war'

(我希望这也有助于人们搜索aco / tomcat示例)

如何编写上下文定义以通过hiera为每个实例设置连接字符串实例?

我还尝试在tomcat上下文(文件context.xml)上建立数据库连接,但没有成功,因此我最终决定以这种方式复制每个应用程序的xml文件:

在我的主要清单site.pp

node default {

    include stdlib
    include java

    # Install tomcat and configure it for my application
    class { 'tomcat':
      install_from         => 'package',
      package_ensure       => 'latest',
      service_ensure       => 'running',
      service_enable       => true,
      tomcat_native        => true,
      manage_firewall      => false,
    }

    class {'myapp_tomcat': }
}

我使用以下文件创建了名为myapp_tomcat自定义模块:

modules/myapp_tomcat/manifests/init.pp

class myapp_tomcat {

    file { '/var/lib/tomcat8/conf/Catalina/localhost/Myapp.xml':
      source => 'puppet:///modules/myapp_tomcat/Myapp.xml',
      owner   => 'root',
      group   => 'root',
      mode    => '0644',
      require => Service['tomcat8'],
    }

}

modules/myapp_tomcat/files/Myapp.xml

<?xml version='1.0' encoding='utf-8'?>

<Context>

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <Resource name="jdbc/MyappDS" auth="Container" type="javax.sql.DataSource"
        maxTotal="50" maxIdle="20" maxWaitMillis="10000"
        username="dbuser" password="dbpassword"
        driverClassName="org.postgresql.Driver"
        url="jdbc:postgresql://localhost:5432/mydbname"/>

</Context>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM