Seite wählen

NETWAYS Blog

Weekly Snap: Introducing CouchDB & Nginx, Offering Dev Job & NETWAYS Training

11 – 15 July introduced CouchDB, new ways of using Nginx, a part-time job opening and our training course schedule for September.
Christoph put a spin on the popular Nginx for use as a load-balanced image converter. As the first step, he showed how Nginx can distribute incoming queries to other web servers. He defined an upstream server and vhost to check for the requested image on all servers and to generate it in a shared directory when it is not found. In the second step, he used vhost’s image filter and security check for image optimisation. SSL and other image formats can be easily integrated, making this a handy tool but most of all scalable, stable and (with a bit of additional effort) also redundant.
Following on Gunnar introduced CouchDB. The Erlang, doc based DBMS has been packaged for most Linux distributions, and thanks to its HTTP based REST interface, can be accessed by most HTTP clients. With a simple UI for admin and database editing, it differs from relational DBMS in that no database schemas in the form of tables need to be defined upon DB setup. Instead, JSON formatted documents can be directly stored in the DB. Documents are accessed via _id, and views can be defined to enable access via other fields. In using an internal binary tree CouchDB can offer performance comparable with indexes in relational DBMS. Information on replication, document validation and more can be found on the Apache project page and in the online book “CouchDB: The Definitive Guide”.
Marius continued to fortify the development team, announcing a position for a student with Python and UML modelling experience. Uni students available to work 80 hours a month, and are interested in working on open source projects with a focus on Python, object modelling in UML based on EMF, document oriented databases, XML and JSON interfaces are welcome to apply at jobs@netways.de or find more info in our jobs area.
Ending the week, Rebecca gave a rundown of upcoming NETWAYS training courses in Icinga (19 – 23 Sep), Nagios (19 – 22 Sep), Puppet (13 – 15 Sep) and SLA Reporting with Jasper (28 – 29 Sep). Thanks to our innumerable consulting projects, we have much practical experience in dealing with highly varied environments and installations to share through our courses. These are designed for intensive learning with small groups, and many opportunities to share ideas and experience between attendees. For more, see our training area.

Einführung zu CouchDB

Bei CouchDB handelt es sich um ein in Erlang geschriebenes dokumentenbasiertes DBMS, das durch sein Design einige interessante Features anbietet.
Die meisten Linux-Distributionen bieten bereits vorgefertigte Pakete an. Unter Ubuntu kann CouchDB z.B. wie folgt installiert werden:
$ sudo apt-get install couchdb
Für den Zugriff auf CouchDB-Datenbanken sind keine speziellen Client-Anwendungen notwendig. Da CouchDB eine HTTP-basierte REST-Schnittstelle anbietet, kann nahezu jeder beliebige HTTP-Client (z.B. curl) verwendet werden, um auf die Daten zuzugreifen.
CouchDB bietet dennoch von Haus aus eine einfache Oberfläche zum Administrieren und Bearbeiten von Datenbanken an. Standardmäßig ist dieses unter http://localhost:5984/_utils/ erreichbar.
Im Gegensatz zu relationalen Datenbanksystemen ist es bei CouchDB nach dem Anlegen einer Datenbank nicht notwendig, ein Datenbankschema in Form von Tabellen zu definieren.
Stattdessen werden JSON-formatierte Dokumente direkt in der Datenbank abgelegt. Jedes Dokument verfügt dabei zunächst nur über zwei Felder:

  • _id: ein eindeutiger Bezeichner für das jeweilige Dokument; wird er vom Benutzer nicht mit angegeben, vergibt CouchDB automatisch eine einzigartige ID
  • _rev: die Revisionsnummer des Dokuments; sie wird bei jedem Update hochgezählt und intern von CouchDB zur Lösung von Konflikten verwendet

Weitere Felder können nach Bedarf beliebig hinzugefügt werden. Dabei ist es möglich, dass mehrere Dokumente unterschiedliche Felder enthalten.
Ein Zugriff auf die Dokumente ist über das _id-Feld möglich. Um über andere Felder nach Dokumenten zu suchen, müssen Views definiert werden. Diese bestehen aus JavaScript-Funktionen, die Dokumente bestimmten Schlüsseln zuordnet.
Um beispielsweise bei einem Blog alle Posts finden zu können, die an einem Donnerstag veröffentlicht wurden, könnte man eine View definieren, die den einzelnen Wochentagen jeweils die entsprechenden Blog-Posts zuordnet. Über die optionale Integration von Apache Lucene ist es auch möglich, Volltextsuchen durchzuführen.
Views werden beim Bearbeiten von Dokumenten aktualisiert und verwenden intern einen binären Baum, um eine ähnliche Performance anzubieten wie Indizes bei relationalen Datenbanksystemen.
Mehr Informationen zu CouchDB-Features wie z.B. Replikation, Dokumenten-Validierung und etlichen weiteren gibt es auf der offiziellen Webseite unter http://couchdb.apache.org/ und im online verfügbaren Buch „CouchDB: The Definitive Guide
“ unter http://guide.couchdb.org/.