puppet

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, } } }
? ? ? ? ?

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末帚稠,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子床佳,更是在濱河造成了極大的恐慌滋早,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,372評論 6 498
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件砌们,死亡現(xiàn)場離奇詭異杆麸,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)浪感,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,368評論 3 392
  • 文/潘曉璐 我一進(jìn)店門昔头,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人影兽,你說我怎么就攤上這事揭斧。” “怎么了峻堰?”我有些...
    開封第一講書人閱讀 162,415評論 0 353
  • 文/不壞的土叔 我叫張陵讹开,是天一觀的道長。 經(jīng)常有香客問我捐名,道長旦万,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,157評論 1 292
  • 正文 為了忘掉前任镶蹋,我火速辦了婚禮成艘,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘贺归。我一直安慰自己淆两,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,171評論 6 388
  • 文/花漫 我一把揭開白布牧氮。 她就那樣靜靜地躺著琼腔,像睡著了一般。 火紅的嫁衣襯著肌膚如雪踱葛。 梳的紋絲不亂的頭發(fā)上丹莲,一...
    開封第一講書人閱讀 51,125評論 1 297
  • 那天光坝,我揣著相機(jī)與錄音,去河邊找鬼甥材。 笑死盯另,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的洲赵。 我是一名探鬼主播鸳惯,決...
    沈念sama閱讀 40,028評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼叠萍!你這毒婦竟也來了芝发?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,887評論 0 274
  • 序言:老撾萬榮一對情侶失蹤苛谷,失蹤者是張志新(化名)和其女友劉穎辅鲸,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體腹殿,經(jīng)...
    沈念sama閱讀 45,310評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡独悴,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,533評論 2 332
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了锣尉。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片刻炒。...
    茶點故事閱讀 39,690評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖自沧,靈堂內(nèi)的尸體忽然破棺而出坟奥,到底是詐尸還是另有隱情,我是刑警寧澤拇厢,帶...
    沈念sama閱讀 35,411評論 5 343
  • 正文 年R本政府宣布筏勒,位于F島的核電站,受9級特大地震影響旺嬉,放射性物質(zhì)發(fā)生泄漏管行。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,004評論 3 325
  • 文/蒙蒙 一邪媳、第九天 我趴在偏房一處隱蔽的房頂上張望捐顷。 院中可真熱鬧,春花似錦雨效、人聲如沸迅涮。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽叮姑。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間传透,已是汗流浹背耘沼。 一陣腳步聲響...
    開封第一講書人閱讀 32,812評論 1 268
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點兒被人妖公主榨干…… 1. 我叫王不留朱盐,地道東北人群嗤。 一個月前我還...
    沈念sama閱讀 47,693評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像兵琳,于是被迫代替她去往敵國和親狂秘。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,577評論 2 353

推薦閱讀更多精彩內(nèi)容

  • 一.puppet介紹 (1)什么是puppetpuppet是一種重量級自動化運(yùn)維工具躯肌,實現(xiàn)自動化運(yùn)維以及能夠幫助系...
    楠人幫閱讀 1,050評論 0 3
  • 1.puppet 是什么 puppet是一個開源的軟件自動化配置和部署工具者春,很多大型IT公司均在使用puppet對...
    milo_e1ce閱讀 4,878評論 0 4
  • puppet簡介 puppet是一套IT基礎(chǔ)設(shè)施自動化管理工具,可以管理其整個生命周期清女,其官方網(wǎng)站:www.pup...
    魏鎮(zhèn)坪閱讀 3,909評論 0 5
  • Puppet部署與應(yīng)用 前言:到目前為止碧查,我們已經(jīng)搭建了很多的服務(wù)器,每一臺服務(wù)器都需要執(zhí)行很多的命令校仑,給我的感覺...
    李偉銘MIng閱讀 2,703評論 0 3
  • 每次看別人的公眾號 故事的開頭一般都是這樣的 我有一個朋友…… 媽蛋 別人的朋友可以三個一組湊齊一年的公眾號推文 ...
    小小俠閱讀 608評論 2 4