Monday, August 11, 2014

Adding static Routes in OSX

Just a quick correction to this blog entry:

http://blog.irrashai.com/blog/2009/03/how-to-add-static-route-in-mac-os-x/


Note: Edit the IP addresses listed below to match your network.

Create two files:  /Library/StartupItems/AddRoutes/AddRoutes
 
#!/bin/sh

# Set static routing tables

. /etc/rc.common

StartService ()
{
  ConsoleMessage "Adding Static Routing Table"
  route -n add -net 10.0.255.0/24 10.1.1.1
}

StopService ()
{
return 0
}

StopService ()
{
return 0
}

RestartService ()
{
return 0
}

RunService "$1"

 And: /Library/StartupItems/AddRoutes/StartupParameters.plist

{
Description = "Add static routing tables";
Provides = ("AddRoutes");
Requires = ("Network");
OrderPreference = "None";
}


Set everything as executable:
chmod 755 /Library/StartupItems/AddRoutes/*

Finally, reboot and check if your new routes "stuck":
netstat -rn


Monday, February 24, 2014

Rabbit MQ - Replication Options

When you need to replicate data with Rabbit MQ there are three main choices:
  • Federation plugin (Federated Exchanges).
  • Shovel Plugin
  • Mirror Queues (Part of the basic Rabbit clustering)
A useful starting point when trying to decide which to use is to examine where the various options read messages from and where they write the messages to:


Message Source
Exchange Queue
Target Exchange Federated Exchange Shovel
Queue Mirror Queue

Note: The federation plugin actually creates a temporary queue bound to the source exchange in order to collect messages however since this queue is configured automatically you are effectively reading messages from the source exchange.

However there is a much easier way to choose the right option for you:

If you are replicating data between clusters you need either the federation plugin or the shovel plugin.
If you are simply want redundant copies of the data within the same cluster use mirror queues.

In practice the choice between the federation and shovel comes down to:
  • The federation plugin is much simpler to setup, however it only supports "pulling data".
  • Where as the shovel plugin has to be manually configured, but data can be pulled or pushed**. 
** Pushing data means that the system where the shovel plugin is installed is pushing data to the other clusters. Where as pulling means that the system where shovel is installed is pulling data from the remote cluster.

Therefore if your pulling data your better off with the federation plugin, however if you need to push it you will be forced to use shovel.

Thursday, January 2, 2014

Building Readline 6.2 on Mavericks

This is not a long post, as the only additional step I have introduced is Step #4 - editing the Makefile
  1. cd /usr/local/src
  2. tar -zvxf readline-6.2.tar.gz
  3. cd readline-6.2
  4. vi shlib/Makefile
  5. make
  6. sudo make install

When you edit the Makefile (Step # 4) make the following change:

Change line #84 from:
SHOBJ_LDFLAGS = -dynamic

To
SHOBJ_LDFLAGS = -dynamiclib

Friday, October 25, 2013

Fixing Ubuntu Postgres Install

Ubuntu chose to install the default database as LATIN1, this is a problem for "double byte" languages and may cause issues with other languages.

To fix it:

Switch to root then:

export LANGUAGE="en_US.UTF-8"
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
pg_dropcluster --stop 9.1 main
pg_createcluster --start -e UTF-8 9.1 main
 
NOTE: This completely nukes your DB install,
don't do this if you already have data in the database.

Thursday, September 5, 2013

Accessing a LVM partion inside a Guest OS Raw Image

Sometimes its handy to be able to access the contents of a Guest OS image before/without booting it up.

It can be a pain as the kernel doesn't recognize the devices without a few extra commands.

For quick refence here they are:

To mount an LVM partition:

  • kpartx -a /var/lib/libvirt/images/CentOSGuest.img
  • pvscan
  • vgchange -ay vg_centguest
  • mount /dev/mapper/vg_centguest-lv_root /mnt
Note: The pvscan is optional, it's useful to allow you to check the group name.

Then to un-mount:
  • umount /mnt
  • vgchange -an vg_centguest
  • kpartx -d /var/lib/libvirt/images/CentGuesst.img

Behind the scenes, this will create a loop device /dev/loop0 so you may want to increase the number of available devices by editing /etc/modules.conf and add the following line:

options loop max_loop=64

Saturday, August 18, 2012

Choosing a NoSQL Database

Where to Start?

When starting a new project, it is necessary to figure out which of the multitude of No SQL providers to choose from.

I found the following diagram very helpful: No-SQL Diagram
Take note that it covers both CAP requirements and data model (Key-Value, Column or Document).

The following article brings home what CAP means in the real world:  MongoDB vs CouchDB

Once we have eliminated a few choices (we are picking from a short-list) the following article is helpful to understand the trade-offs we are making:  No-SQL Summary

What does CAP mean to me ?

When we introduce a second data center into our design, we are forced into an overall AP model.
We know there will be times that the two data centers will lose connectivity from each other (P) and the primary reason we are doing this is to keep our site available (A).

Even if we run an Active-Passive configuration, we must accept that our primary DC may lose power before replicating data to our secondary. If/when we get the primary datacenter back online we will need to reconcile the data (eventually consistent).

The question becomes, do we want to handle this inconsistency at the application or the data-store layer, putting this another way:
Do we want our data store to span data centers?

If we span data centers we need to deal with eventually consistent data on the site, we will have different data at each site and totals will not always match, we have to make sure that these inconsistencies don't impact the user (too much).

If we isolate the data centers (data-store clusters don't span DC's) all the data-stores within the datacenter can be CP (if a fatal problem occurs it is still possible to cut over to the other data-center). But within each DC things are now much simpler as all the stores are consistent.
The fail-over/back events (at the datacenter level) cause inconsistencies that have to be handled at the application layer, however this may be okay if such fail-overs are rare and the desired SLA is more generous.

In summary if data-stores clusters are restricted to a single data center (or AWS region) our application logic can be simpler, than it would be, if it had to handle eventually consistent data.
However we run the risk of having to reconcile data during a datacenter failover. This risk can be mitigated by spreading the nodes of the cluster across independent power/network zones (availability zones) hence reducing the chance of an outage at the datacenter. But this risk can not be eliminated unless we handle inconsistent data at the application layer.

Data Model

The choice of data model comes down to how we want to handle "document linkage". Key/Value stores are easy to understand and the most efficient for simple use cases. However we inevitably get to the point where we want to "serialize" more complex objects into a single value.
Then we discover that we need to access the data in a more complex way and we end up with a more complex solution:
  • Creating reference documents, where the value is a list of keys.
  • Mangling the keys so that we can load data based on a pattern.
  • Using a third party index (such as solr).
Document stores are specifically optimized for this usage pattern - to be able to extract (and update) parts of multiple documents in a single query.

Hence the choice between these technologies is based on how complex we expect our use cases to be.

Sanity Check our Choice

Running a google query on "DATABASE_NAME doesn't scale" is a good way to find the articles about the negatives.

The most important question is why (the given DB doesn't scale), since if a product only has one limiting feature its likely someone is working on fixing it (we can also make an assessment of how likely the fix is).

Anyway here are a couple of good negative articles:

Monday, May 28, 2012

Reseting the Default Root Password on OSX

If you have ever set the root password on an OSX machine using the: passwd
Command you may be wondering how to reset it back to the default;

rm /var/db/shadow/hash/FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000000*

Edit /var/db/dslocal/nodes/Default/users/root.plist

Remove the key "authentication_authority" and any values it has.

Reboot the machine.