<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>David Goodwin &#187; sysadmin</title>
	<atom:link href="http://codepoets.co.uk/tag/sysadmin/feed/" rel="self" type="application/rss+xml" />
	<link>http://codepoets.co.uk</link>
	<description>PHP, running, family stuff, Bromsgrove and other bits</description>
	<lastBuildDate>Tue, 24 Jan 2012 11:20:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>netstat &#8211;tcp -lp output not showing a process id</title>
		<link>http://codepoets.co.uk/2011/netstat-tcp-lp-output-not-showing-a-process-id/</link>
		<comments>http://codepoets.co.uk/2011/netstat-tcp-lp-output-not-showing-a-process-id/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 14:13:51 +0000</pubDate>
		<dc:creator>David Goodwin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[nfs]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://codepoets.co.uk/?p=459</guid>
		<description><![CDATA[I often use &#8216;netstat &#8211;tcp -lpn&#8217; to display a list of open ports on a server &#8211; so i can check things aren&#8217;t listening where they shouldn&#8217;t be (e.g. MySQL accepting connections from the world) and so on. Obviously I firewall boxes; but I like to have a reasonable default incase the firewall decides to &#8230; <a class="read-excerpt" href="http://codepoets.co.uk/2011/netstat-tcp-lp-output-not-showing-a-process-id/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I often use &#8216;netstat &#8211;tcp -lpn&#8217; to display a list of open ports on a server &#8211; so i can check things aren&#8217;t listening where they shouldn&#8217;t be (e.g. MySQL accepting connections from the world) and so on. Obviously I firewall boxes; but I like to have a reasonable default incase the firewall decides to flush itself randomly or whatever.</p>
<p>Anyway, I ran &#8216;netstat &#8211;tcp -lpn&#8217; and saw something like the following :</p>
<pre>tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      3355/mysqld
tcp        0      0 0.0.0.0:54283           0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      1940/portmap</pre>
<p>Now &#8216;mysqld&#8217; looks OK &#8211; and portmap does (well, I need it on this box). But what on earth was listening on port 54283, and why is there no process name/pid attached to it?</p>
<p>After lots of rummaging, and paranoia where I thought perhaps the box had been rooted, I discovered it was from an NFS mount (which explains the lack of a pid, as it&#8217;s kernel based).</p>
<pre>lsof -i tcp:54283</pre>
<p>Didn&#8217;t help either. Unmounting the NFS filesystem did identify the problem &#8211; and the entry went away.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepoets.co.uk/2011/netstat-tcp-lp-output-not-showing-a-process-id/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Checking varnish configuration syntax</title>
		<link>http://codepoets.co.uk/2011/checking-varnish-configuration-syntax/</link>
		<comments>http://codepoets.co.uk/2011/checking-varnish-configuration-syntax/#comments</comments>
		<pubDate>Wed, 01 Jun 2011 11:35:32 +0000</pubDate>
		<dc:creator>David Goodwin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://codepoets.co.uk/?p=419</guid>
		<description><![CDATA[If you&#8217;ve updated your varnish server&#8217;s configuration, there doesn&#8217;t seem to be an equivalent of &#8216;apachectl configtest&#8217; for it, but you can do : varnishd -C -f /etc/varnish/default.vcl If everything is correct, varnish will then dump out the generated configuration. Otherwise you&#8217;ll get an error message pointing you to a specific line number.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve updated your varnish server&#8217;s configuration, there doesn&#8217;t seem to be an equivalent of &#8216;apachectl configtest&#8217; for it, but you can do :</p>
<pre class="brush:shell">varnishd -C -f /etc/varnish/default.vcl</pre>
<p>If everything is correct, varnish will then dump out the generated configuration. Otherwise you&#8217;ll get an error message pointing you to a specific line number.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepoets.co.uk/2011/checking-varnish-configuration-syntax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automated snapshot backup of an Amazon EBS volume</title>
		<link>http://codepoets.co.uk/2011/automated-snapshot-backup-of-an-amazon-ebs-volume/</link>
		<comments>http://codepoets.co.uk/2011/automated-snapshot-backup-of-an-amazon-ebs-volume/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 16:49:18 +0000</pubDate>
		<dc:creator>David Goodwin</dc:creator>
				<category><![CDATA[python]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://codepoets.co.uk/?p=296</guid>
		<description><![CDATA[I found the following Python script online, but it didn&#8217;t really work too well : http://aws-musings.com/manage-ebs-snapshots-with-a-python-script/ EBS &#8211; Elastic Block Storage &#8230; I had to easy_install boto, to get it to work. I&#8217;m not sure the Debian python-boto package in Lenny is up to date. Anyway, $server now has : from boto.ec2.connection import EC2Connection from &#8230; <a class="read-excerpt" href="http://codepoets.co.uk/2011/automated-snapshot-backup-of-an-amazon-ebs-volume/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I found the following Python script online, but it didn&#8217;t really work too well :</p>
<p><a href="http://aws-musings.com/manage-ebs-snapshots-with-a-python-script/">http://aws-musings.com/manage-ebs-snapshots-with-a-python-script/</a></p>
<p>EBS &#8211; Elastic Block Storage &#8230;</p>
<p>I had to easy_install boto, to get it to work. </p>
<p>I&#8217;m not sure the Debian python-boto package in Lenny is up to date.</p>
<p>Anyway, $server now has :</p>
<p><code></p>
<pre class="brush:python">
from boto.ec2.connection import EC2Connection
from boto.ec2.regioninfo import RegionInfo

from datetime import datetime
import sys

# Substitute your access key and secret key here
aws_access_key = 'MY_AWS_ACCESS_KEY'
aws_secret_key = 'MY_AWS_SECRET_KEY'
# Change to your region/endpoint...
region = RegionInfo(endpoint='eu-west-1.ec2.amazonaws.com', name='eu-west-1')

if len(sys.argv) &lt; 3:
    print "Usage: python manage_snapshots.py volume_id number_of_snapshots_to_keep description"
    print "volume id and number of snapshots to keep are required. description is optional"
    sys.exit(1) 

vol_id = sys.argv[1]
keep = int(sys.argv[2])
conn = EC2Connection(aws_access_key, aws_secret_key, region=region)
volumes = conn.get_all_volumes([vol_id])
print "%s" % repr(volumes)
volume = volumes[0]
description = 'Created by manage_snapshots.py at ' + datetime.today().isoformat(' ')
if len(sys.argv) &gt; 3:
    description = sys.argv[3]

if volume.create_snapshot(description):
    print 'Snapshot created with description: ' + description

snapshots = volume.snapshots()
snapshot = snapshots[0]

def date_compare(snap1, snap2):
    if snap1.start_time &lt; snap2.start_time:
        return -1
    elif snap1.start_time == snap2.start_time:
        return 0
    return 1

snapshots.sort(date_compare)
delta = len(snapshots) - keep
for i in range(delta):
    print 'Deleting snapshot ' + snapshots[i].description
    snapshots[i].delete()
</pre>
<p></code></p>
<p>And then plonk something like the following in /etc/cron.daily/backup_ebs :</p>
<pre class="brush:bash">for volume in vol-xxxx vol-yyyyy vol-zzzz
do
	/path/to/above/python/script.py $volume 7 "Backup of $volume on $(date +%F-%H:%m)"
done</pre>
<p>Which keeps 7 backups for each volume with a time/date stamp in each description.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepoets.co.uk/2011/automated-snapshot-backup-of-an-amazon-ebs-volume/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Varnish + Zope &#8211; Multiple zope instances behind a single varnish cache</title>
		<link>http://codepoets.co.uk/2010/varnish-zope-multiple-zope-instances-behind-a-single-varnish-cache/</link>
		<comments>http://codepoets.co.uk/2010/varnish-zope-multiple-zope-instances-behind-a-single-varnish-cache/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 13:22:23 +0000</pubDate>
		<dc:creator>David Goodwin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://codepoets.co.uk/?p=85</guid>
		<description><![CDATA[I run multiple Zope instances on one server. Each Zope instance listens on a different port (localhost:100xx). Historically I&#8217;ve just used Apache as a front end which forwards requests to the Zope instance. Unfortunately there are periods of the year when one site gets a deluge of requests (for example; when hosting a school site, &#8230; <a class="read-excerpt" href="http://codepoets.co.uk/2010/varnish-zope-multiple-zope-instances-behind-a-single-varnish-cache/">Continue reading <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I run multiple <a title="zope" href="http://zope.org">Zope</a> instances on one server. Each Zope instance listens on a different port (localhost:100xx). Historically I&#8217;ve just used Apache as a front end which forwards requests to the Zope instance.</p>
<p>Unfortunately there are periods of the year when one site gets a deluge of requests (for example; when hosting a school site, if it snows overnight, all the parents will check the site in the morning at around about 8am).</p>
<p>Zope is not particularly quick on it&#8217;s own &#8211; Apache&#8217;s &#8220;ab&#8221; reports that a dual core server with plenty of RAM can manage about 7-14 requests per second &#8211; which isn&#8217;t that many when you consider each page on a Plone site will have a large number of dependencies (css/js/png&#8217;s etc).</p>
<p><a title="varnish homepage" href="http://varnish.projects.linpro.no/">Varnish</a> is a reverse HTTP proxy &#8211; meaning it sits in-front of the real web server, caching content.</p>
<p>So, as I&#8217;m using Debian Lenny&#8230;.</p>
<ol>
<li>apt-get install -t lenny-backports varnish</li>
<li>Edit /etc/varnish/default.vcl</li>
<li>Edit Apache virtual hosts to route requests through varnish (rather than directly to Zope)</li>
<li>I didn&#8217;t need to change /etc/default/varnish.</li>
</ol>
<p>In my case there are a number of Zope instances on the same server, but I only wanted to have one instance of varnish running. This is possible &#8211; but it requires me to look at the URL requested to determine which Zope instance to route through to.</p>
<p>So, for example, SiteA runs on a Zope instance on localhost:10021/sites/sitea. My original Apache configuration would contain something like :﻿﻿</p>
<pre>&lt;IfModule mod_rewrite.c&gt;</pre>
<pre>   RewriteEngine on</pre>
<pre>   RewriteRule ^/(.*) http://127.0.0.1:10021/VirtualHostBase/http/www.sitea.com:80/sites/sitea/VirtualHostRoot/$1 [L,P]</pre>
<pre> &lt;/IfModule&gt;</pre>
<p>To use varnish, I&#8217;ll firstly need to tell Varnish how to recognise requests for sitea (and other sites), so it can forward a cache miss to the right place, and then reconfigure Apache &#8211; so it sends requests into varnish and not directly to Zope.</p>
<p>So, firstly, in Varnish&#8217;s configuration (/etc/varnish/default.vcl), we need to define the different backend server&#8217;s we want varnish to proxy / cache. In my case they&#8217;re on the same server -</p>
<pre>
<div id="_mcePaste">backend zope1 {</div>
<div id="_mcePaste">   .host = "127.0.0.1";</div>
<div id="_mcePaste">   .port = "10021";</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">backend zope2 {</div>
<div id="_mcePaste">   .host = "127.0.0.1";</div>
<div id="_mcePaste">   .port = "10022";</div>
<div id="_mcePaste">}</div>
<div id="_mcePaste">Then, in the 'sub vcl_recv' section, use logic like :</div>
</pre>
<pre>if ( req.url ~ "/sites/sitea/VirtualHostRoot") {</pre>
<pre>   set req.backend = zope1;
}
if ( req.url ~ "/siteb/VirtualHostRoot") {
    set req.backend = zope2;
}</pre>
<p>With the above in place, I can now just tell Apache to rewrite Sitea to :</p>
<p><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: 19px; white-space: normal; font-size: 13px;"> </span></p>
<pre>RewriteRule ^/(.*) http://127.0.0.1:6081/VirtualHostBase/http/www.sitea.com:80/sites/sitea/VirtualHostRoot/$1 [L,P]</pre>
<p>Instead&#8230;.. and now we&#8217;ll find that our site is much quicker <img src='http://codepoets.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  (This assumes your varnish listens on localhost:6081).</p>
<p>There are a few additional snippets I found &#8211; in the vcl_fetch { &#8230; } block, I&#8217;ve told Varnish to always cache items for 30 seconds, and to also overwrite the default Server header given out by Apache etc, namely :</p>
<pre>sub vcl_fetch {

    # ..... &lt;snip&gt; &lt;snip&gt;

    # force minimum ttl for objects

    if (obj.ttl &lt; 30s) {

        set obj.ttl = 30s;

    }

    # ... &lt;snip&gt; &lt;snip&gt;

    unset obj.http.Server;

    set obj.http.Server = "Apache/2 Varnish";

    return (deliver);

}
<div>I'm happy anyway. <img src='http://codepoets.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </div>
<div>Use 'varnishlog', 'varnishtop' and 'varnishhist' to monitor varnish.</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://codepoets.co.uk/2010/varnish-zope-multiple-zope-instances-behind-a-single-varnish-cache/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

