前言:

最近在伺服器系統上安裝了最新的Puppet客戶端,發現跟老版本的PuppetMaster做同步時出現了一些問題,警告類的資訊很好解決,註釋掉配置檔案templatedir該行即可,後來又對PuppetMaster做了次升級,直接升為最新的3.6.1,隨後發現PuppetMaster預設安裝的WEBrick的web伺服器效能較低且最新版本3.6.1存在bug以至於無法同時接受多臺Agent客戶端請求,因此使用Apache+Passenger方案替代原WEBrick,提高併發效能,同時解決bug帶來的問題

環境:

Ubuntu 12.04 64-LTS

PuppetMaster: 3.6.1(升級前版本為3.4.3)

PuppetAgent: 3.6.1

1、安裝Apache2

$ sudo apt-get install apache2 ruby1.8-dev rubygems
$ sudo a2enmod ssl
$ sudo a2enmod headers

2、安裝Rack/Passenger

$ sudo gem install rack passenger
$ sudo passenger-install-apache2-module
# 按提示解決軟體依賴關係後,再次執行命令安裝passenger模組
Please edit your Apache configuration file, and add these lines:

LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-4.0.44/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.44
  PassengerDefaultRuby /usr/bin/ruby1.8
</IfModule>

$ sudo mkdir /etc/puppet/rack
$ sudo mkdir /etc/puppet/rack/{public,tmp}
$ sudo scp /usr/share/puppet/ext/rack/config.ru /etc/puppet/rack/
$ sudo chown -R puppet:root /etc/puppet/rack

3、配置Puppet虛擬主機檔案

$ sudo cp /usr/share/puppet/ext/rack/example-passenger-vhost.conf /etc/apache2/sites-available/puppet.conf
$ sudo vim /etc/apache2/sites-available/puppet.conf
# 按之前的提示新增如下內容
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-4.0.44/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /var/lib/gems/1.8/gems/passenger-4.0.44
  PassengerDefaultRuby /usr/bin/ruby1.8
  PassengerHighPerformance on
  PassengerMaxPoolSize 12
  PassengerPoolIdleTime 1500
# PassengerMaxRequests 1000
  PassengerStatThrottleRate 120
# RackAutoDetect Off                 # 註釋該行
# RailsAutoDetect Off                # 註釋該行
</IfModule>

Listen 8140

<VirtualHost *:8140>
        SSLEngine on
        SSLProtocol             ALL -SSLv2
        SSLCipherSuite          ALL:!aNULL:!eNULL:!DES:!3DES:!IDEA:!SEED:!DSS:!PSK:!RC4:!MD5:+HIGH:+MEDIUM:!LOW:!SSLv2:!EXP
        SSLHonorCipherOrder     on
        # 修改為SSL實際路徑及檔名
        SSLCertificateFile      /var/lib/puppet/ssl/certs/test.cominggo.com.pem
        SSLCertificateKeyFile   /var/lib/puppet/ssl/private_keys/test.cominggo.com.pem
        SSLCertificateChainFile /var/lib/puppet/ssl/certs/ca.pem
        SSLCACertificateFile    /var/lib/puppet/ssl/certs/ca.pem
        # If Apache complains about invalid signatures on the CRL, you can try disabling
        # CRL checking by commenting the next line, but this is not recommended.
        SSLCARevocationFile     /var/lib/puppet/ssl/crl.pem
        SSLVerifyClient optional
        SSLVerifyDepth  1
        # The `ExportCertData` option is needed for agent certificate expiration warnings
        SSLOptions +StdEnvVars +ExportCertData

        # This header needs to be set if using a loadbalancer or proxy
        RequestHeader unset X-Forwarded-For

        RequestHeader set X-SSL-Subject %{SSL_CLIENT_S_DN}e
        RequestHeader set X-Client-DN %{SSL_CLIENT_S_DN}e
        RequestHeader set X-Client-Verify %{SSL_CLIENT_VERIFY}e

        DocumentRoot /etc/puppet/rack/public/
        RackBaseURI /
        <Directory /etc/puppet/rack/>
                Options None
                AllowOverride None
                Order allow,deny
                allow from all
        </Directory>
        ## Logging        # 設定Puppet訪問日誌(可選,預設日誌為other_vhosts_access.log)
        ErrorLog "/var/log/apache2/puppet_error.log"
        ServerSignature Off
        CustomLog "/var/log/apache2/puppet_access.log" combined
</VirtualHost>

$ cd /etc/apache2/sites-available/
$ sudo a2ensite puppet.conf

4、移除WEBrick服務(puppetmaster),並重啟Apache服務

$ sudo /etc/init.d/puppetmaster stop
$ sudo update-rc.d -f puppetmaster remove
$ sudo /etc/init.d/apache2 restart
$ sudo ss -talnp | grep apache2
LISTEN     0      128      *:8140         *:*      users:(("apache2",30037,5),("apache2",29472,5),("apache2",29467,5))
LISTEN     0      128      *:80           *:*      users:(("apache2",30037,3),("apache2",29472,3),("apache2",29467,3))
LISTEN     0      128      *:443          *:*      users:(("apache2",30037,4),("apache2",29472,4),("apache2",29467,4))

5、驗證是否部署成功

1)訪問HTTPS服務

# 訪問頁面:https://test.cominggo.com:8140/
The environment must be purely alphanumeric, not ``

2)PuppetAgent節點執行測試

# PuppetAgent:
$ sudo puppet agent -t

# PuppetMaster:檢視apache訪問日誌是否有200狀態請求
$ sudo tail /var/log/apache2/puppet_access.log
172.16.2.22 - - [20/Jun/2014:19:11:53 +0800] "GET /production/file_metadata/modules/zabbix/check.sh?source_permissions=use&links=manage HTTP/1.1" 200 5987 "-" "-"
172.16.2.22 - - [20/Jun/2014:19:11:53 +0800] "GET /production/file_metadata/modules/zabbix/zabbix-release_2.2-1+precise_all.deb?source_permissions=use&links=manage HTTP/1.1" 200 6003 "-" "-"
172.16.2.22 - - [20/Jun/2014:19:11:53 +0800] "GET /production/file_metadata/modules/zabbix/game.conf?source_permissions=use&links=manage HTTP/1.1" 200 5971 "-" "-"
172.16.2.22 - - [20/Jun/2014:19:11:53 +0800] "GET /production/file_metadatas/modules/game/release/data?checksum_type=md5&recurse=true&links=manage HTTP/1.1" 200 44519 "-" "-"
172.16.2.22 - - [20/Jun/2014:19:11:54 +0800] "GET /production/file_metadata/modules/zabbix/netif.py?source_permissions=use&links=manage HTTP/1.1" 200 5987 "-" "-"
172.16.2.22 - - [20/Jun/2014:19:11:56 +0800] "PUT /production/report/t1.cominggo.com HTTP/1.1" 200 5683 "-" "-"

參考:

官方文件:http://docs.puppetlabs.com/guides/passenger.html

KissPuppet部落格:http://kisspuppet.com/2013/11/08/apache-passenger/