![如何通过 Puppet 在 Tomcat 上安装 Solr 4.x?](https://linux22.com/image/655092/%E5%A6%82%E4%BD%95%E9%80%9A%E8%BF%87%20Puppet%20%E5%9C%A8%20Tomcat%20%E4%B8%8A%E5%AE%89%E8%A3%85%20Solr%204.x%EF%BC%9F.png)
到目前为止,我一直使用以下方法在 Tomcat 6 上安装 Solr 3.x:
package { 'openjdk-6-jdk' :
ensure => installed,
}
package { 'solr-tomcat' :
ensure => installed,
}
exec { 'tomcat-port':
command => "sed -i.bak 's|port=\"8080\"|port=\"8983\"|g' /etc/tomcat6/server.xml",
path => ["/bin", "/usr/bin"],
}
service { 'tomcat6' :
ensure => running,
require => Package['solr-tomcat'],
}
然而我想在 Tomcat 7 上安装 Solr 4.x,但 Debian 似乎没有适合 Solr 的软件包(例如solr-tomcat
)。
到目前为止,Tomcat 7 的运行方式如下:
package { [ 'tomcat7', 'tomcat7-admin' ]: ensure => installed, }
service { 'tomcat7' : ensure => running, }
exec { 'tomcat-port':
command => "sed -i.bak 's|port=\"8080\"|port=\"8983\"|g' /etc/tomcat7/server.xml",
path => ["/bin", "/usr/bin"],
}
但是我如何安装 Solr 4.x?
答案1
您可以创建自己的 Debian 软件包并将其托管在自己的存储库中。FPM 等项目(https://github.com/jordansissel/fpm) 在这里帮了大忙。另一个选择是从项目网站检索 Solr tarball,并管理一系列exec
语句以将其提取到 Tomcat 安装中的 webapps 目录中。
答案2
最简单的方法是定义exec
,例如:
exec { "solr-download":
command => "/usr/bin/wget http://archive.apache.org/dist/lucene/solr/4.9.1/solr-4.9.1.tgz && /bin/tar -xf solr-4.9.1.tgz"
cwd => "/opt",
creates => "/opt/solr-4.9.1.tgz",
}
为了获得更灵活的解决方案,您必须编写一个类(solr4-tomcat.pp), 例如:
class solr {
# variables
$version = '4.10.4'
$data_dir = "/opt/solr/data"
$home_dir = "/opt/solr/home"
$tomcat_version = "tomcat7"
$tomcat_base = "/var/lib/${tomcat_version}"
$tomcat_user = $operatingsystem ? {
/RedHat|CentOS/ => "tomcat",
/Debian|Ubuntu/ => $tomcat_version,
}
# includes
include solr::files
class { 'tomcat': install_from_source => false }
# Ensure Java libraries are installed
package { "java":
ensure => present,
name => $operatingsystem ? {
'Centos' => $operatingsystemrelease ? {
'6.0' => "java-1.6.0-openjdk.$hardwaremodel",
'*' => 'openjdk-7-jre',
},
/Debian|Ubuntu/ => 'openjdk-7-jre-headless',
},
}
# Set port 8983 for Tomcat 7 and make sure it's running.
tomcat::instance {'default': package_name => $tomcat_version} ->
tomcat::service {'default':
service_name => 'tomcat7',
service_ensure => 'running',
use_jsvc => false, use_init => true,
# use_jsvc => true, java_home => "/usr/lib/jvm/java-7-openjdk-amd64",
}->
tomcat::config::server { $tomcat_version:
catalina_base => $tomcat_base,
port => 8983,
}
class solr::files {
# Ensure solr directories are present.
file { 'home_dir':
path => $solr::home_dir,
ensure => directory,
recurse => true,
}
file { 'data_dir':
path => $solr::data_dir,
ensure => directory,
recurse => true,
owner => $solr::tomcat_user,
group => $solr::tomcat_user,
}
# Download and extract solr
exec { "solr-extract":
path => ['/usr/bin', '/usr/sbin', '/bin'],
command => "curl -s http://archive.apache.org/dist/lucene/solr/${solr::version}/solr-${solr::version}.tgz | tar zxf -",
cwd => "/opt/solr",
require => [File["data_dir"], File["home_dir"]],
creates => "/opt/solr/solr-${solr::version}/dist/solr-${solr::version}.war",
}
# Logging setup for Tomcat.
exec { 'solr-install-logging-jars':
path => ['/usr/bin', '/usr/sbin', '/bin'],
cwd => "/opt/solr",
command => "cp -v /opt/solr/solr-${solr::version}/example/lib/ext/*.jar /opt/solr/solr-${solr::version}/dist/solrj-lib/*.jar /opt/solr/solr-${solr::version}/example/resources/log4j.properties ${solr::tomcat_base}/webapps/solr/WEB-INF/lib",
onlyif => "test ! -f ${solr::tomcat_base}/webapps/solr/WEB-INF/lib/log4j-1.2.17.jar",
require => Exec['solr-extract'],
}
}
tomcat::war { 'solr.war':
catalina_base => $tomcat_base,
war_source => "/opt/solr/solr-${solr::version}/dist/solr-${solr::version}.war",
require => Class["solr::files"],
notify => Service[$tomcat_version],
}
}
检查替代清单: