零基礎學習Puppet自動化配置管理系列文檔mysql
將基礎環境模塊部署到puppetmaster端以後就能夠初始化全部節點了,接下來就是部署應用代碼了。衆所周知,一個企業中應用代碼的編寫並非運維一我的完成的,並且代碼的上線也不是一次性完成的。標準的架構應該由開發、測試、生產三個組成,對應到puppetmaster裏面應該有3套代碼纔對。並且每套代碼都應該對應到本身的環境中,而代碼的變動更應該經過版本控制工具進行管理,好比svn、git等。 接下來咱們爲puppetmaster創造3個環境,它們分別是開發環境(kissdev)、測試環境(kissqa)、生產環境(kissprd).git
在標籤[master]中添加environments環境,其次建立對應的環境標籤及配置sql
[root@puppetmaster ~]# vim /etc/puppet/puppet.conf [main] logdir = /var/log/puppet rundir = /var/run/puppet ssldir = $vardir/ssl [agent] classfile = $vardir/classes.txt localconfig = $vardir/localconfig server = puppetmaster.kisspuppet.com certname = puppetmaster_cert.kisspuppet.com [master] certname = puppetmaster.kisspuppet.com environments = kissdev,kisstmq,kissprd #添加三個環境的標籤名稱 [kissdev] modulepath = $confdir/environments/kissdev/environment/modules:$confdir/environments/kissdev/application/modules #設置環境的搜索路徑 manifest = $confdir/environments/kissdev/manifests/site.pp #設置環境的site.pp文件位置 fileserverconfig = /etc/puppet/fileserver.conf.kissdev #設置環境的fileserver [kissmq] modulepath = $confdir/environments/kissmq/environment/modules:$confdir/environments/kisstest/application/modules manifest = $confdir/environments/kisstest/manifests/site.pp fileserverconfig = /etc/puppet/fileserver.conf.kisstest [kissprd] modulepath = $confdir/environments/kissprd/environment/modules:$confdir/environments/kissprd/application/modules manifest = $confdir/environments/kissprd/manifests/site.pp fileserverconfig = /etc/puppet/fileserver.conf.kissprd
順便解釋一下:爲何在每一個環境下會有environment和application兩個目錄,其中environment目錄是存放基礎環境模塊的,好比puppet、yum等;而application目錄是存在應用環境模塊的,好比apache、mysql等。固然也能夠放在同一個目錄下,若是應用多的話還能夠將application進行拆分,一切都是爲了方便管理而考慮。apache
[root@puppetmaster environments]# mkdir kissdev [root@puppetmaster environments]# mkdir kissdev/{application/modules,environment/modules} -p [root@puppetmaster environments]# tree . . └── kissdev ├── application │ └── modules #存放應用的模塊 └── environment └── modules #存放基礎環境模塊 5 directories, 0 files [root@puppetmaster environments]# cp kissdev kissmq -rp [root@puppetmaster environments]# cp kissdev kissprd -rp [root@puppetmaster environments]# tree . . ├── kissdev │ ├── application │ │ └── modules │ └── environment │ └── modules ├── kissmq │ ├── application │ │ └── modules │ └── environment │ └── modules └── kissprd ├── application │ └── modules └── environment └── modules 15 directories, 0 files
其中puppet和yum模塊屬於基礎環境模塊,motd屬於應用環境模塊vim
[root@puppetmaster environments]# mv /etc/puppet/modules/puppet kissprd/environment/modules/ [root@puppetmaster environments]# mv /etc/puppet/modules/yum kissprd/environment/modules/ [root@puppetmaster environments]# mv /etc/puppet/modules/motd kissprd/application/modules/
[root@puppetmaster environments]# cp /etc/puppet/manifests kissprd/ -r
複製完成後整個環境以下微信
[root@puppetmaster environments]# tree kissprd/ kissprd/ ├── application │ └── modules │ └── motd │ ├── files │ │ └── etc │ │ └── motd │ ├── manifests │ │ └── init.pp │ └── templates ├── environment │ └── modules │ ├── puppet │ │ ├── files │ │ ├── manifests │ │ │ ├── config.pp │ │ │ ├── init.pp │ │ │ ├── install.pp │ │ │ ├── params.pp │ │ │ └── service.pp │ │ └── templates │ │ └── puppet.conf.erb │ └── yum │ ├── files │ │ ├── etc │ │ │ └── yum.conf │ │ └── PM-GPG-KEY │ │ ├── RPM-GPG-KEY-puppet-release │ │ ├── RPM-GPG-KEY-redhat-release-rhel5 │ │ └── RPM-GPG-KEY-redhat-release-rhel6 │ ├── manifests │ │ ├── config.pp │ │ ├── init.pp │ │ ├── install.pp │ │ └── params.pp │ └── templates └── manifests └── site.pp 20 directories, 17 files
由於模塊已經移除,其次默認環境production已經再也不使用了。架構
[root@puppetmaster environments]# >/etc/puppet/manifests/site.pp
[root@puppetmaster ~]# cp /etc/puppet/fileserver.conf{,.kissdev} [root@puppetmaster ~]# cp /etc/puppet/fileserver.conf{,.kissqa} [root@puppetmaster ~]# cp /etc/puppet/fileserver.conf{,.kissprd} [root@puppetmaster ~]# ll /etc/puppet/ total 88 -rw-r--r-- 1 root root 2569 Jan 7 07:51 auth.conf -rw-r--r-- 1 root root 17 Mar 9 17:54 autosign.conf.bak drwxr-xr-x 5 root root 4096 Mar 27 22:33 environments -rw-r--r-- 1 root root 381 Jan 7 07:49 fileserver.conf -rw-r--r-- 1 root root 381 Mar 27 22:46 fileserver.conf.kissdev #指向kissdev環境 -rw-r--r-- 1 root root 381 Mar 27 22:46 fileserver.conf.kissprd #指向kissmq環境 -rw-r--r-- 1 root root 381 Mar 27 22:46 fileserver.conf.kissqa #指向kissdev環境 drwxr-xr-x 2 root root 4096 Mar 25 05:23 manifests drwxr-xr-x 2 root root 4096 Mar 27 22:40 modules -rw-r--r-- 1 root root 1063 Mar 27 21:55 puppet.conf -rw-r--r-- 1 root root 853 Mar 9 00:48 puppet.conf.bak -rw-r--r-- 1 root root 42031 Mar 9 03:25 puppet.conf.out
七、重啓puppetmaster服務app
[root@puppetmaster ~]# /etc/init.d/puppetmaster restart Stopping puppetmaster: [ OK ] Starting puppetmaster: [ OK ]
八、節點測試驗證運維
[root@agent1 ~]# >/etc/motd You have new mail in /var/spool/mail/root [root@agent1 ~]# puppet agent -t #默認請求的是production環境,因爲此環境裏面沒有模塊全部不更新 info: Caching catalog for agent1_cert.kisspuppet.com info: Applying configuration version '1395931884' notice: Finished catalog run in 0.02 seconds [root@agent1 ~]# puppet agent -t --environment=kissprd #環境指向kissprd info: Caching catalog for agent1_cert.kisspuppet.com info: Applying configuration version '1395931962' notice: /Stage[main]/Motd/File[/etc/motd]/content: --- /etc/motd 2014-03-27 22:52:27.000000000 +0800 +++ /tmp/puppet-file20140327-26204-29bst1-0 2014-03-27 22:52:44.000000000 +0800 @@ -0,0 +1,3 @@ +-- -- +--------puppet test--------- +-- -- info: FileBucket got a duplicate file {md5}d41d8cd98f00b204e9800998ecf8427e info: /Stage[main]/Motd/File[/etc/motd]: Filebucketed /etc/motd to puppet with sum d41d8cd98f00b204e9800998ecf8427e notice: /Stage[main]/Motd/File[/etc/motd]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}87ea3a1af8650395038472457cc7f2b1' notice: Finished catalog run in 0.68 seconds [root@agent1 ~]# cat /etc/motd -- -- --------puppet test--------- -- --
九、節點更改環境svn
若是節點是主動同步的方式,應該在puppet.conf文件中添加environment配置
[root@agent1 ~]# vim /etc/puppet/puppet.conf ### config by puppet ### [main] logdir = /var/log/puppet rundir = /var/run/puppet ssldir = $vardir/ssl [agent] classfile = $vardir/classes.txt localconfig = $vardir/localconfig server = puppetmaster.kisspuppet.com certname = agent1_cert.kisspuppet.com runinterval = 10 environment =kissprd #添加默認環境爲kissprd
十、繼續測試
[root@agent1 ~]# puppet agent -t info: Caching catalog for agent1_cert.kisspuppet.com info: Applying configuration version '1395931962' notice: /Stage[main]/Motd/File[/etc/motd]/content: --- /etc/motd 2014-03-27 22:55:43.000000000 +0800 +++ /tmp/puppet-file20140327-30010-8ada2g-0 2014-03-27 22:56:19.000000000 +0800 @@ -0,0 +1,3 @@ +-- -- +--------puppet test--------- +-- -- info: FileBucket got a duplicate file {md5}d41d8cd98f00b204e9800998ecf8427e info: /Stage[main]/Motd/File[/etc/motd]: Filebucketed /etc/motd to puppet with sum d41d8cd98f00b204e9800998ecf8427e notice: /Stage[main]/Motd/File[/etc/motd]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}87ea3a1af8650395038472457cc7f2b1' notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content: --- /etc/puppet/puppet.conf 2014-03-27 22:56:14.000000000 +0800 +++ /tmp/puppet-file20140327-30010-cmjg48-0 2014-03-27 22:56:19.000000000 +0800 @@ -10,4 +10,3 @@ server = puppetmaster.kisspuppet.com certname = agent1_cert.kisspuppet.com runinterval = 10 - environment =kissprd info: FileBucket got a duplicate file {md5}43df60b1aa2638c5f10aa7e6be892b77 info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Filebucketed /etc/puppet/puppet.conf to puppet with sum 43df60b1aa2638c5f10aa7e6be892b77 notice: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]/content: content changed '{md5}43df60b1aa2638c5f10aa7e6be892b77' to '{md5}8c67cb8c039bb6436556b91f0c6678c4' info: /Stage[main]/Puppet::Config/File[/etc/puppet/puppet.conf]: Scheduling refresh of Class[Puppet::Service] info: Class[Puppet::Service]: Scheduling refresh of Service[puppet] notice: /Service[puppet]/ensure: ensure changed 'stopped' to 'running' notice: /Service[puppet]: Triggered 'refresh' from 1 events notice: Finished catalog run in 0.68 seconds [root@agent1 ~]# cat /etc/motd -- -- --------puppet test--------- -- --
備註: 記得設置puppet模塊中的puppet.conf.erb模板,不然會被還原哦。
一、puppetmaster端有三套環境,那麼如何管理呢,接下來就應該考慮版本控制系統了,這裏已經有寫了http://rsyslog.org/2013/11/16/svn-puppet/
二、後面講的hiear中關於設置的變量對應到每一個環境中是如何解決的。
關於多環境的部署有不理解的還能夠參考書籍《精通Puppet配置管理工具》或者官網
微信公衆號:puppet2014,可微信搜索加入,也能夠掃描如下二維碼進行加入
QQ交流羣:296934942