August 2009

I just got back from watching District 9 in the cinema, and wow, what a refreshing experience! It’s been a long time since I’ve watched a movie that was awesome (in the big guns, space ships and robots kind of way), smart, scary (intellectually), gory, and fun. It messes with your mind several times over and it feels wonderful. Take a look at the latest trailer for the movie:

I was skeptic after watching the trailer, but it turned out to be more of a distraction than a summarization of the film. Without revealing too much, let me just say that it is worth watching District 9 even if the trailer leaves you thinking it might just be a Resident Evil clone (it’s not).

District 9 is a bloody good action movie (emphasis on bloody) that challenges the viewer’s perception of humankind. I find it hard to believe that its budget was set at a meager USD $30,000,000.

Now my wait for the sequel begins. I wonder if it will be able to successfully expand on the message conveyed so exceptionally by Neill Blomkamp in the first movie.

Google’s Own SEO Tips

August 26, 2009

in Web design

If one were to point at a person who knows a few search engine optimization tricks, it wouldn’t be far off if that person was Matt Cutts, the head of Google’s webspam team. Matt’s job is to keep Google’s search results clean and thus he has intimate knowledge of how the search engine categorizes and rates different pages and sites.

Matt recently spoke at WordCamp 2009 and previously at WordCamp 2007 about making your blog/website search engine friendly, with a focus on playing nice with Google. Each talk is about an hour long and touches on many of the concerns about optimization that webmasters commonly have. If you’re familiar with SEO and you watch these two talks, you can’t go wrong. You can find the videos and slideshow presentations on Matt’s own website, here:

  1. WordCamp 2007 talk: Whitehat SEO tips for bloggers
  2. Straight from Google: What You Need to Know

For a quick overview and future reference, I’ve noted down all of the important points of Matt’s talks and combined them with the conclusions reached in the subsequent Q&A’s. If you have time, watch both of Matt’s talks first. If you’re then looking for a SEO cheat sheet, of sorts, this should be quite decent:

Code & Structure

  • Google specifically looks at content in the title, URL and H1/H2/H3 sections.
  • Dashes/hyphens are best in URL paths, underscores next best, and no spacing between words is the worst.
  • Use ALT tags on images (3-4, maybe 5 relevant words) — it can yield a lot of alternative traffic.
  • .php, .html, .cfm, none of the extensions matter, just don’t use .exe
  • In general, TLD’s do not matter (.info, .biz, etc.), but try to go for .com
  • When Google sees a hashmark (#) in a URL, it truncates at the hash (and the remainder of the URL is ignored).
  • Dynamic URLs (with question marks) are treated exactly the same as static pages. Keep the number of parameters to 2 or 3. If you have e.g. 15, you risk having duplicate text in the URL, which can get penalized.
  • Google does not check domain WHOIS information.
  • Make sure your site is crawlable. Don’t use framesets, excessive Flash, etc. A good way of testing is to try browsing your site on your phone or in a text-mode browser like links or lynx — this is basically how Google sees your site.
  • Putting date information in the URL is fine. Google does not care about the “depth” of a URL/the amount of slashes (keep in mind that /2007/ will count as a URL keyword, however).
  • If it’s possible, use the same site for both regular browsers and phones, and make variations via stylesheets.
  • Don’t put your blog at the root of your domain. People will link to your root domain and your blog, and you’ll be able to easily expand your site further on.
  • Use ‘blog’ as your blog’s subdirectory, not e.g. ‘WordPress’. This counts as a keyword — if you use ‘WordPress’, you’re going to show up in results for WordPress, even if you’re not talking about WordPress (and disappear from somewhere else).
  • Try to use the rel canonical tag (newer WordPress versions do this by default).
  • WordPress specific: Change default permalink (domain.com/?p=48) to e.g. domain.com/blog/%postname%
  • WordPress specific: Protect your /wp-admin/ folder, limit access with e.g. .htaccess

Keywords

  • Write in plain English, consider what people search for.
  • Use Google’s Keyword Tool to find relevant keywords.
  • Don’t use keywords more than 2, 3, or 4 times on a page (unless it makes sense). It doesn’t help to repeat a major keyword 50 or 100 times.
  • Don’t hide keywords, absolutely don’t consciously mask keywords to artificially improve search engine rankings (this is called cloaking).
  • If you know people are going to type in “fun”, “pictures”, “cats” or “kittens” when they search, there are completely natural ways to work this into your text without spamming. Use many different forms of your major keywords, for instance, have “change” in your URL, but “changing” in the title, “Firefox” but also “Mozilla”, “print server” and also “CUPS”, etc. — Synonyms, plurals, singular, etc.
  • Use categories that are good keywords if they make sense.
  • Use your keywords in the content of your post. Use the major ones inside and close to the title if possible.
  • The Meta Keyword tag does not really matter.

PageRank

  • Google crawls roughly in order of PageRank. The more pagerank you have, the deeper and more often Googlebot will crawl your site.
  • Pagerank is about the quality of the sites linking to you. 10 links from respected sites are better than 50 links from ‘random’ sites.
  • If e.g. 100 sites link to you, and you link to two sites, each site gets roughly 50 pagerank.

Human Factors

  • Don’t care about the amount of incoming links. Concentrate on being relevant and reputable.
  • Write about something you care about.
  • Don’t worry about small things, concentrate on writing more, good, unique content.
  • Katamari; start out with a (really) small niche. Build, build, build and expand your niche gradually. Do original research.
  • Make your post creation dates easy to find. Not so much for the search engine, but people want to know when a post was created.
  • Don’t try to get search engines to like you to get noticed by the world. Get known, then worry about SEO. Do some whitehat linkbaiting — make some funny videos, iPhone apps, do tutorials, analysis, 13 reasons why something sucks or rocks, etc.

When Changing Hosts

  1. (Optional) Reduce your DNS time-to-live so your new IP will propagate a lot faster, e.g. in five minutes.
  2. Bring both sites up, so users will see your site at both the old and the new IP address.
  3. Change the domain settings to point to your new IP address.
  4. When you are receiving traffic from Googlebot and users (and your DNS time-to-live has passed) on the new site, take down the old site (try to keep the old site up for the duration of your TTL though). The default TTL is usually 1 hour.

When Moving to a New Domain

  • Standard advice: Use a 301 (permanent) redirect.
  • Even better: pick one subdirectory and move that first. If the traffic stays desired, move the rest of the site.
  • Standardize your backlinks (e.g. enforce ‘www.’ or no ‘www’ on your server, and only link to one variation of your domain).
  • Ask people who link to you to update their links.

Other

  • Don’t do paid posts/don’t sell or buy links. If you want to do affiliate linking, “nofollow” the links.
  • Use Google’s Webmaster Tools — see what people are linking to, what Google can’t find, check your robots.txt, and so on. Also, indicate your ‘www.’ or no ‘www.’ preference.
  • Use Google Analytics — having Google Analytics does not affect your search engine ratings.
  • Use Feedburner and Feedburner MyBrand (host your feeds on e.g. feeds.patrickmylund.com).
  • To show up in Google News, you generally need to be more than one person — be a “proper news outlet”.
  • Report splogs with Google Webmaster Tools’ “Report spam in our index” feature, rather than filing a DMCA. Don’t think of it as a copyright violation, but as spam.
  • Make great, viral content.

Oh, this reminds me of the days of transparent PNG troubles. Using CSS alpha opacity seems to break Internet Explorer 8.0:

.hovers {
        opacity: .6;
        -moz-opacity: .6;
        filter: alpha(opacity=60);
}
.hovers:hover {
        opacity: 1;
        -moz-opacity: 1;
        filter: alpha(opacity=100);
}

This is how images styled with this CSS renders in the most popular browsers (for the real styling, hover over the “Follow” icons in the top of the sidebar to the right):

Maybe I’m just doing it wrong? I’d like to know, since I don’t want to choose between awesome hovers and looking shady to 20% of the site’s visitors (I just realized the stats have changed quite a bit: Firefox 62.38%, Internet Explorer 20.25%, Chrome 6.52%, Safari 4.14%, Opera 4.09%).

Update: Turns out filter: alpha isn’t a CSS standard, but is in W3C’s CSS3 recommendation.

Journey to The Motherland

August 17, 2009

in Travel

I was recently at a conference in Moscow, the heart of the Russian Motherland. Moscow, albeit heavily influenced by the Western world, is a very unique and fascinating city, and its people appeared to me surprisingly humorous and refreshingly honest. It was a cool experience.

It didn’t take long before a few things occurred to me, however:

  • there are a lot of cab drivers in Moscow who really want to drive somewhere with you
  • traffic laws; there aren’t any
  • travel lanes; why thank you, yes, I think I’ll take eight
  • Russians really enjoy the consumption of vodka
  • it is considered impolite to sit out on rounds when drinking said vodka
  • there are at least 15 ways to say “Cheers” in Russian
  • I am holding off on vodka for a little while

What really fascinated me about Moscow was some of its architecture. Neglecting the obligatory Red Square:

Oh look, they have IKEA t--waiiiiiit a minute

Oh look, they have IKEA t--waiiiiiit a minute

I miss you, Dune

I miss you, Dune

We humbly greet our extraterrestrial overlords

We humbly greet our extraterrestrial overlords

I'm not entirely sure what this is

I'm not entirely sure what this is

As for the quality, cell phone camera in a moving car: no, no, no.

What is your best programmer joke? is now one of my favorite StackOverflow threads — C-x M-c M-butterfly!

A man flying in a hot air balloon suddenly realizes he’s lost. He reduces height and spots a man down below. He lowers the balloon further and shouts to get directions, “Excuse me, can you tell me where I am?”

The man below says: “Yes, you’re in a hot air balloon, hovering 30 feet above this field.”

“You must work in Information Technology,” says the balloonist.

“I do” replies the man. “How did you know?”

“Well,” says the balloonist, “everything you have told me is technically correct, but It’s of no use to anyone.”

The man below replies, “You must work in management.”

“I do” replies the balloonist, “But how’d you know?”

“Well”, says the man, “you don’t know where you are, or where you’re going, you expect me to be able to help. You’re in the same position you were before we met, but now it’s my fault.”

Feature, not a bug

“Knock, knock.”

“Who’s there?”

very long pause….

“Java.”

:-o

A Rare Act of Kindness

August 15, 2009

in Life

Yesterday, I was carrying home from work an 88-key MIDI controller (a long keyboard of the musical variety) in quite possibly the most impractical box in the world. The walk home from work is about two miles, so my arms were beginning to give up at the end. I had just put the box down on the road to take a few seconds when a stranger came up to me and asked, “Do you need some help with that?”. Normally, I’d thank him for the offer and decline, but this one was a little too good to pass up. “That’d be great, thank you”, I replied, and he grabbed the other end of the box. “It’s nothing!”, he said.

Now, there’s a railway station on the route to my home, and this was where the stranger was headed. When we reached it, I said somewhat insistently, “I can take it from here”, to which he responded by shaking his head and saying, “My train isn’t leaving for another three minutes, I might as well help you carry this for one more minute”. We almost reached my house before he had to put his end of the box down on the ground and rush off to catch the train. “Good luck to you!”, he said as he left.

How nice it was to experience a truly selfless act of kindness, void of any hidden agendas or ulterior motives. It may have been nothing to the stranger — whose name I didn’t even catch — but it made my day.

outSSIDer is the lonely little application that’s there for you when you drop your phone in the big city and you really need to twitter about it. Get the laptop, open outSSIDer, close the lid, then start walking around. When it makes a successful connection to a wireless network, it’ll make a ding sound. If it is then successful in retrieving a file (in this case, Google’s favicon) from the great internet, it’ll start dinging frantically. If not, well, it’s the hi-hat, of course.

Download it here.

I wasn’t joking about closing the laptop lid, by the way — you stand out a little when you walk around looking at an open laptop making cymbal noises.

outSSIDer is based on inSSIDer, a Wi-Fi diagnostics tool.

Staying ahead of IT service issues can be frustrating when you manage several servers, or even a single server with many services. Enterprise IT Infrastructure Monitoring Solutions (a fancy term for something that is really pretty simple) attempt to remedy the problem by repeatedly checking the status of machines and services on the network and alerting the responsible administrators as soon as something goes wrong, or even before there’s a problem.

It’s hard to argue against implementing a monitoring solution within the network, as it is much a setup-and-forget matter that adds negligible load. The monitoring solution itself is — or at least, should be — very low maintenance, yet provides very valuable insight into the health of the network.

Introducing Nagios

Nagios LogoNagios is an infrastructure monitoring solution that is both popular and open source. Apart from its obvious monitoring capabilities, it includes the ability to associate an event handler to an event, allowing you to fix a problem automatically. If — for example — one of your Python applications crashes, you can have Nagios do python /opt/myapp/myapp.py automatically, before any human administrators have the time to do so. Other features include the ability to create many kinds of reports, and to send notifications and alerts via email and SMS.

Nagios' web interface screenshot

Nagios' web interface

Nagios is based primarily on C and shell scripts, which makes it light on performance but adds a slightly ‘hackish’ feel. It comes with a CGI-based web interface (which we’ll spice up a bit) that lets you view and manage Nagios, through what are known as External Commands.

I’d like to demonstrate how to set up rudimentary Nagios monitoring on a small farm of Linux servers, with an Ubuntu/Debian server running the primary Nagios process. In the end, we’ll be monitoring the states of various services on the servers, including the ones seen in the screenshot above (Apache processes, APT, Current Load, Current Users, Disk Space, Dovecot, FTP, HTTP, MySQL, SMTP, SSH, Swap, Total Processes, and Zombie Processes). We will also receive notifications by email whenever something goes wrong:

Nagios Email Notification

Please note that this guide is meant to get you up and running quickly, and that it’s not a substitute for the official Nagios documentation. If you want to know what all of the different configuration options do (or can do), please consult the (excellent) documentation.

Setting Up The Nagios Server

The steps in this section should just be done on the main Nagios server, not the clients it will be monitoring. We’ll get to those later!

This procedure should be quite similar on other distributions if you use their package managers (yum, yast, urpmi, etc.) or install Nagios from source, but no guarantees.

  1. Let’s become root so we don’t have to prepend sudo to everything:
    sudo -s
  2. If you want to make use of Nagios’ web interface and Apache isn’t already installed:
    apt-get install apache2

    It’s entirely possible to use something like nginx or lighttpd to serve the interface, but that is not covered in this guide.

  3. Install Nagios from the package repositories:
    apt-get install nagios3 nagios-nrpe-plugin
  4. Nagios should be accessible at http://nameofnagiosserver/nagios3 already! We still have some configuration to do, though.

  5. Stop Nagios:
    /etc/init.d/nagios3 stop
  6. Add a new user for the web interface, e.g. patrick. The default configuration grants all security permissions to the user nagiosadmin, but we’ll change that to the name of the new user, too:
    htpasswd -c /etc/nagios3/htpasswd.users patrick
    perl -p -i -e "s/nagiosadmin/patrick/g" /etc/nagios3/cgi.cfg
  7. The perl command above replaces all occurrences of nagiosadmin with patrick in the file /etc/nagios3/cgi.cfg.

    The users listed in /etc/nagios3/cgi.cfg are effectively global administrators. For regular users, you can still add them as users with htpasswd, but assign privileges by making them Contacts for certain hosts or hostgroups, instead. We’ll get to this later!

  8. If you want to add more user accounts for the web interface:
    htpasswd /etc/nagios3/htpasswd.users john
  9. And if you want to give them superuser privileges:
    perl -p -i -e "s/patrick/patrick, john/g" /etc/nagios3/cgi.cfg

    Go through /etc/nagios3/cgi.cfg manually to see what the different security options do, and to grant more fine-grained privileges to other administrators.

  10. Edit /etc/nagios3/nagios.cfg and change check_external_commands=0 to 1 to allow monitoring commands to be issued through the web interface
  11. On Debian/Ubuntu, run the following commands after setting check_external_commands=1:
    dpkg-statoverride --update --add nagios www-data 2710 /var/lib/nagios3/rw
    dpkg-statoverride --update --add nagios nagios 751 /var/lib/nagios3
  12. Edit /etc/nagios3/conf.d/contacts_nagios2.cfg to match your preferences. Example:
    define contact{
            contact_name                    patrick
            alias                           Patrick Mylund
            service_notification_period     24x7
            host_notification_period        24x7
            service_notification_options    w,u,c,r
            host_notification_options       d,r
            service_notification_commands   notify-service-by-email
            host_notification_commands      notify-host-by-email
            email                           my@emailaddress.com
            }

    And further down:

    define contactgroup{
            contactgroup_name       admins
            alias                   Nagios Administrators
            members                 patrick
            }
  13. Make a host definition for a server you want to monitor by creating a matching config file, e.g for the server ‘tranquillity’, nano -w /etc/nagios3/conf.d/tranquillity_nagios2.cfg, then insert a declaration. Example:
    define host{
            use                     generic-host            ; Name of host template to use
            host_name               tranquillity
            alias                   PatrickMylund.com Web Server
            address                 209.20.82.6
            }

    You can put all of your host definitions in one file if you want, e.g. datacenter1_nagios2.cfg — just remember the _nagios2.cfg at the end of the file name, which is what tells Nagios to load that file (and in the proper format).

  14. Repeat the step above to add a host definition for each server you want to monitor
  15. Move some standard configs to make room for our configured ones:
    mv /etc/nagios3/conf.d/localhost_nagios2.cfg /etc/nagios3/conf.d/localhost_nagios2.cfg.old
    mv /etc/nagios3/conf.d/services_nagios2.cfg /etc/nagios3/conf.d/services_nagios2.cfg.old
    wget http://patrickmylund.com/files/misc/1202-nagios_quickstart/services_nagios2.cfg -O /etc/nagios3/conf.d/services_nagios2.cfg
  16. Edit /etc/nagios3/conf.d/hostgroups_nagios2.cfg. List which hosts (comma-separated) should belong to which groups (debian-servers, http-servers, ssh-servers, and ping-servers), and add some extra hostgroups: db-server, ftp-servers, and mail-servers:
    define hostgroup {
            hostgroup_name  db-servers
                    alias           Database servers
                    members         tranquillity, singularity
            }
     
    define hostgroup {
            hostgroup_name  ftp-servers
                    alias           FTP servers
                    members         tranquillity, singularity
            }
     
    define hostgroup {
            hostgroup_name  mail-servers
                    alias           IMAPS/SMTP servers
                    members         tranquillity
            }

    You can see which services are associated with which hostgroups by looking in /etc/nagios3/conf.d/services_nagios2.cfg.

We’re done with the Nagios server for now. Let’s look at the settings for the Linux servers we want to monitor.

Configuring Monitored Clients

The steps in this section should be done on each Linux host that you want to monitor.

  1. Again, let’s become root:
    sudo -s
  2. Install Nagios’ NRPE module:
    apt-get install nagios-nrpe-server

    Installing the NRPE module is optional, but you won’t be able to run any of Nagios’ scripts directly on the target client if you do not. This is necessary for monitoring system stats, and generally anything that cannot be probed from the outside over the network (by the main Nagios server).

    See the NRPE documentation (PDF) for manual installation instructions, as well as how to get information via SSH (get_by_ssh) instead of NRPE.

  3. Stop NRPE:
    /etc/init.d/nagios-nrpe-server stop
  4. Install a custom nrpe_local.cfg (this will save us some time later):
    mv /etc/nagios/nrpe_local.cfg /etc/nagios/nrpe_local.cfg.old
    wget http://patrickmylund.com/files/misc/1202-nagios_quickstart/nrpe_local.cfg -O /etc/nagios/nrpe_local.cfg

    Go through /etc/nagios/nrpe_local.cfg to see the list of commands that Nagios will be able to execute on hosts running NRPE. By default, NRPE will only run the commands defined in this configuration file, and without any arbitrary arguments. I strongly recommend you stick to this for security purposes.

    On the main Nagios server, all service commands prefixed with check_nrpe_1arg in /etc/nagios3/services_nagios2.cfg are commands defined in /etc/nagios/nrpe_local.cfg on the monitored clients.

  5. Define what hosts are going to be allowed to probe the NRPE module for information (comma-separated). For instance, if the main Nagios server has IP 192.168.1.105:
    perl -p -i -e "s/127.0.0.1/192.168.1.105/g" /etc/nagios/nrpe_local.cfg
  6. If you have a firewall (iptables, ufw, etc.), you need to open for connections on port 5666 on the clients (for NRPE). If the main Nagios server has IP 192.168.1.105, you could do ufw allow proto tcp from 192.168.1.105 to any port 5666, or ufw allow 5666/tcp with Ubuntu’s Uncomplicated Firewall.
  7. Start the NRPE module:
    /etc/init.d/nagios-nrpe-server start

We just about have a basic Nagios setup now!

Testing Nagios

Let’s see if what we’ve set up is working. On the main Nagios server, start the Nagios service:

/etc/init.d/nagios3 start

If all goes well, navigate to e.g. http://192.168.1.105, login with the user credentials you set up earlier, then click on Service Detail in the menu on the left. All of our services will be PENDING, meaning they’ll be checked shortly. You can speed this up by clicking on a service and clicking Re-schedule the next check of this service (this is what is called an External Command).

If any of the service states turn out to be CRITICAL or UNKNOWN, don’t panic — take a look at the different configuration files in /etc/nagios3/conf.d. The settings and commands are pretty straight-forward.

You can find examples of the resulting configuration files in nagios-conf-example.tar.gz. The configs are for a single server (singularity) with the IP address 192.168.2.3.

An Extra Touch

Nagios’ web interface doesn’t look very pretty. We can spice it up a little by changing the CSS. I’ve prepared a modified status.css for your convenience:

mv /etc/nagios3/stylesheets/status.css /etc/nagios3/stylesheets/status.css.old
wget http://patrickmylund.com/files/misc/1202-nagios_quickstart/status.css -O /etc/nagios3/stylesheets/status.css

Now hit F5 in the web interface!

Bear In Mind

  • The easiest way to monitor the Nagios server itself is to pretend it’s yet another server. Install NRPE, set the connection settings, and add it in the host declarations with the other servers.
  • The exclamation mark (!) is meant to separate command arguments in Nagios configuration files. For instance, check_nrpe_1arg!check_swap would mean you’re running check_nrpe_1arg with the argument check_swap.
  • All of the scripts and commands you can issue through Nagios are stand-alone scripts. When configuring Nagios, you can run each command, for instance check_smtp, manually instead of doing tons of trial-and-error with the configuration files:
    /usr/lib/nagios/plugins/check_smtp -H 192.168.1.105
    /usr/lib/nagios/plugins/check_smtp -h
  • All lists in Nagios configuration files are comma-separated.
  • You can set the contact_groups value on any service, host, or hostgroup declaration. Contact groups are defined in /etc/nagios3/conf.d/contacts_nagios2.cfg. Any person in a contact group that has a user account for the web interface (htpasswd.users) can automatically view any hosts and services associated with it.

    Example:

    define hostgroup {
            hostgroup_name  mail-servers
                    alias           IMAPS/SMTP servers
                    members         singularity
                    contact_groups  mailadmins
            }

Again, the best part about what we’ve set up now is that you can go right ahead and forget about it. You’ll receive an e-mail at the contact address specified whenever something is amiss, as well as when it gets better. If I’m right, though, you’ll want to tune your configuration a lot further. We’ve barely touched the surface; Nagios can do much more, and everything is thoroughly documented in the official documentation.

Other useful links:

Blind Search Is Cool

August 9, 2009

in Tools,Web

Blind Search is one of my favorite new toys. It lets you search for something on Google, Bing and Yahoo simultaneously, and lines up the results in three columns. The catch? It doesn’t tell you which search engine each column of search results comes from — rather, it asks you which results you think are the best. I’m pretty sure the results are going to surprise you.

One thing is for sure; whenever I turn out voting for Bing, they’ll gain significantly more of my respect than when they tried to turn me over with a $1.15 meal and a ten grand hidden treasure, especially since the guy behind Blind Search works for Microsoft. It’s too bad that the site isn’t officially endorsed by the company — what better way to win over users and market your product than to empirically demonstrate its prowess?