Puppet集中配置管理系統

Puppet是一個配置管理工具,典型的,puppet是一個C/S結構,當然,這裏的C(客戶端)可以有很多,因此,也可以說是一個星形結構,所有的puppet客戶端同一個服務器端的puppet通訊。每個puppet客戶端每半小時連接一次客戶端(時間也可以設置爲其他),下載最新的配置文件,並且嚴格按照配置文件來配置服務器,配置完成以後,puppet客戶端可以反饋給服務器端一個消息,如果出錯,也會給服務器端反饋一個消息。下面是一個典型的puppet配置的數據流動情況

1 (管理員)管理員編寫puppet manifest,提交到svn (svn db  svn db備份 ) 只需要備份svn,你就備份了所有的服務器配置 哪怕是上萬臺計算機 這裏的備份數據不會超過100M

2 svn取出所有的puppet配置信息

3 puppet master)客戶端facter收集服務器信息發送給puppet master (連接是基於ssl和證書的,保證了安全性)

4 puppet master 根據收集到的客戶端信息,編譯manifest,發回到客戶端

5(多個puppet clientpuppet執行從服務器收到的manifest,完成對機器的配置

穩定性

Puppet與其他手工操作工具由一個最大區別就是puppet的配置具有穩定性,因此你可以多次執行puppet,一旦你更新了你的配置文件,puppet就會根據配置文件夾更改你的機器配置,通常每30分鐘檢查一次,puppet會讓你的系統狀態同配置文件所要求的狀態保持一致(比如你配置文件裏要求ssh服務必須開啓,加入不小心把ssh服務關閉了,那麼下一次執行puppet的時候,puppet會發現這個異常,然後會開啓ssh服務,以使系統狀態和配置文件保持一致) puppet就像一個魔術師 會讓你混亂的系統收斂到puppet配置文件想要的狀態,可以使用puppet管理服務器的整個生命週期,從初始化到退役,不同於傳統的例如sunjumpstart或者redhatkickstartpuppet可以長年讓服務器保持最新狀態,只要一開始就正確的配置他們,然後再也不用去管他們,通常puppet用戶只需要給機器安裝好puppet並讓他們運行,然後剩餘的工作就交給puppet來完成

Puppet的細節和原理

Puppet的目的時爲了讓你只集中於你要管理的目標,而忽略實現的細節,例如命令名 參數或者文件格式,puppet把系統裏面的用戶 軟件包 服務等看作是資源,puppet的作用就是管理這些資源以及資源之間的相互聯繫。

Puppet採用了非常簡單的C/S架構,所有數據的交互都通過ssl進行,以保證安全,它的工作流程入圖所示:

spacer.gifPuppet clientpuppet master

spacer.gifConnet1plugins

spacer.gif                 2

spacer.gifspacer.gifFacter3ENC

                                4

Apply catalognode $certname(

spacer.gifspacer.gif  $conf = linux

  Class {‘ssh’:

    Ssh_key=>’$file’,

}

spacer.gif)

                       5

spacer.gifspacer.gifFile?Comple catelog functions

              6

spacer.gifspacer.gifReportfileserver

 8               7   

Finishreport

 

1 客戶端puppetmaster發起認證請求,或使用帶簽名的證書

2 Master告訴client你是合法的

3 客戶端puppetd調用fasterfaster探測出主機的一些變量,例如主機名,內存大小,ip地址等,puppet將這些信息通過ssl連接發送到服務器端

4 服務器端的puppet master檢測客戶端的主機名,然後找到manifest對應的node配置,並對該部分內容進行解析。Facter送過來的信息可以作爲變量處理,node牽扯到的代碼才解析,其他沒牽扯到的代碼不解析。解析分爲幾個階段,首先是語法檢查,如果語法錯誤就報錯;如果語法沒錯,就繼續解析,解析的結果生成一箇中間的僞代碼(catelog),然後把僞代碼發給客戶端

5 客戶端接收到僞代碼 並且執行

6 客戶端在執行時判斷有沒有file文件,如果有 則向fileserver發起請求

7 客戶端判斷有沒有配置report,如果已配置,則把執行結果發送給服務器

8服務器端把客戶端的執行結果寫入日誌,併發送給報告系統

 

 

 

 

@@@@@@@@@@@@@@   puppert  @@@@@@@@@@@@@@@@@@@

系統環境:rhel6.3 selinux and iptables disabled

Server:192.168.0.201   desktop1.example.com   puppet master

Client: 192.168.0.202   desktop2.example.com   puppet agent

Client: 192.168.0.203   desktop3.example.com   puppet agent

重要:Server和所有的client之間需要解析,以及時間同步,不然會驗證失敗

 

Server

yum localinstall -y rubygems-1.3.7-1.el6.noarch.rpm

搭建yum倉庫:【puppet】和【ruby]這兩個

Yum install -y puppet-server

 

/etc/puppet配置目錄:

組織結構如下:

-puppet.conf     主配置文件,詳細內容可執行puppet --genconfig

-fileserver.conf   文件服務器配置文件

-auth.conf        認證配置文件

-autosign.conf    自動驗證配置文件

-tagmail.conf     郵件配置文件(將錯誤信息發送此)

-manifests        文件存儲目錄(puppet會先讀取該目錄的.pp文件,<site.pp>

-node

-puppetclient.pp

-site.pp      定義puppet相關的變量和默認配置

-modules.pp   加載class類模塊文件(include syslog

-modules      定義模塊

-syslog     syslog爲例

-file

-manifests

-init.pp    class類配置

-templates    模塊配置目錄

-syslog.erb   erb模塊

Puppet第一個執行的代碼是/etc/puppet/manifest/site.pp,因此這個文件必須存在,而且其他的代碼也要通過該文件來調用

touch /etc/puppet/manifest/site.pp

沒有此文件puppet master無法啓動,配置後面在定義

 Service puppetmaster start   啓動puppetmaster

Netstat -antlp |grep ruby

Tcp      8140      listen 1596/ruby

 

Client端:

只需安裝puppet即可,安裝方法同server端:yum install -y puppet

##客戶端連接到puppet master:

Puppet agent --server=desktop1.example.com --no-daemonize --veibose

   Infocreating a new SSL key for desktop2.example.com

   Info:  caching certificate for ca

   Info:  cteating a new SSL certificate request for desktop2.example.com

Info(information)的縮寫 信息 知料 情報 通知

Clientmaster發出證書驗證請求,然後等待master簽名並返回證書

參數 --server指定了需要連接的puppet master的名字或是地址,默認連接名爲puppet的主機

如果修改默認連接主機可以修改/etc/sysconfig/puppet文件中的PUPPET_SERVER=puppet選項

參數 --no-daemonizepuppet客戶端運行在前臺

參數--verbose使客戶端輸出詳細的日誌

 

master端:

Puppet cert list    顯示所有等待簽名的證書

puppet cert sign desktop2.example.com   簽名證書

## 如果同時簽名所有證書,執行以下命令:

Puppet cert sign --all

Puppet cert clean desktop2.example.com  刪除簽名證書

 

在對證書籤名後的兩分鐘後,在agent端上可以看到如下輸出:

Info:caching certification for desktop2.example.com

Starting puppet client version 3.0.0

Info:caching certificate_revocation_list for ca

Info:applying configuration version ‘1349536603’

Finished catalog run in 0.13 seconds

自動驗證:

server端,編譯puppet.conf文件:

Vim /etc/puppet/puppet.conf

[main]

Autosign = true 允許所有客戶端認證

/etc/puppet 目錄下創建autosign.conf文件,內容如下:

 Vim /etc/puppet/autosign.conf

*.example.com  表示允許所有example.com域的主機

Service puppetmaster reload

 

client端只需執行:

server puppet start

 在實際中有時會修改client端的主機名,這樣就需要重新生成證書:

   1 server端執行:puppet cert --clean desktop2.example.com

你要刪除的原client端主機名

   2 client 端執行 : rm -fr /var/lib/puppet/ssl/*

Puppet agent --server=puppet.example.com

 

 

Puppet資源定義

一下資源均可在

      

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

server1

8個軟件 在打開服務 /etc/init.d/puppertmaster start

server2

7個軟件 在打開服務 /etc/init.d/puppert start  

發送請求 puppet agent --server server1.example.com --no-daemonize -vt

server1

puppet cert list   顯示所有的等待簽名的證書   

puppet cert list --all

puppet cert sign server2.example.com  ##發送證書

server2

puppet agent --server server1.example.com --no-daemonize -vt   

## 查看發送的證書

server3

7個軟件

server1 cd /etc/puppet  

vim autosign.conf(自創文件)

*.example.com

vim puppet.conf

在【main】目錄下加  autosign = true

/etc/init.d/puppetmaster reload

server3

puppet agent --server server1.example.com --no-daemonize -vt

  ### 即可發送請求成功

server1

puppet cert list --all

puppet cert clean server2.example.com

puppet cert list --all

server2

puppet agent --server server1.example.com --no-daemonize -vt

###  會有報錯  因爲修改了配製文件 得到了認證 發送請求自動成功

cd /var/lib/puppet/ssl  rpm -qf /var/lib/puppet/ssl  ls  rm -fr *

刪除之後 在向master發送認證請求 就不會報錯了 若再有報錯就重啓一下puppetmaster  reload

server1

puppet cert list --all 即可看到三個證書請求

server1

cd manifests/   vim site.pp  (自創)

file {

        "/tmp/testfile":

        content => "www.westos.org"

}

server2

puppet agent --server server1.example.com --no-daemonize -vt 即可

server1變動的東西cat /tmptestfile    md5sum /tmp/testfile

vim /tmp/testfile   隨便加一些東西在發送請求可看到變動

puppet agent --server server1.example.com --no-daemonize -vt

cat /tmp/testfile 會看到server2/tmp/testfile 文件已經被主服務器更改了

server2server1操縱

 

 

 

 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章