简体   繁体   English

::如何使用p清单配置Tomcat数据源?

[英]Puppet: how to configure a Tomcat datasource using a puppet manifest?

I made a puppet class to install Apache Tomcat 7.55 in my node, but I do not know how to configure a datasource in it. 我制作了一个up类,以在节点中安装Apache Tomcat 7.55,但我不知道如何在其中配置数据源。

The last step of my class is to deploy an application: 我课程的最后一步是部署应用程序:

tomcat::war { 'my.war':
    catalina_base => '/opt/apache-tomcat/tomcat_7_0_55',
    war_source    => '/etc/puppet/resources/my.war',
  }

After this step, I need to configure the following datasource in conf/server.xml file: 完成此步骤后,我需要在conf / server.xml文件中配置以下数据源:

 <Context path="/my-app" docBase="my-app" debug="5" reloadable="true" crossContext="true">
                 <Resource name="jdbc/my-app-db" auth="Container" 
                          type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="5"
                          username="xxx" password="yyy"
                          driverClassName="com.mysql.jdbc.Driver"
                          url="jdbc:mysql://<host>:3306/<database>?zeroDateTimeBehavior=convertToNull"/>
</Context>

How can I do this through Puppet? 如何通过Puppet做到这一点? I am using puppetlabs-tomcat module. 我正在使用puppetlabs-tomcat模块。

Thanks! 谢谢!

you can create a template for the server.xml file, and set file type as below 您可以为server.xml文件创建一个模板,并如下设置文件类型

$mysql_username = xxx
$mysql_password = yyy
$mysql_server = zzz

file { "${install_path}/conf/server.xml" :
    ensure  => present,
    content => template('tomcat/server.xml.erb'),
    owner   => 'tomcat',
    group   => 'tomcat,
    mode    => '0644',
    notify  => 'Class[tomcat::service]',
}

The tomcat/template/server.xml.erb should include the content as tomcat/template/server.xml.erb应该包含以下内容:

.... blabla

 <Context path="/my-app" docBase="my-app" debug="5" reloadable="true" crossContext="true">
                 <Resource name="jdbc/my-app-db" auth="Container" 
                          type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="5"
                          username="<%= @mysql_username %>" password="<%= @mysql_password %>"
                          driverClassName="com.mysql.jdbc.Driver"
                          url="jdbc:mysql://<%= @mysql_server %>:3306/<database>?zeroDateTimeBehavior=convertToNull"/>
</Context>

.... blabla

You can use augeas tool with xml lens to configure this inside server.xml. 您可以将augeas工具与xml镜头一起使用,以在server.xml中进行配置。 You need to have augeas module installed with puppet though. 您需要安装带有puppet的augeas模块。

Here is an example config 这是一个示例配置

tomcat::config::server::context {'alfresco.war':
doc_base => 'alfresco.war',
context_ensure => present,
catalina_base => '/var/lib/tomcat7/alfresco.war',
parent_service        => 'Catalina',
parent_engine         => 'Catalina',
parent_host           => 'localhost',
server_config         => '/etc/tomcat7/server.xml',
additional_attributes => {
          'path' => '/alfresco',
        },
} 

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

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