Puppet
理論
定義: Puppet 是一個(gè)跨平臺(tái)的集中化配置管理系統(tǒng),它使用自有的描述語(yǔ)言,可管理配置文件、用戶、Cron、軟件包、系統(tǒng)服務(wù)等,Puppet把這些統(tǒng)稱為“資源”。
運(yùn)維的三個(gè)層次,以及對(duì)應(yīng)的軟件產(chǎn)品
OS Provision:OS Provision:
bare metal:pxe, cobblervirutal machine:image file template
Configuration:
ansible(agentless)puppet(master/agent)(ruby)saltstack(python)
Command and Control:
ansible(playbook)fabric(fab)func...
puppet的工作模型:
分為兩種
單機(jī)模型:手動(dòng)應(yīng)用清單;
master/agent:由agent周期性地向Master請(qǐng)求清單并自動(dòng)應(yīng)用于本地;
單機(jī)模型
程序環(huán)境:
配置文件:/etc/puppet/puppet.conf
主程序:/usr/bin/puppet
?
?
puppet程序: Usage: puppet <subcommand> [options] <action> [options] help Display Puppet help. apply Apply Puppet manifests locally describe Display help about resource types agent The puppet agent daemon master The puppet master daemon module Creates, installs and searches for modules on the Puppet Forge …… 'puppet help <subcommand>' for help on a specific subcommand. 'puppet help <subcommand> <action>' for help on a specific subcommand action. puppet apply: Applies a standalone Puppet manifest to the local system. puppet apply [-d|--debug] [-v|--verbose] [-e|--execute] [--noop] <file> 程序環(huán)境: 配置文件:/etc/puppet/ puppet.conf 主程序:/usr/bin/puppet puppet程序: Usage: puppet <subcommand> [options] <action> [options] help Display Puppet help. apply Apply Puppet manifests locally describe Display help about resource types agent The puppet agent daemon master The puppet master daemon module Creates, installs and searches for modules on the Puppet Forge …… 'puppet help <subcommand>' for help on a specific subcommand. 'puppet help <subcommand> <action>' for help on a specific subcommand action. puppet apply: Applies a standalone Puppet manifest to the local system. puppet apply [-d|--debug] [-v|--verbose] [-e|--execute] [--noop] <file>
? ?
puppet資源: 資源抽象的緯度(RAL如何抽象資源的?): 類(lèi)型:具有類(lèi)似屬性的組件,例如package、service、file; 將資源的屬性或狀態(tài)與其實(shí)現(xiàn)方式分離; 僅描述資源的目標(biāo)狀態(tài),也即期望其實(shí)現(xiàn)的結(jié)果狀態(tài),而不是具體過(guò)程; RAL由“類(lèi)型”和提供者(provider); puppet describe: Prints help about Puppet resource types, providers, and metaparameters. puppet describe [-h|--help] [-s|--short] [-p|--providers] [-l|--list] [-m|--meta] [type] -l:列出所有資源類(lèi)型; -s:顯示指定類(lèi)型的簡(jiǎn)要幫助信息; -m:顯示指定類(lèi)型的元參數(shù),一般與-s一同使用; 資源定義:向資源類(lèi)型的屬性賦值來(lái)實(shí)現(xiàn),可稱為資源類(lèi)型實(shí)例化; 定義了資源實(shí)例的文件即清單,manifest; 定義資源的語(yǔ)法: type {'title': attribute1 => value1, atrribute2 => value2, …… } 注意:type必須使用小寫(xiě)字符;title是一個(gè)字符串,在同一類(lèi)型中必須惟一; 資源屬性中的三個(gè)特殊屬性: Namevar, 可簡(jiǎn)稱為name; ensure:資源的目標(biāo)狀態(tài); Provider:指明資源的管理接口; 資源類(lèi)型: group: Manage groups. 屬性: name:組名; gid:GID; system:是否為系統(tǒng)組,true OR false; ensure:目標(biāo)狀態(tài),present/absent; members:成員用戶; user: Manage users. 屬性: name:用戶名; uid: UID; gid:基本組ID; groups:附加組,不能包含基本組; comment:注釋; expiry:過(guò)期時(shí)間 ; home:家目錄; shell:默認(rèn)shell類(lèi)型; system:是否為系統(tǒng)用戶 ; ensure:present/absent; password:加密后的密碼串; 關(guān)系元參數(shù):before/require A before B: B依賴于A,定義在A資源中; { ... before => Type['B'], ... } B require A: B依賴于A,定義在B資源中; { ... require => Type['A'], ... } package: Manage packages. 屬性: ensure:installed, present, latest, absent name:包名; source:程序包來(lái)源,僅對(duì)不會(huì)自動(dòng)下載相關(guān)程序包的provider有用,例如rpm或dpkg;
service: Manage running services. 屬性: ensure:Whether a service should be running. Valid values are stopped (also called false), running (also called true). enable:Whether a service should be enabled to start at boot. Valid values are true, false, manual. name: path:The search path for finding init scripts. Multiple values should be separated by colons or provided as an array. 腳本的搜索路徑,默認(rèn)為/etc/init.d/; hasrestart: hasstatus: start:手動(dòng)定義啟動(dòng)命令; stop: status: restart:Specify a restart command manually. If left unspecified, the service will be stopped and then started. 通常用于定義reload操作; 資源引用: Type['title'] 類(lèi)型的首字母必須大寫(xiě); 資源有特殊屬性: 名稱變量(namevar): name可省略,此時(shí)將由title表示; ensure: 定義資源的目標(biāo)狀態(tài); 元參數(shù):metaparameters 依賴關(guān)系: before require 通知關(guān)系:通知相關(guān)的其它資源進(jìn)行“刷新”操作; notify A notify B:B依賴于A,且A發(fā)生改變后會(huì)通知B; { ... notify => Type['B'], ... } subscribe B subscribe A:B依賴于A,且B監(jiān)控A資源的變化產(chǎn)生的事件; { ... subscribe => Type['A'], ... }? file: Manages files, including their content, ownership, and permissions. ensure:Whether the file should exist, and if so what kind of file it should be. Possible values are present, absent, file, directory, and link. file:類(lèi)型為普通文件,其內(nèi)容由content屬性生成或復(fù)制由source屬性指向的文件路徑來(lái)創(chuàng)建; link:類(lèi)型為符號(hào)鏈接文件,必須由target屬性指明其鏈接的目標(biāo)文件; directory:類(lèi)型為目錄,可通過(guò)source指向的路徑復(fù)制生成,recurse屬性指明是否遞歸復(fù)制; path:文件路徑; source:源文件; content:文件內(nèi)容; target:符號(hào)鏈接的目標(biāo)文件; owner:屬主 group:屬組 mode:權(quán)限; atime/ctime/mtime:時(shí)間戳; 通知元參數(shù): A notify B:B依賴于A,接受由A觸發(fā)refresh; B subscribe A:B依賴于A,接受由A觸發(fā)refresh; 示例1: file{'test.txt': path => '/tmp/test.txt', ensure => file, source => '/etc/fstab', }? file{'test.symlink': path => '/tmp/test.symlink', ensure => link, target => '/tmp/test.txt', require => File['test.txt'], }? file{'test.dir': path => '/tmp/test.dir', ensure => directory, source => '/etc/yum.repos.d/', recurse => true, } 示例2: service{'httpd': ensure => running, enable => true, restart => 'systemctl restart httpd.service', # subscribe => File['httpd.conf'], }? package{'httpd': ensure => installed, }? file{'httpd.conf': path => '/etc/httpd/conf/httpd.conf', source => '/root/manifests/httpd.conf', ensure => file, notify => Service['httpd'], }? Package['httpd'] -> File['httpd.conf'] -> Service['httpd']
回顧:
Bootstraping,Configuration, Command and Control;
puppet:Configuration apply:standalone master/agent: manifest: resource node 資源:resource type{'title': atrribute => value, ... } 關(guān)系元參數(shù):before/require, notify/subscribe 特殊參數(shù):NameVar 目標(biāo)狀態(tài):ensure 資源類(lèi)型:group, user, package, service, file;exec, cron, notify, ... puppet describe
? Puppet(2)
資源類(lèi)型: exec: Executes external commands. Any command in an exec resource must be able to run multiple times without causing harm --- that is, it must be idempotent. command (namevar):要運(yùn)行的命令; cwd:The directory from which to run the command. creates:文件路徑,僅此路徑表示的文件不存在時(shí),command方才執(zhí)行; user/group:運(yùn)行命令的用戶身份; path:The search path used for command execution. Commands must be fully qualified if no path is specified. onlyif:此屬性指定一個(gè)命令,此命令正常(退出碼為0)運(yùn)行時(shí),當(dāng)前command才會(huì)運(yùn)行; unless:此屬性指定一個(gè)命令,此命令非正常(退出碼為非0)運(yùn)行時(shí),當(dāng)前command才會(huì)運(yùn)行; refresh:重新執(zhí)行當(dāng)前command的替代命令; refreshonly:僅接收到訂閱的資源的通知時(shí)方才運(yùn)行; cron: Installs and manages cron jobs. Every cron resource created by Puppet requires a command and at least one periodic attribute (hour, minute, month, monthday, weekday, or special). command:要執(zhí)行的任務(wù); ensure:present/absent; hour: minute: monthday: month: weekday: user:以哪個(gè)用戶的身份運(yùn)行命令 target:添加為哪個(gè)用戶的任務(wù) name:cron job的名稱; 示例: cron{'timesync': command => '/usr/sbin/ntpdate 10.1.0.1 &> /dev/null', ensure => present, minute => '*/3', user => 'root', } notify: Sends an arbitrary message to the agent run-time log. 屬性: message:信息內(nèi)容 name:信息名稱;? 核心類(lèi)型: group: 組 user:用戶 packge:程序包 service:服務(wù) file:文件 exec:執(zhí)行自定義命令,要求冪等 cron:周期性任務(wù)計(jì)劃 notify:通知 puppet variable:? $variable_name=value 數(shù)據(jù)類(lèi)型: 字符型:引號(hào)可有可無(wú);但單引號(hào)為強(qiáng)引用,雙引號(hào)為弱引用; 數(shù)值型:默認(rèn)均識(shí)別為字符串,僅在數(shù)值上下文才以數(shù)值對(duì)待; 數(shù)組:[]中以逗號(hào)分隔元素列表; 布爾型值:true, false; hash:{}中以逗號(hào)分隔k/v數(shù)據(jù)列表; 鍵為字符型,值為任意puppet支持的類(lèi)型;{ 'mon' => 'Monday', 'tue' => 'Tuesday', }; undef:未定義 ; 正則表達(dá)式: (?<ENABLED OPTION>:<PATTERN>) (?-<DISABLED OPTION>:<PATTERN>) OPTIONS: i:忽略字符大小寫(xiě); m:把.當(dāng)換行符; x:忽略<PATTERN>中的空白字符 (?i-mx:PATTERN) 不能賦值給變量 ,僅能用在接受=或!操作符的位置; puppet的變量類(lèi)型: facts: 由facter提供;top scope; 內(nèi)建變量: master端變量 agent端變量 parser變量 用戶自定義變量: 變量有作用域,稱為Scope; top scope: $::var_name node scope class scope
puppet流程控制語(yǔ)句: if語(yǔ)句: if CONDITION { ... } else { ... } CONDITION的給定方式: (1) 變量 (2) 比較表達(dá)式 (3) 有返回值的函數(shù)
if $osfamily =~ /(?i-mx:debian)/ { $webserver = 'apache2' } else { $webserver = 'httpd' }? package{"$webserver": ensure => installed, before => [ File['httpd.conf'], Service['httpd'] ], }? file{'httpd.conf': path => '/etc/httpd/conf/httpd.conf', source => '/root/manifests/httpd.conf', ensure => file, }? service{'httpd': ensure => running, enable => true, restart => 'systemctl restart httpd.service', subscribe => File['httpd.conf'], }
case語(yǔ)句: case CONTROL_EXPRESSION { case1: { ... } case2: { ... } case3: { ... } ... default: { ... } } CONTROL_EXPRESSION: (1) 變量 (2) 表達(dá)式 (3) 有返回值的函數(shù) 各case的給定方式: (1) 直接字串; (2) 變量 (3) 有返回值的函數(shù) (4) 正則表達(dá)式模式; (5) default ? case $osfamily { "RedHat": { $webserver='httpd' } /(?i-mx:debian)/: { $webserver='apache2' } default: { $webserver='httpd' } }? package{"$webserver": ensure => installed, before => [ File['httpd.conf'], Service['httpd'] ], }? file{'httpd.conf': path => '/etc/httpd/conf/httpd.conf', source => '/root/manifests/httpd.conf', ensure => file, }? service{'httpd': ensure => running, enable => true, restart => 'systemctl restart httpd.service', subscribe => File['httpd.conf'], } selector語(yǔ)句: CONTROL_VARIABLE ? { case1 => value1, case2 => value2, ... default => valueN, } CONTROL_VARIABLE的給定方法: (1) 變量 (2) 有返回值的函數(shù) 各case的給定方式: (1) 直接字串; (2) 變量 (3) 有返回值的函數(shù) (4) 正則表達(dá)式模式; (5) default 注意:不能使用列表格式;但可以是其它的selecor; $pkgname = $operatingsystem ? { /(?i-mx:(ubuntu|debian))/ => 'apache2', /(?i-mx:(redhat|fedora|centos))/ => 'httpd', default => 'httpd', }? package{"$pkgname": ensure => installed, } ? 示例2: $webserver = $osfamily ? { "Redhat" => 'httpd', /(?i-mx:debian)/ => 'apache2', default => 'httpd', }
package{"$webserver": ensure => installed, before => [ File['httpd.conf'], Service['httpd'] ], }? file{'httpd.conf': path => '/etc/httpd/conf/httpd.conf', source => '/root/manifests/httpd.conf', ensure => file, }? service{'httpd': ensure => running, enable => true, restart => 'systemctl restart httpd.service', subscribe => File['httpd.conf'], } puppet的類(lèi): 類(lèi):puppet中命名的代碼模塊,常用于定義一組通用目標(biāo)的資源,可在puppet全局調(diào)用; 類(lèi)可以被繼承,也可以包含子類(lèi); 語(yǔ)法格式: class NAME { ...puppet code... } class NAME(parameter1, parameter2) { ...puppet code... } 類(lèi)代碼只有聲明后才會(huì)執(zhí)行,調(diào)用方式: (1) include CLASS_NAME1, CLASS_NAME2, ... (2) class{'CLASS_NAME': attribute => value, } 示例1: class apache2 { $webpkg = $operatingsystem ? { /(?i-mx:(centos|redhat|fedora))/ => 'httpd', /(?i-mx:(ubuntu|debian))/ => 'apache2', default => 'httpd', }? package{"$webpkg": ensure => installed, }? file{'/etc/httpd/conf/httpd.conf': ensure => file, owner => root, group => root, source => '/tmp/httpd.conf', require => Package["$webpkg"], notify => Service['httpd'], }? service{'httpd': ensure => running, enable => true, } }? include apache2 示例2: class dbserver($pkgname) { package{"$pkgname": ensure => latest, }? service{"$pkgname": ensure => running, enable => true, } }? #include dbserver
if $operatingsystem == "CentOS" { $dbpkg = $operatingsystemmajrelease ? { 7 => 'mariadb-server', default => 'mysqld-server', } }? class{'dbserver': pkgname => $dbpkg, } 類(lèi)繼承的方式: class SUB_CLASS_NAME inherits PARENT_CLASS_NAME { ...puppet code... } 示例: class nginx { package{'nginx': ensure => installed, }? service{'nginx': ensure => running, enable => true, restart => '/usr/sbin/nginx -s reload', } }? class nginx::web inherits nginx { Service['nginx'] { subscribe => File['ngx-web.conf'], }? file{'ngx-web.conf': path => '/etc/nginx/conf.d/ngx-web.conf', ensure => file, source => '/root/manifests/ngx-web.conf', } }? class nginx::proxy inherits nginx { Service['nginx'] { subscribe => File['ngx-proxy.conf'], }? file{'ngx-proxy.conf': path => '/etc/nginx/conf.d/ngx-proxy.conf', ensure => file, source => '/root/manifests/ngx-proxy.conf', } }? include nginx::proxy 在子類(lèi)中為父類(lèi)的資源新增屬性或覆蓋指定的屬性的值: Type['title'] { attribute1 => value, ... } 在子類(lèi)中為父類(lèi)的資源的某屬性增加新值: Type['title'] { attribute1 +> value, ... } puppet模板: erb:模板語(yǔ)言,embedded ruby; puppet兼容的erb語(yǔ)法: https://docs.puppet.com/puppet/latest/reference/lang_template_erb.html file{'title': ensure => file, content => template('/PATH/TO/ERB_FILE'), } 文本文件中內(nèi)嵌變量替換機(jī)制: <%= @VARIABLE_NAME %> 示例: class nginx { package{'nginx': ensure => installed, }? service{'nginx': ensure => running, enable => true, require => Package['nginx'], } }? class nginx::web inherits nginx { file{'ngx-web.conf': path => '/etc/nginx/conf.d/ngx-web.conf', ensure => file, require => Package['nginx'], source => '/root/manifests/nginx/ngx-web.conf', }? file{'nginx.conf': path => '/etc/nginx/nginx.conf', ensure => file, content => template('/root/manifests/nginx.conf.erb'), require => Package['nginx'], }? Service['nginx'] { subscribe => [ File['ngx-web.conf'], File['nginx.conf'] ], } }? include nginx::web puppet模塊: 模塊就是一個(gè)按約定的、預(yù)定義的結(jié)構(gòu)存放了多個(gè)文件或子目錄的目錄,目錄里的這些文件或子目錄必須遵循一定格式的命名規(guī)范; puppet會(huì)在配置的路徑下查找所需要的模塊; MODULES_NAME: manifests/ init.pp files/ templates/ lib/ spec/ tests/ 模塊名只能以小寫(xiě)字母開(kāi)頭,可以包含小寫(xiě)字母、數(shù)字和下劃線;但不能使用”main"和"settings“; manifests/ init.pp:必須一個(gè)類(lèi)定義,類(lèi)名稱必須與模塊名稱相同; files/:靜態(tài)文件; puppet URL: puppet:///modules/MODULE_NAME/FILE_NAME templates/: tempate('MOD_NAME/TEMPLATE_FILE_NAME') lib/:插件目錄,常用于存儲(chǔ)自定義的facts以及自定義類(lèi)型; spec/:類(lèi)似于tests目錄,存儲(chǔ)lib/目錄下插件的使用幫助和范例; tests/:當(dāng)前模塊的使用幫助或使用范例文件; 注意: 1、puppet 3.8及以后的版本中,資源清單文件的文件名要與文件聽(tīng)類(lèi)名保持一致,例如某子類(lèi)名為“base_class::child_class”,其文件名應(yīng)該為child_class.pp; 2、無(wú)需再資源清單文件中使用import語(yǔ)句; 3、manifests目錄下可存在多個(gè)清單文件,每個(gè)清單文件包含一個(gè)類(lèi),其文件名同類(lèi)名;
puppet config命令: 獲取或設(shè)定puppet配置參數(shù); puppet config print [argument] puppet查找模塊文件的路徑:modulepath mariadb模塊中的清單文件示例: class mariadb($datadir='/var/lib/mysql') { package{'mariadb-server': ensure => installed, }? file{"$datadir": ensure => directory, owner => mysql, group => mysql, require => [ Package['mariadb-server'], Exec['createdir'], ], }? exec{'createdir': command => "mkdir -pv $datadir", require => Package['mariadb-server'], path => '/bin:/sbin:/usr/bin:/usr/sbin', creates => “$datadir", }? file{'my.cnf': path => '/etc/my.cnf', content => template('mariadb/my.cnf.erb'), require => Package['mariadb-server'], notify => Service['mariadb'], }? service{'mariadb': ensure => running, enable => true, require => [ Exec['createdir'], File["$datadir"], ], } } 實(shí)踐作業(yè): 開(kāi)發(fā)模塊: memcached nginx(反代動(dòng)態(tài)請(qǐng)求至httpd,work_process的值隨主機(jī)CPU數(shù)量而變化) jdk(輸出JAVA_HOME環(huán)境變量) tomcat mariadb httpd(反代請(qǐng)求至tomcat,ajp連接器;mpm允許用戶通過(guò)參數(shù)指定)
回顧:
puppet核心資源類(lèi)型:group, user, file, package, service, exec, cron, notify
puppet describe [-l] [type]
資源清單:manifests, *.pp
type{'title': attribute => value, ...}?引用:Type['title']
元參數(shù):
before/requirenotify/subscribe->, ~>
?
數(shù)據(jù)類(lèi)型:字符串、數(shù)值、布爾型、數(shù)組、hash、undef
正則表達(dá)式:
(?<enable_flag>-<disable_flag>:<PATTERN>)flag: i, m, x
變量:$variable,
FQN: $::scope1::scope2::variable $variable
編程元素:
流程控制:
if, case, selector, unless
類(lèi):
class class_name[($parameter1[=value1], $parameter2)] { ...puppet code...}class sub_class_name inherits class_name { ... puppet code ...} sub_class_name: base_class::sub_class_name
?
子類(lèi)中引用父類(lèi)的資源:
Type['title'] { attribute => value, atrribute +> value,}
?
聲明類(lèi):
include class_nameclass{'class_name': attribute => value,}
模板:
erb:Embedded RuBy <%= erb code %> <% erb code %> <%# erb code %>
file類(lèi)型的資源
content => template('/PATH/TO/ERB_FILE')
?
模塊:
modulepath配置參數(shù)指定的目錄路徑下(puppet config print modulepath); manifests/ init.pp (至少得存在一個(gè)與模塊名同名的類(lèi)) sub_class_name.pp files/ puppet:///modules/MOD_NAME/FILE_NAME templates/ template('MOD_NAME/ERB_FILE') tests/ # 當(dāng)前模塊的幫助 spec/ # 幫助和示例模塊
?
puppet(3)
standalone:puppet apply
standalone:
puppet apply -e 'include CLASS_NAME'
master/agent:agent每隔30分鐘到master端請(qǐng)求與自己相關(guān)的catalog
master: site manifest
node 'node_name' { ...puppet code...}
相關(guān)網(wǎng)站
程序包下載路徑:
https://yum.puppetlabs.com/
官方文檔:
https://docs.puppet.com/puppet/3/reference/
內(nèi)建函數(shù):
https://docs.puppet.com/puppet/3/reference/function.html
配置參數(shù)列表:
https://docs.puppet.com/puppet/3/reference/configuration.html
安裝部署 master/agent
部署master:
安裝程序包:facter, puppet, puppet-server
初始化master:
puppet master --no-daemonize --verbose
生成一個(gè)完整的配置參數(shù)列表:可能不可用
puppet master --genconfig puppet agent --genconfig # 在agent端運(yùn)行...
打印基于默認(rèn)配置生效的各配置參數(shù)列表:
puppet config <action> [--section SECTION_NAME]puppet config print
基于命令行設(shè)定某參數(shù)的值:
puppet config set
可以直接啟動(dòng)
systemctl start puppetmaster.service
puppet 默認(rèn)監(jiān)聽(tīng)的端口:tcp/8140
master端管理證書(shū)簽署:
puppet cert <action> " style="box-sizing: border-box; cursor: pointer; text-decoration: underline; outline: 0px; transition: all 0.2s ease-in-out; color: rgb(224, 224, 224);">--all
action: list sign revoke clean:吊銷(xiāo)指定的客戶端的證書(shū),并刪除與其相關(guān)的所有文件;
站點(diǎn)清單的定義:
主機(jī)名定義:
主機(jī)名(主機(jī)角色)#-機(jī)架-機(jī)房-運(yùn)營(yíng)商-區(qū)域.域名:www1-rack1-yz-unicom-bj.magedu.com
/etc/puppet/manifests/site.pp node 'base' { include ntp } node 'HOSTNAME' { ...puppet code... } node /PATTERN/ { ...puppet code... } node /node[0-9]+.magedu.com/ 節(jié)點(diǎn)定義的繼承: node NODE inherits PAR_NODE_DEF { ...puppet code... } nodes/
?
清單配置信息可模塊化組織:
databases.d/tomcatservers.d/nodes.d/:可通過(guò)多個(gè)pp文件分別定義各類(lèi)站點(diǎn)的清單;而后統(tǒng)一導(dǎo)入site.pp,方法如下:
site.pp文件使用中如下配置:
import 'nodes/*.pp'
多環(huán)境配置
默認(rèn)環(huán)境是production;
environmentpath =
puppet 3.4 之前的版本配置多環(huán)境的方法:
各環(huán)境配置:
/etc/puppet/environments/{production,development,testing}
master支持多環(huán)境:puppet.conf
[master]# modulepath=# manifest=environments = production, development, testing[production]modulepath=/etc/puppet/environments/production/modules/manifest=/etc/puppet/environments/production/manifests/site.pp[development]modulepath=/etc/puppet/environments/development/modules/manifest=/etc/puppet/environments/development/manifests/site.pp [testing]modulepath=/etc/puppet/environments/testing/modules/manifest=/etc/puppet/environments/testing/manifests/site.pp
puppet 3.6之后的版本配置多環(huán)境的方法:
master支持多環(huán)境:
(1) 配置文件puppet.conf
[master]environmentpath = $confdir/environments
(2) 在多環(huán)境配置目錄下為每個(gè)環(huán)境準(zhǔn)備一個(gè)子目錄
ENVIRONMENT_NAME/ manifests/ site.pp modules/
agent端:
[agent]environment = { production|development | testing }
?
額外配置文件:
文件系統(tǒng):fileserver.conf
認(rèn)證(URL):auth.conf
?
puppet kick: agent: puppet.conf [agent] listen = true auth.conf path /run method save auth any allow master.magedu.com path / auth any master端: puppet kick puppet kick [--host <HOST>] [--all] GUI: dashboard foreman: 項(xiàng)目實(shí)踐: haproxy(keepalived) cache --> varnish imgs--> nginx server app --> httpd+tomcat --> mariadb-server zabbix --> zabbix-server zabbix-agent
? ?
生產(chǎn)環(huán)境案例:haproxy.pp
class haproxy { # init haproxy class init { file { '/etc/init.d/haproxy': ensure => present, source => "puppet:///modules/haproxy/haproxy/init.d/haproxy.init", group => "root", owner => "root", mode => "0755", } exec { 'init_haproxy_service': subscribe => File['/etc/init.d/haproxy'], refreshonly => true, command => "/sbin/chkconfig --add haproxy; /sbin/chkconfig --level 235 haproxy off;", } service { 'haproxy': ensure => running, enable => true, hasrestart => true, hasstatus => true, # restart => true, } } # init haproxy.cfg class conf { # file { '/usr/local/haproxy','/usr/local/haproxy/etc': file { ['/usr/local/haproxy','/usr/local/haproxy/etc']: ensure => directory, before => File['/usr/local/haproxy/etc/haproxy.cfg'], group => "root", owner => "root", mode => "0755", } class piccenter { file { '/usr/local/haproxy/etc/haproxy.cfg': ensure => present, source => "puppet:///modules/haproxy/haproxy/conf/haproxy_piccenter.cfg", group => "root", owner => "root", mode => "0644", } } } }
keepalived.pp
class keepalived { # init haproxy class init { file { '/etc/init.d/keepalived': ensure => present, source => "puppet:///modules/haproxy/keepalived/init.d/keepalived.init", group => "root", owner => "root", mode => "0755", } exec { 'init_keepalived_service': subscribe => File['/etc/init.d/keepalived'], refreshonly => true, command => "/sbin/chkconfig --add keepalived; /sbin/chkconfig --level 235 keepalived off;", } service { 'keepalived': ensure => running, enable => true, hasrestart => true, hasstatus => true, restart => true, } } }
? ? ? ? ?