Puppet
理論
定義: Puppet 是一個跨平臺的集中化配置管理系統(tǒng),它使用自有的描述語言侨糟,可管理配置文件拨拓、用戶苏遥、Cron、軟件包彬犯、系統(tǒng)服務(wù)等向楼,Puppet把這些統(tǒng)稱為“資源”。
運(yùn)維的三個層次谐区,以及對應(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ī)模型:手動應(yīng)用清單湖蜕;
master/agent:由agent周期性地向Master請求清單并自動應(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如何抽象資源的宋列?): 類型:具有類似屬性的組件昭抒,例如package、service炼杖、file戈鲁; 將資源的屬性或狀態(tài)與其實現(xiàn)方式分離; 僅描述資源的目標(biāo)狀態(tài)嘹叫,也即期望其實現(xiàn)的結(jié)果狀態(tài),而不是具體過程诈乒; RAL由“類型”和提供者(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:列出所有資源類型; -s:顯示指定類型的簡要幫助信息; -m:顯示指定類型的元參數(shù)喂饥,一般與-s一同使用消约; 資源定義:向資源類型的屬性賦值來實現(xiàn),可稱為資源類型實例化员帮; 定義了資源實例的文件即清單或粮,manifest; 定義資源的語法: type {'title': attribute1 => value1, atrribute2 => value2, …… } 注意:type必須使用小寫字符捞高;title是一個字符串氯材,在同一類型中必須惟一; 資源屬性中的三個特殊屬性: Namevar硝岗, 可簡稱為name氢哮; ensure:資源的目標(biāo)狀態(tài); Provider:指明資源的管理接口型檀; 資源類型: 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:過期時間 录语; home:家目錄倍啥; shell:默認(rèn)shell類型; 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:程序包來源,僅對不會自動下載相關(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:手動定義啟動命令啊犬; stop: status: restart:Specify a restart command manually. If left unspecified, the service will be stopped and then started. 通常用于定義reload操作灼擂; 資源引用: Type['title'] 類型的首字母必須大寫; 資源有特殊屬性: 名稱變量(namevar): name可省略觉至,此時將由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ā)生改變后會通知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:類型為普通文件,其內(nèi)容由content屬性生成或復(fù)制由source屬性指向的文件路徑來創(chuàng)建孽锥; link:類型為符號鏈接文件嚼黔,必須由target屬性指明其鏈接的目標(biāo)文件; directory:類型為目錄惜辑,可通過source指向的路徑復(fù)制生成唬涧,recurse屬性指明是否遞歸復(fù)制; path:文件路徑盛撑; source:源文件碎节; content:文件內(nèi)容; target:符號鏈接的目標(biāo)文件抵卫; owner:屬主 group:屬組 mode:權(quán)限狮荔; atime/ctime/mtime:時間戳; 通知元參數(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 資源類型:group, user, package, service, file慨亲;exec, cron, notify, ... puppet describe
? Puppet(2)
資源類型: 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:文件路徑,僅此路徑表示的文件不存在時刑棵,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:此屬性指定一個命令蛉签,此命令正常(退出碼為0)運(yùn)行時胡陪,當(dāng)前command才會運(yùn)行茂附; unless:此屬性指定一個命令,此命令非正常(退出碼為非0)運(yùn)行時督弓,當(dāng)前command才會運(yùn)行; refresh:重新執(zhí)行當(dāng)前command的替代命令乒验; refreshonly:僅接收到訂閱的資源的通知時方才運(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:以哪個用戶的身份運(yùn)行命令 target:添加為哪個用戶的任務(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:信息名稱;? 核心類型: group: 組 user:用戶 packge:程序包 service:服務(wù) file:文件 exec:執(zhí)行自定義命令鳄厌,要求冪等 cron:周期性任務(wù)計劃 notify:通知 puppet variable:? $variable_name=value 數(shù)據(jù)類型: 字符型:引號可有可無荞胡;但單引號為強(qiáng)引用,雙引號為弱引用了嚎; 數(shù)值型:默認(rèn)均識別為字符串泪漂,僅在數(shù)值上下文才以數(shù)值對待; 數(shù)組:[]中以逗號分隔元素列表歪泳; 布爾型值:true, false萝勤; hash:{}中以逗號分隔k/v數(shù)據(jù)列表; 鍵為字符型呐伞,值為任意puppet支持的類型敌卓;{ 'mon' => 'Monday', 'tue' => 'Tuesday', }; undef:未定義 伶氢; 正則表達(dá)式: (?<ENABLED OPTION>:<PATTERN>) (?-<DISABLED OPTION>:<PATTERN>) OPTIONS: i:忽略字符大小寫趟径; m:把.當(dāng)換行符; x:忽略<PATTERN>中的空白字符 (?i-mx:PATTERN) 不能賦值給變量 癣防,僅能用在接受=或!操作符的位置蜗巧; puppet的變量類型: facts: 由facter提供;top scope劣砍; 內(nèi)建變量: master端變量 agent端變量 parser變量 用戶自定義變量: 變量有作用域惧蛹,稱為Scope; top scope: $::var_name node scope class scope
puppet流程控制語句: if語句: 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語句: 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語句: 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的類: 類:puppet中命名的代碼模塊掠兄,常用于定義一組通用目標(biāo)的資源像云,可在puppet全局調(diào)用锌雀; 類可以被繼承,也可以包含子類迅诬; 語法格式: class NAME { ...puppet code... } class NAME(parameter1, parameter2) { ...puppet code... } 類代碼只有聲明后才會執(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, } 類繼承的方式: 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 在子類中為父類的資源新增屬性或覆蓋指定的屬性的值: Type['title'] { attribute1 => value, ... } 在子類中為父類的資源的某屬性增加新值: Type['title'] { attribute1 +> value, ... } puppet模板: erb:模板語言,embedded ruby侈贷; puppet兼容的erb語法: 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模塊: 模塊就是一個按約定的惩歉、預(yù)定義的結(jié)構(gòu)存放了多個文件或子目錄的目錄,目錄里的這些文件或子目錄必須遵循一定格式的命名規(guī)范俏蛮; puppet會在配置的路徑下查找所需要的模塊撑蚌; MODULES_NAME: manifests/ init.pp files/ templates/ lib/ spec/ tests/ 模塊名只能以小寫字母開頭,可以包含小寫字母搏屑、數(shù)字和下劃線争涌;但不能使用”main"和"settings“; manifests/ init.pp:必須一個類定義辣恋,類名稱必須與模塊名稱相同亮垫; files/:靜態(tài)文件; puppet URL: puppet:///modules/MODULE_NAME/FILE_NAME templates/: tempate('MOD_NAME/TEMPLATE_FILE_NAME') lib/:插件目錄抑党,常用于存儲自定義的facts以及自定義類型包警; spec/:類似于tests目錄,存儲lib/目錄下插件的使用幫助和范例底靠; tests/:當(dāng)前模塊的使用幫助或使用范例文件害晦; 注意: 1、puppet 3.8及以后的版本中暑中,資源清單文件的文件名要與文件聽類名保持一致壹瘟,例如某子類名為“base_class::child_class”,其文件名應(yīng)該為child_class.pp鳄逾; 2稻轨、無需再資源清單文件中使用import語句; 3雕凹、manifests目錄下可存在多個清單文件殴俱,每個清單文件包含一個類,其文件名同類名枚抵;
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"], ], } } 實踐作業(yè): 開發(fā)模塊: memcached nginx(反代動態(tài)請求至httpd,work_process的值隨主機(jī)CPU數(shù)量而變化) jdk(輸出JAVA_HOME環(huán)境變量) tomcat mariadb httpd(反代請求至tomcat汽摹,ajp連接器李丰;mpm允許用戶通過參數(shù)指定)
回顧:
puppet核心資源類型: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ù)類型:字符串、數(shù)值逼泣、布爾型趴泌、數(shù)組舟舒、hash、undef
正則表達(dá)式:
(?<enable_flag>-<disable_flag>:<PATTERN>)flag: i, m, x
變量:$variable,
FQN: $::scope1::scope2::variable $variable
編程元素:
流程控制:
if, case, selector, unless
類:
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
?
子類中引用父類的資源:
Type['title'] { attribute => value, atrribute +> value,}
?
聲明類:
include class_nameclass{'class_name': attribute => value,}
模板:
erb:Embedded RuBy <%= erb code %> <% erb code %> <%# erb code %>
file類型的資源
content => template('/PATH/TO/ERB_FILE')
?
模塊:
modulepath配置參數(shù)指定的目錄路徑下(puppet config print modulepath)嗜憔; manifests/ init.pp (至少得存在一個與模塊名同名的類) 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端請求與自己相關(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
生成一個完整的配置參數(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
可以直接啟動
systemctl start puppetmaster.service
puppet 默認(rèn)監(jiān)聽的端口:tcp/8140
master端管理證書簽署:
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:吊銷指定的客戶端的證書秃励,并刪除與其相關(guān)的所有文件;
站點清單的定義:
主機(jī)名定義:
主機(jī)名(主機(jī)角色)#-機(jī)架-機(jī)房-運(yùn)營商-區(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é)點定義的繼承: node NODE inherits PAR_NODE_DEF { ...puppet code... } nodes/
?
清單配置信息可模塊化組織:
databases.d/tomcatservers.d/nodes.d/:可通過多個pp文件分別定義各類站點的清單吉捶;而后統(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)境配置目錄下為每個環(huán)境準(zhǔn)備一個子目錄
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: 項目實踐: 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, } } }
? ? ? ? ?