我是一名全職開發人員,在Puppet Labs工作。我也是Pro Puppet的合着者。
木偶無疑是足夠的你的目標。這是使用Puppet解決這個問題的一種方法。首先,我將解決依賴關係管理問題,因爲無論應用程序有多少實例正在管理,都應該只管理一次。然後,我將介紹如何使用Puppet中定義的資源類型和vcsrepo
資源類型來處理應用程序的多個安裝。
首先,關於組織傀儡代碼來處理同一應用程序的多個安裝。您提到的依賴關係(如beanstalkd,solr和PHP擴展)應使用Puppet類建模。無論在節點上管理多少個應用程序副本,該類只會包含在配置目錄中一次。這個類的一個例子可能是這樣的:
# <modulepath>/site/manifests/app_dependencies.pp
class site::app_dependencies {
# Make all package resources in this class default to
# being managed as installed on the node
Package { ensure => installed }
# Now manage the dependencies
package { 'php': }
package { 'solr': }
package { 'beanstalk': }
# The beanstalk worker queue service needs to be running
service { 'beanstalkd':
ensure => running,
require => Package['beanstalk'],
}
}
現在,你有你的依賴在一個類中,你可以簡單地包括您的應用程序將被部署在節點上這個課。如果您使用的是Web界面,則通常會在site.pp
文件或Puppet儀表板中發生。
# $(puppet config print confdir)/manifests/site.pp
node www01 {
include site::app_dependencies
}
接下來,您需要一種方法來在系統上聲明應用程序的多個實例。不幸的是,現在有一個簡單的方法可以從Web界面執行此操作,但可以使用Puppet清單和定義的資源類型。此解決方案使用vcsrepo
資源來管理應用程序的git存儲庫檢出。
# <modulepath>/myapp/manifests/instance.pp
define myapp::instance($git_rev='master') {
# Resource defaults. The owner and group might be the web
# service account instead of the root account.
File {
owner => 0,
group => 0,
mode => 0644,
}
# Create a directory for the app. The resource title will be copied
# into the $name variable when this resource is declared in Puppet
file { "/var/lib/myapp/${name}":
ensure => directory
}
# Check out the GIT repository at a specific version
vcsrepo { "/var/lib/myapp/${name}/working_copy":
ensure => present,
provider => git,
source => 'git://github.com/puppetlabs/facter.git',
revision => $git_rev,
}
}
有了這個定義的資源類型,你可以聲明你的應用程序的多個安裝,像這樣:
# $(puppet config print confdir)/manifests/site.pp
node www01 {
include site::app_dependencies
# Our app instances always need their dependencies to be managed first.
Myapp::Instance { require => Class['site::app_dependencies'] }
# Multiple instances of the application
myapp::instance { 'jeff.acme.com': git_rev => 'tags/1.0.0' }
myapp::instance { 'josh.acme.com': git_rev => 'tags/1.0.2' }
myapp::instance { 'luke.acme.com': git_rev => 'tags/1.1.0' }
myapp::instance { 'teyo.acme.com': git_rev => 'master' }
}
遺憾的是,目前沒有一個易於使用的現成的辦法,使信息可見從網頁圖形用戶界面。但是,使用外部節點分類器API肯定是可行的。有關拉外部數據導入木偶更多信息,請參閱以下資源:
希望這個信息幫助。
我試圖做一些非常相似的事情,使用工廠模式界面,但我有一個helluva時間處理跨實例共享的目錄,你可以看看我的問題@ http://serverfault.com/questions/ 442520 /木偶可能使用的軟件設計圖案式模塊 – 2012-10-31 20:27:07