puppet系列之nginx+foreman

 foreman架構:

本文主要講述搭建foreman,及集成進nginx的過程

環境說明:

CentOS 5.8 x86_64

puppet version:3.1.1

master hostname:server.domain.com

client hostname:client.test.com

----------------------------------------------

  1. 1,puppet,nginx環境 
  2. 均按上篇文章所部署安裝好puppet,nginx,ruby等 
  3.  
  4. 2,配置yum源 
  5. # rpm -ivh http://yum.theforeman.org/releases/1.1/el5/x86_64/foreman-release-1.1stable-3.el5.noarch.rpm 
  6.  
  7. 3,安裝foreman,foreman-proxy 
  8. # yum -y install foreman-installer 
  9. # ruby /usr/share/foreman-installer/generate_answers.rb 
  10. 分別輸入三次 y 
  11. # yum install ruby-mysql 
  12. # yum -y install foreman  foreman-proxy  
  13. # chown foreman.foreman -R /usr/share/foreman 
  14. # su - foreman -s /bin/bash -c /usr/share/foreman/extras/dbmigrate 
  15. # vim /usr/share/foreman/config/database.yml    
  16. 原文件爲sqllite的配置,此處改爲mysql作爲數據庫存儲  
  17. =================================================  
  18. production:  
  19.   adapter: mysql  
  20.   database: puppet  
  21.   username: puppet  
  22.   password: puppet  
  23.   host: localhost  
  24.   socket: "/tmp/mysql.sock"  
  25. =================================================  
  26. mysql> create database puppet CHARACTER SET utf8;  
  27. mysql> grant all privileges on puppet.* to puppet@'localhost' identified by 'puppet';  
  28. mysql>  flush privileges;  
  29.  
  30. # cd /usr/share/foreman/  
  31. RAILS_ENV=production rake db:migrate  
  32. rake puppet:migrate:populate_hosts RAILS_ENV=production  
  33.   
  34. # chown foreman.foreman /usr/share/foreman/tmp/secret_token  
  35. # vim /etc/foreman-proxy/settings.yml  
  36. ==========================================================  
  37. :trusted_hosts:  
  38. - server.domain.com  
  39. :puppetca: true  
  40. :puppet: true  
  41. :puppet_conf: /etc/puppet/puppet.conf  
  42. ========================================================= 
  43. # /etc/init.d/foreman-proxy start  啓動proxy 端口8443 
  44. 4,集成進nginx 
  45. nginx虛擬主機如下: 
  46. server { 
  47.         listen 443; 
  48.         server_name server.domain.com; 
  49.         ssl on; 
  50.         ssl_certificate            /var/lib/puppet/ssl/certs/server.domain.com.pem; 
  51.         ssl_certificate_key        /var/lib/puppet/ssl/private_keys/server.domain.com.pem; 
  52.          
  53.         #Verify puppetmaster clients against Puppet CA 
  54.         ssl_crl                    /var/lib/puppet/ssl/ca/ca_crl.pem; 
  55.         ssl_client_certificate     /var/lib/puppet/ssl/certs/ca.pem; 
  56.         ssl_verify_client optional; 
  57.         ssl_verify_depth 1; 
  58.  
  59.         access_log /usr/local/nginx/logs/foreman_access.log; 
  60.         error_log /usr/local/nginx/logs/foreman_error.log debug; 
  61.         root /usr/share/foreman/public; 
  62.  
  63.         passenger_enabled on; 
  64.         passenger_set_cgi_param HTTPS on; 
  65.         passenger_set_cgi_param SSL_CLIENT_S_DN $ssl_client_s_dn; 
  66.         passenger_set_cgi_param SSL_CLIENT_VERIFY $ssl_client_verify; 
  67.  
  68.        } 
  69. # /etc/init.d/nginxd start  ###啓動nginx  
  70.  
  71. 5,訪問foreman 
  72. 輸入網址:https://server.domain.com 
  73. 默認賬號:admin   密碼:changeme 
  74. 進入之後配置more-configureation-smart proxies----  
  75. 添加proxy地址: https://server.domain.com:8443 
  76.  
  77. #vim /etc/puppet/node.rb   
  78. :url          => "https://server.domain.com", 
  79.  
  80. 6,設置report自動導入foreman 
  81. # cp /usr/share/foreman-installer/foreman/templates/foreman-report.rb.erb /usr/lib/ruby/site_ruby/1.8/puppet/reports/foreman.rb 
  82. # vim foreman.rb 
  83. 修改成一下配置,其他不變(ps:一直就是卡在住錯)
  84. #<%= ERB.new(File.read(File.expand_path("_header.erb",File.dirname(file)))).result(binding) -%> 
  85. # copy this file to your report dir - e.g. /usr/lib/ruby/1.8/puppet/reports/ 
  86.  
  87. # add this report in your puppetmaster reports - e.g, in your puppet.conf add: 
  88. reports=log, foreman # (or any other reports you want) 
  89.  
  90. # URL of your Foreman installation 
  91. $foreman_url = 'https://server.domain.com' 
  92. # if CA is specified, remote Foreman host will be verified 
  93. $foreman_ssl_ca = "/var/lib/puppet/ssl/certs/ca.pem" 
  94. # ssl_cert and key are required if require_ssl_puppetmasters is enabled in Foreman 
  95. $foreman_ssl_cert = "/var/lib/puppet/ssl/certs/server.domain.com.pem" 
  96. $foreman_ssl_key = "/var/lib/puppet/ssl/private_keys/server.domain.com.pem" 
  97.  
  98. 客戶端需修改 
  99. agent配置如下 
  100. [agent] 
  101.     classfile = $vardir/classes.txt 
  102.     localconfig = $vardir/localconfig 
  103.     report      = true      
  104.     pluginsync  = true 
  105.     masterport  = 8140 
  106.     environment = production 
  107.     certname    = client.test.com 
  108.     server      = server.domain.com 
  109.     listen      = true 
  110. 服務器端修改 
  111. [master] 
  112.     autosign       = $confdir/autosign.conf { mode = 664 } 
  113.     reports        = log,foreman 
  114.     external_nodes = /etc/puppet/node.rb 
  115.     node_terminus  = exec 
  116.     ca             = true 
  117. ======================= 
  118. 7,class,host.facts導入foreman 
  119. #cd /usr/share/foreman
  120. #導入hosts 和facts
  121. rake puppet:import:hosts_and_facts RAILS_ENV=production
  122. 把/etc/puppet/modules底下的模塊都複製至/etc/puppet/modules/production 
  123. 在foreman web管理 
  124. mode---configuration---puppet classes 
  125. 點擊import from server 即可 

主要截圖如下:

 

這樣puppet系列文章已基本完成;

在此感謝下itnihao,liu.cy的指導 (ps:爲了文章的完整性,所以引用了大量itnihao文章的內容)

 

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