tech: puppet unter debian mit nginx beschleunigen

viele wege führen nach rom, so auch zu dem für einen selbst zu einem guten
puppet setup. eine möglichkeit wäre es [puppet via git zu
skalieren](http://bitfieldconsulting.com/scaling-puppet-with-distributed-
version-control), die andere webrick
oder mongrel. damit ich das gesamte
besser pflegen kann, habe ich mich für ein mongrel setup mit vorgelagertem
nginx entschieden. einfach da mit die default debian installation hier schon
sehr gute hilfe mit auf den weg gibt. wichtig ist vielleicht noch das es mir
hier nur um den puppetmaster geht, nicht das aufsetzen einer kompletten
puppetumgebung oder den client. ich setze auf die lenny-backports[1], also einfach folgendes in der
/etc/apt/sources.list ergänzen wenn es nicht eh schon drin steht.

deb http://www.backports.org/debian lenny-backports main contrib non-free

es folgt die installation des puppetmasters via aptitude[2], jedoch mit
der expliziten ansage, das wir das paket aus lenny-backports wünschen.

aptitude install puppetmaster -t lenny-backports

als nächstes kommen einige kleine anpassungen im puppetmaster
/etc/default/puppetmaster, welche aber dann auch schon alles gewesen sind
was hier anzupassen ist. wenn nicht benötigt kann natürlich der debug modus
ausgeschaltet werden, ich selbst verwende diesen jedoch gerne per default.

# Start puppet on boot?
START=yes

# Startup options
DAEMON_OPTS="--debug --ssl_client_header=HTTP_X_SSL_SUBJECT"

# What server type to run 
# Options: 
#      webrick (default, cannot handle more than ~30 nodes)
#      mongrel (scales better than webrick because you can run
#               multiple processes if you are getting
#               connection-reset or End-of-file errors, switch to
#               mongrel. Requires front-end web-proxy such as
#               apache, nginx, or pound)
#      See: http://reductivelabs.com/trac/puppet/wiki/UsingMongrel
#SERVERTYPE=webrick
SERVERTYPE=mongrel


# How many puppetmaster instances to start? Its pointless to set this
# higher than 1 if you are not using mongrel. 
PUPPETMASTERS=2

# What port should the puppetmaster listen on (default: 8140). If
# PUPPETMASTERS is set to a number greater than 1, then the port for
# the first puppetmaster will be set to the port listed below, and
# further instances will be incremented by one 
#
# NOTE: if you are using mongrel, then you will need to have a
# front-end web-proxy (such as apache, nginx, pound) that takes
# incoming requests on the port your clients are connecting to
# (default is: 8140), and then passes them off to the mongrel
# processes.  In this case it is recommended to run your web-proxy on
# port 8140 and change the below number to something else, such as
# 18140.
PORT=18140

auch die bei lenny vorhandene nginx version kann leider nicht das was wir
benötigen, jedoch sollte auch hier der nginx aus lenny-backports reichen. ich
habe mich dazu entschieden die aktuelle entwickler-version zu installieren, da
ich einige der features für andere dinge benötige. also hier der kleine weg
zur nginx installation im debian style[3]. wobei es
natürlich auch hier eleganter geht. jeder der einen laufenden nginx hat,
einfach zur konfiguration springen. nginx war bereits auf dem system
installiert, dadurch sind alle passenden scripte und konfigurationen
vorhanden.

apt-get remove nginx
echo "nginx hold" | dpkg --set-selections

dann natürlich der download, sowie die installation des neuen nginx

cd /usr/src
wget http://nginx.org/download/nginx-0.9.3.tar.gz
tar xzvf nginx-0.9.3.tar.gz
cd nginx-0.9.3
./configure --prefix=/usr --conf-path=/etc/nginx/nginx.conf --sbin-path=/usr/sbin --user=www-data --group=www-data --http-log-path=/var/log/nginx/access.log --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module
make
make install

jetzt kommen wir zur nginx konfiguration, welche sich am debian weg
orientiert. als erstes wird unter /etc/nginx/conf.d die datei
puppetmaster.conf angelegt.

ssl                     on;
ssl_certificate /var/lib/puppet/ssl/certs/CHANGE_TO_SERVER.pem;
ssl_certificate_key /var/lib/puppet/ssl/private_keys/CHANGE_TO_SERVER.pem;
ssl_client_certificate  /var/lib/puppet/ssl/certs/ca.pem;
ssl_ciphers             SSLv2:-LOW:-EXPORT:RC4+RSA;
ssl_session_cache       shared:SSL:8m;
ssl_session_timeout     5m;

upstream puppet-production {
   server 127.0.0.1:18140;
   server 127.0.0.1:18141;
}

danach wird dann die entsprechende puppet-nginx-server konfiguration unter
/etc/nginx/sites-available angelegt. bei mir ist das die puppetmaster

server {
  listen 8140;

  ssl                     on;
  ssl_session_timeout     5m;
  ssl_certificate         /var/lib/puppet/ssl/certs/CHANGE_TO_SERVER.pem;
  ssl_certificate_key     /var/lib/puppet/ssl/private_keys/CHANGE_TO_SERVER.pem;
  ssl_client_certificate  /var/lib/puppet/ssl/ca/ca_crt.pem;

  # choose any ciphers
  ssl_ciphers             SSLv2:-LOW:-EXPORT:RC4+RSA;

  # allow authenticated and client without certs
  ssl_verify_client       optional;

  # obey to the Puppet CRL
  ssl_crl /var/lib/puppet/ssl/ca/ca_crl.pem;

  root                    /var/tmp;

  location / {
    proxy_pass              http://puppet-production;
    proxy_redirect         off;
    proxy_set_header    Host             $host;
    proxy_set_header    X-Real-IP        $remote_addr;
    proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header    X-Client-Verify  $ssl_client_verify;
    proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
    proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
    proxy_read_timeout  65;
  }
}

das vorkommen von CHANGE_TO_SERVER muss natürlich entsprechend geändert
werden. jetzt folgt noch der obligatorische symlink

ln -s /etc/nginx/sites-available/puppetmaster /etc/nginx/sites-enabled/puppetmaster

sowie natürlich dann der start des nginx mittels /etc/init.d/nginx start. so
sollte jetzt der nginx als frontend für den puppet mongrel laufen. wichtig ist
noch, das der default host des nginx ggf. zu deaktivieren ist, damit es keinen
konflikt mit einem anderen bereits laufenden webserver gibt. jetzt ist auch
das skalieren mit mehreren worker und puppet-mongrel instanzen ohne probleme
möglich. dieses setup kann mit dem erhöhen der nginx worker auf vier sowie
zwei zusätzlichen mongrelinstanzen mit ~ 300 clients problemlos. vielleicht
kann ja jemand diese hilfe gebrauchen! referenzen: [nginx
debian](http://www.sturbi.de/blog/index.php/2010/04/21/nginx-auf-debian-
installieren-compilieren/) [nginx puppet
mongrel](http://www.davidpashley.com/blog/systems-administration/puppet/nginx-
mongrel) nginx download

[1]: was nicht jeder kann und will, ob das auch mit den lenny default packen funktioniert habe ich nicht verifiziert
[2]: jeder nach seiner eigenen einstellung, ich nutze eigentlich fast nur noch aptitude
[3]: ohne ein .deb zu bauen

Show Comments