Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Working memcached and pgpool configs; strip the local stuff.

  • Loading branch information...
commit bd8aee694782ffd15bff5df92ceb9d70a20933f1 1 parent 904c7e4
Jacob Kaplan-Moss jacobian authored
9 fabfiles/multiple-webs.py
View
@@ -69,9 +69,14 @@ def buildout():
def reload():
"Reload Apache to pick up new code changes."
run("invoke-rc.d apache2 reload")
-
+
+def flush_cache():
+ "Flush memcached."
+ run("invoke-rc.d memcached restart")
+
def deploy():
"Full deploy: push, buildout, and reload."
push()
buildout()
- reload()
+ reload()
+ flush_cache()
1  fumblerooski-site/buildout.cfg
View
@@ -6,6 +6,7 @@ eggs =
psycopg2
Unipath
django-piston
+ python-memcached
extra-paths = ${buildout:directory}
${buildout:directory}/parts
${buildout:directory}/parts/gcharts
6 fumblerooski-site/fski/settings.py
View
@@ -25,12 +25,18 @@
SECRET_KEY = 'd8i0we+qjkwf*xt&fxl^$)x1pa-c%=$ib(^vrcy2z3y8!w_sua'
USE_I18N = False
+# Umcomment this and the middleware below to enable caching.
+# Replace the IPs with the internal IPs of the machines running memcached.
+# CACHE_BACKEND = 'memcached://10.X.X.X:11211;10.X.X.X:11211/'
+
MIDDLEWARE_CLASSES = (
+ # 'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.doc.XViewMiddleware',
'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
+ # 'django.middleware.cache.FetchFromCacheMiddleware',
)
ROOT_URLCONF = 'fumblerooski.urls'
2  memcached/memcached.conf
View
@@ -4,7 +4,7 @@
logfile /var/log/memcached.log
# Memory cap
--m 128
+-m 32
# Connection port
-p 11211
77 notes/pycon-2010-script.txt
View
@@ -37,7 +37,7 @@ Keys::
Better tab completion::
- <all>$ aptitude -y install bash-completion
+ <all>$ aptitude install bash-completion
<all>$ echo ". /etc/bash_completion" >> .bashrc
Pre-fetch the big data file::
@@ -49,7 +49,7 @@ Pre-fetch the big data file::
Bootstrap up the example app::
- web1$ aptitude -y install git-core python-dev postgresql-dev postgresql-client build-essential libpq-dev
+ web1$ aptitude install git-core python-dev postgresql-dev postgresql-client build-essential libpq-dev
web1$ mkdir -p /home/web/static
web1$ cd /home/web
web1$ git clone git://github.com/jacobian/django-deployment-workshop.git
@@ -63,19 +63,9 @@ Get ``http://pycon-web1:8000/`` - operational error. Exactly what I'd expect.
2. PostgreSQL
=============
-Install Postgres. Fix locale problems (see
-http://cloudservers.rackspacecloud.com/index.php/Ubuntu_-_Repairing_Perl_Locale_Errors
-and http://jacobian.org/writing/pg-encoding-ubuntu/)::
+Install and configure Postgres.
- db1$ aptitude -y install postgresql
- db1$ aptitude -y install language-pack-en-base
- db1$ dpkg-reconfigure locales
- db1$ pg_dropcluster --stop 8.4 main
- db1$ pg_createcluster --start -e UTF-8 8.4 main
-
-Configure postgres:
-
- db1$ aptitude -y install git-core
+ db1$ aptitude install git-core postgresql
db1$ git clone git://github.com/jacobian/django-deployment-workshop.git
db1$ cd /etc/postgresql/8.4/main/
db1$ invoke-rc.d postgresql-8.4 stop
@@ -184,8 +174,65 @@ Check it out, looking at ``X-Handled-By``::
7. Caching servers
==================
+Install, enable, config memcached::
+
+ web1$ aptitude install memcached
+ web1$ echo "ENABLE_MEMCACHED=yes" > /etc/default/memcached
+ web1$ rm /etc/memcached.conf
+ web1$ ln -s /home/web/django-deployment-workshop/memcached/memcached.conf /etc/memcached.conf
+
+Make memcached listen on the internal IP, then start it (and check)::
+
+ web1$ vim /etc/memcached.conf
+ web1$ invoke-rc.d memcached start
+ web1$ echo stats | nc -q1 <internal-ip> 11211
+
+Repeat on web2.
+
+Edit ``fski/settings.py`` to point to both cache servers::
+
+ CACHE_BACKEND = "memcached://<web1>:11211;<web2>:11211/"
+
+ MIDDLEWARE_CLASSES = (
+ 'django.middleware.cache.UpdateCacheMiddleware',
+ ...
+ 'django.middleware.cache.FetchFromCacheMiddleware',
+ )
+
+Check that it's working.
+
+Check cache stats::
+
+ web1$ echo stats | nc -q1 <web1> 11211
+ web1$ echo stats | nc -q1 <web2> 11211
+
8. Database connection middleware
=================================
+Install pgpool2. There's a bug in the current Ubuntu we'll need to work around
+with this ``/etc/default/pgpool2``::
+
+ web1$ aptitude install pgpool2
+ web1$ invoke-rc.d pgpool2 stop
+ web1$ rm /etc/default/pgpool2
+ web1$ ln -s /home/web/django-deployment-workshop/pgpool/etc-default-pgpool /etc/default/pgpool2
+ web1$ rm /etc/pgpool.conf
+ web1$ ln -s /home/web/django-deployment-workshop/pgpool/pgpool-single-db.conf /etc/pgpool.conf
+
+Fix up ``pgpool.conf`` to point to the backend (``db1``). Start it and check.
+
+ web1$ vim /etc/pgpool.conf
+ web1$ invoke-rc.d pgpool2 start
+ web1$ psql -l
+
+Repeat on ``web2``.
+
+Modify Django to use pgpool::
+
+ DATABASE_HOST = ''
+
+Check it out.
+
9. Database redundancy
-======================
+======================
+
Please sign in to comment.
Something went wrong with that request. Please try again.