Browse files

Added the very skeleton of a Chef config as an example.

  • Loading branch information...
1 parent ad99e43 commit c5d24b4a45a704035ab6d61fa0d65779206c758b @jacobian jacobian committed Mar 10, 2011
View
10 apache/apache2.conf
@@ -66,12 +66,4 @@ DocumentRoot "/home/web/static"
# And finally the app config.
#
-WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"
-
-
-
-
-
-
-
-
+WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"
View
70 chef/cookbooks/web/files/default/apache2.conf
@@ -0,0 +1,70 @@
+# Apache conf (/etc/apache2/apache2.conf)
+
+#
+# Basic server setup
+#
+ServerRoot "/etc/apache2"
+PidFile ${APACHE_PID_FILE}
+User ${APACHE_RUN_USER}
+Group ${APACHE_RUN_GROUP}
+ServerTokens ProductOnly
+ServerAdmin someone@example.com
+
+# Standalone server.
+Listen *:80
+
+#
+# Worker MPM features
+#
+
+Timeout 60
+StartServers 2
+ServerLimit 5
+MinSpareThreads 2
+MaxSpareThreads 4
+ThreadLimit 10
+ThreadsPerChild 10
+MaxClients 50
+MaxRequestsPerChild 10000
+
+#
+# Modules
+#
+
+LoadModule mime_module /usr/lib/apache2/modules/mod_mime.so
+LoadModule alias_module /usr/lib/apache2/modules/mod_alias.so
+LoadModule wsgi_module /usr/lib/apache2/modules/mod_wsgi.so
+
+#
+# Logging
+#
+
+LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined
+ErrorLog /var/log/apache2/error.log
+CustomLog /var/log/apache2/access.log combined
+
+#
+# Default HTTP features
+#
+
+AddDefaultCharset utf-8
+DefaultType text/plain
+TypesConfig /etc/mime.types
+
+#
+# Basic document root and directory perms.
+#
+
+<Directory />
+ Options FollowSymLinks
+ AllowOverride None
+</Directory>
+
+DocumentRoot "/home/web/static"
+
+#
+# And finally the app config.
+#
+
+WSGIScriptAlias / "/home/web/myblog/mingus.wsgi"
+
View
16 chef/cookbooks/web/recipes/default.rb
@@ -0,0 +1,16 @@
+package "git-core"
+package "python-dev"
+package "python-setuptools"
+package "postgresql-dev"
+package "postgresql-client"
+package "build-essential"
+package "libpq-dev"
+package "subversion"
+package "mercurial"
+
+cookbook_file "/etc/apache2/apache2.conf" do
+ source "apache2.conf"
+ owner "root"
+ group "root"
+ mode "644"
+end
View
3 chef/node.json
@@ -0,0 +1,3 @@
+{
+ "run_list": ["web::default"]
+}
View
3 chef/solo.rb
@@ -0,0 +1,3 @@
+log_level :info
+cookbook_path "/etc/chef/cookbooks"
+json_attribs "/etc/chef/node.json"
View
29 fabfile.py
@@ -1,13 +1,18 @@
"""
-The tutorial's first fabfile: automate deployment onto a single server.
+The tutorial's fabfile.
+
+This starts out pretty simple -- just automating deployment on a single
+server with a few commands. Then it gets a bit more complex (a basic
+provisioning example).
"""
-import os
-from fabric.api import *
+import contextlib
+from fabric.api import env, run, cd, sudo, put, require, settings, hide, puts
+from fabric.contrib import project, files
# This is a bit more complicated than needed because I'm using Vagrant
# for the examples.
-env.hosts = ['pycon-web1']
+env.hosts = ['pycon-web2']
env.user = 'vagrant'
env.key_filename = '/Library/Ruby/Gems/1.8/gems/vagrant-0.7.2/keys/vagrant'
@@ -39,6 +44,11 @@ def reload():
"Reload Apache to pick up new code changes."
sudo("invoke-rc.d apache2 reload")
+#
+# OK, simple stuff done. Here's a more complex example: provisioning
+# a server the simplistic way.
+#
+
def setup():
"""
Set up (bootstrap) a new server.
@@ -77,5 +87,12 @@ def setup():
# Now do the normal deploy.
deploy()
-
-
+
+
+def run_chef():
+ """
+ Run Chef-solo on the remote server
+ """
+ project.rsync_project(local_dir='chef', remote_dir='/tmp', delete=True)
+ sudo('rsync -ar --delete /tmp/chef/ /etc/chef/')
+ sudo('chef-solo')
View
9 nginx/nginx.conf
@@ -33,10 +33,9 @@ http {
include /etc/nginx/mime.types;
# HTTP upstream for load balancers.
- # Replace the IPs below with IPs (or names) of your upstream Apaches
- upstream fumblerooski {
- server 10.X.X.X:8000;
- server 10.X.X.X:8000;
+ upstream mingus {
+ server 33.33.33.10:8000;
+ #server 33.33.33.11:8000;
}
# The actual HTTP sever.
@@ -55,7 +54,7 @@ http {
# Proxy everything else to the backend
location / {
- proxy_pass http://fumblerooski;
+ proxy_pass http://mingus;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header X-Handled-By $upstream_addr;
}
View
42 notes/pycon2011/script.txt
@@ -145,11 +145,49 @@ While it runs talk about configuration management a bit.
6. Load balancers
-----------------
+Set up Nginx on web1::
+
+ web1$ aptitude install nginx
+ web1$ cd /etc/nginx/
+ web1$ rm -rf conf.d/ fastcgi_params koi-* nginx.conf sites-* win-utf
+ web1$ ln -s /home/web/django-deployment-workshop/nginx/nginx.conf .
+
+Edit Apache conf to listen on port 8000::
+
+ web1$ vim /etc/apache2/apache2.conf
+ web1$ invoke-rc.d apache2 restart
+
+Edit Nginx to point to correct backend - just web1 for now::
+
+ web1$ vim /etc/nginx/nginx.conf
+ web1$ invoke-rc.d nginx start
+
+Check it out::
+
+ local$ curl -I http://pycon-web1/
+
+Edit Apache on web2 for port 8000::
+
+ web2$ vim /etc/apache2/apache2.conf
+ web2$ invoke-rc.d apache2 restart
+
+Edit Nginx to point to both backends::
+
+ web1$ vim /etc/nginx/nginx.conf
+ web1$ invoke-rc.d nginx restart
+
+Check it out, looking at ``X-Handled-By``::
+
+ local$ curl -I http://pycon-web1/
+
7. Connection middleware
------------------------
-8. Next steps.
---------------
+Just look at the pgpool conf.
BONUS: Configuration management
-------------------------------
+
+Look at the Chef config. Then::
+
+ local$ fab run_chef

0 comments on commit c5d24b4

Please sign in to comment.