Archive for the ‘Linux’ Category

Fast and dirty install of Graphite on Debian Squeeze

Monday, January 23rd, 2012

Please note that this is not a production-ready installation document! As the title suggests, this is a fast and dirty installation of Graphite for testing, and assumes you’re installing on a new virtual machine dedicated to Graphite. This will break stuff if you run on an existing server!

These installation instructions are basically the steps from http://graphite.wikidot.com/installation, with a few minor adjustments to work on Debian Squeeze.

First things first:

# cd /root
# apt-get update
# apt-get install bzr

Once bzr’s installed, we can:

# bzr branch lp:graphite

Install Whisper:

# cd graphite/whisper
# python setup.py install

At the time of writing, Whisper can be installed from apt-get on Squeeze, but the version doesn’t match what we’ve pulled Launchpad.

Install Carbon:

# cd ../carbon
# python setup.py install

Now we copy some sample configurations into place:

# cd /opt/graphite/conf
# cp carbon.conf.example carbon.conf
# cp storage-schemas.conf.example storage-schemas.conf

Graphite depends on a number of other packages, and I’ve made every attempt to grab stuff from stock apt repos rather than building (unnecessarily) from source. To see what’s missing, run:

cd /root/graphite
python check-dependencies.py

This should return something like this:

# python check-dependencies.py
[FATAL] Unable to import the 'cairo' module, do you have pycairo installed for python 2.6.6?
[FATAL] Unable to import the 'django' module, do you have Django installed for python 2.6.6?
[FATAL] Unable to import the 'tagging' module, do you have django-tagging installed for python 2.6.6?
[WARNING] Unable to import Interface from zope.interface.
Without it, you will be unable to run carbon on this server.
[WARNING] Unable to import the 'mod_python' module, do you have mod_python installed for python 2.6.6?
mod_python is one of the most common ways to run graphite-web under apache.
Without mod_python you will still be able to use the built in development server; which is not
recommended for production use.
wsgi or other approaches for production scale use are also possible without mod_python
[WARNING]
Unable to import the 'memcache' module, do you have python-memcached installed for python 2.6.6?
This feature is not required but greatly improves performance.
 
[WARNING]
Unable to import the 'ldap' module, do you have python-ldap installed for python 2.6.6?
Without python-ldap, you will not be able to use LDAP authentication in the graphite webapp.
 
[WARNING]
Unable to import the 'twisted' package, do you have Twisted installed for python 2.6.6?
Without Twisted, you cannot run carbon on this server.
[WARNING]
Unable to import the 'txamqp' module, this is required if you want to use AMQP.
Note that txamqp requires python 2.5 or greater.
3 necessary dependencies not met. Graphite will not function until these dependencies are fulfilled.
6 optional dependencies not met. Please consider the warning messages before proceeding.

Now, to get this stuff installed:

# apt-get install python-cairo
# apt-get install python-django-tagging
# apt-get install python-twisted
# apt-get install python-memcache
# apt-get install libapache2-mod-wsgi

I don’t know enough about mod_python (which we’re supposed to install), but the sample vhost configuration below refers to mod_wsgi, so I installed that instead.

Now we configure Apache and modify the sample vhost configuration file provided:

# rm /etc/apache2/sites-enabled/000-default
# cp -a examples/example-graphite-vhost.conf /etc/apache2/sites-enabled/graphite
# cp -a conf/graphite.wsgi.example /opt/graphite/conf/graphite.wsgi
# sed -i s%"@DJANGO_ROOT@/contrib/admin/media/"%"/usr/share/pyshared/django/contrib/admin/media/"% /etc/apache2/sites-enabled/graphite
# sed -i 's%WSGISocketPrefix /etc/httpd/wsgi/%WSGISocketPrefix /var/run/apache2/wsgi%' /etc/apache2/sites-enabled/graphite

Once done, go ahead and restart Apache:

# /etc/init.d/apache2 reload

Finally:

# cd /opt/graphite/webapp/graphite
# python manage.py syncdb
# chown -R www-data:www-data /opt/graphite/storage/
# cd /opt/graphite/
# ./bin/carbon-cache.py start

If that’s all worked, you should be able to pump data into Graphite:

# echo "carbon.installation.test $RANDOM `date +%s`" | nc -w 1 localhost 2003

On the above, if I don’t pass -w 1 to nc, nc just sits there doing nothing.

Now, browsing your server’s http://x.x.x.x/ should load up the Graphite app and hopefully you can see a graph for the data you’ve sent in.

Cleanly creating a Fedora 14 xen domU from an existing Fedora 14 VM

Sunday, February 13th, 2011

I recently found myself wanting to use a Fedora 14 xen domU on my Debian Lenny dom0, but kept running into problems trying to build Fedora VMs using xen-tools. Although I previously wrote about creating VMs using qemu, I didn’t have access to a graphical environment w/ qemu and needed another solution. A quick google search returned the following link, and thankfully this worked a treat.

Using my Rackspace Cloud Servers account, I fired up a Fedora 14 VM and once logged in ran:

# mkdir -p /xen/var/lib/rpm
# mkdir -p /xen/var/log
# touch /xen/var/log/yum.log
# rpm --root /xen --initdb

I then installed the Fedora 14-specific release package:

# rpm -ihv --nodeps --root /xen fedora-release-14-1.noarch

Finally, I went ahead and installed all Core packages (a more minimal package set than Base, which is what was used in the original post):

# yum --installroot=/xen -y groupinstall Core

At this point, I tar’d up /xen and copied over to my xen dom0. Sadly, this Fedora 14 domU wouldn’t boot w/ the vmlinuz-2.6.26-2-xen-amd64 kernel on Debian Lenny, but fortunately I had access to a newer pv-ops kernel that does work. Once I copied kernel modules into the domU and did some final last configurations (setting root password, modifying /etc/fstab), the VM was bootable and appeared to work fine.

In retrospect, I could probably remove some unnecessary packages such as kernel, grub, and so on, but that’s pretty insignificant and aren’t worth messing about with at this point in time.

mdadm recovery speeds

Wednesday, June 16th, 2010

The minimum and maximum speeds can be set via:

/proc/sys/dev/raid/speed_limit_min

and:

/proc/sys/dev/raid/speed_limit_max

These are system-wide values and affect all md block devices. If you wish to alter the speeds for a specific block device (overriding the system-wide values), this can be done through:

/sys/block/md0/md/sync_speed_min

and:

/sys/block/md0/md/sync_speed_max

(replacing md0 with the name of the block device in question)

From the md man page:

While this recovery process is happening, the md driver will monitor accesses to the array and will slow down the rate of recovery if other activity is happening, so that normal access to the array will not be unduly affected. When no other activity is happening, the recovery process proceeds at full speed.

Update EveryDNS w/ a dynamic IP

Wednesday, April 28th, 2010

Although EveryDNS has a supported perl script for updating a DNS record w/ a dynamic IP, I needed something that worked through a proxy and couldn’t entirely figure out how to hack eDNS.pl to make it to work. Looking at eDNS.pl, it seemed straight-forward enough so I did a bare-bones hack in ruby as the Net::HTTP documentation seemed quite good:

#!/usr/bin/ruby 
 
require 'net/http'
require 'base64'
require 'rubygems'
require 'ifconfig'
require 'resolv'
 
# enable / disable debugging (prints response body)
debug = 0
 
# everydns.net details
edns = "dyn.everydns.net"
username = "username"
password = "password"
 
# proxy details
proxy_addr = 'proxy.domain.com'
proxy_port = 8888
 
# domain to update
domain = "some.domain.com"
 
ifconfig = IfconfigWrapper.new('Linux').parse
ip = ifconfig['eth0'].addresses('inet').to_s
 
if ip != Resolv::DNS.new.getaddress(domain)
        res = Net::HTTP::Proxy(proxy_addr, proxy_port).start(edns) { |http|
                req = Net::HTTP::Get.new("/index.php?ver=0.1&ip=#{ip}&domain=#{domain}")
                req.basic_auth(username,password)
                response = http.request(req)
                puts response.body if debug == 1
        }
end

Using the ruby-ifconfig gem is kind of unnecessary, seeing as parsing ifconfig output is straight-forward, but things look a bit cleaner when using it. :) Feedback welcome!

screen

Thursday, April 22nd, 2010

My screen fu is a bit weak; I’ll be using this post to document some useful commands for future reference.

Firstly, the following key combo brings up a listing of windows, allowing you to scroll up or down and select a window to switch to:

C-a "

This is great if you have a number of windows open and want to quickly switch to another window when you don’t know the number of that window. Now, to benefit from this window menu, you need to set window titles appropriately. This can be done by hitting:

C-a A

… and then entering a title for the window in question.

Every now and again, I close windows & re-open and this disrupts my screen window flow when using the previous / next window key combinations. In this situation, you can re-order your windows by going to a window and then:

C-a :

This enters command line mode, and here you can type the following to change the current window’s number:

number 0

In this example, the current window’s number will be changed to 0.

tsocks

Thursday, March 18th, 2010

I recently found myself needing to update a new Debian install using apt-get through a proxy server. You can run either of the following to force apt-get to use an HTTP or FTP proxy:

# export http_proxy=http://username:password@proxyserver.net:port/
# export ftp_proxy=http://username:password@proxyserver.net:port/

However, I didn’t want to start messing about with proxies but use ssh’s SOCKS5 feature instead. A quick Google search turned up the following link, which worked beautifully. After pulling the tsocks .deb package via ssh from another box and installing, it was simply a matter of dumping the following into /root/.tsocks.conf:

server = 127.0.0.1
server_type = 5
server_port = 8888

At that point, I launched the SOCKS5 proxy using:

# ssh -D 8888 user@remotehost

Finally, I was able to:

# tsocks apt-get update
# tsocks apt-get upgrade

It is possible to use tsocks a bit more transparently, but as I only had to send those two commands through the proxy I didn’t have any need. Look at the tsocks man page for more information.

Lastly, make sure you unset $http_proxy or $ftp_proxy if you’ve set either. I forgot that I tried setting $http_proxy and spent far too long trying to debug why tsocks wasn’t working!

Postfix /etc/hosts

Tuesday, September 29th, 2009

So, today I had a client who had a domain with a TTL set to 7 days and the two caching name servers their server was configured to use were seeing different results for their mail A record. I suggested they override DNS with an /etc/hosts entry, but after trying this on my own server I noticed Postfix wasn’t reading /etc/hosts. A quick google revealed this link, and sure enough my Postfix configuration was set to:

# postconf | grep smtp_host_lookup
smtp_host_lookup = dns
#

I then did:

# postconf -e smtp_host_lookup=native
# /etc/init.d/postfix restart

Perhaps a reload would have done the trick, but I did a full restart for good measure.

With this configuration in place, Postfix now checks DNS & /etc/hosts in the order defined in /etc/nsswitch.conf.

I’ve reverted back since I don’t need it checking /etc/hosts, but this was worth noting for future reference.

New xen bridge

Thursday, September 24th, 2009

So, I needed to create a new domU for a friend but didn’t want to pay an additional $1 for a static IP address. What I decided to do was create a dummy interface on my dom0 (dummy0) for a new internal network (10.0.0.0/255.0.0.0) and then create a new bridge on that interface. Basically, I used the following link to achieve this on my xen 3.2.1 install, and this involved creating /etc/xen/scripts/network-bridge-wrapper (with a permission of 755) containing:

#!/bin/sh
/etc/xen/scripts/network-bridge "$@" netdev=eth0
/etc/xen/scripts/network-bridge "$@" netdev=dummy0

I then changed the following in /etc/xen/xend-config.sxp from:

(network-script network-bridge)
(vif-script vif-bridge)

to:

(network-script network-bridge-wrapper)
(vif-script vif-bridge)

After restarting xend, I then created a new virtual machine with IP 10.0.0.2.

Finally:

# iptables -t nat -A POSTROUTING -o eth0 -s 10.0.0.0/255.0.0.0 -j MASQUERADE
# iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to 10.0.0.2:22
# sysctl -w net.ipv4.ip_forward=1

The first iptables rule explicitly matches a source of 10.0.0.0/255.0.0.0 only, as I don’t need this applied to my other domUs. Essentially, it allows me to masquerade outgoing traffic from this internal slice. The second iptables rule port forwards port 2222 to the internal slice. Lastly, the sysctl line is needed for the masquerading to work.

All in all, a bit ghetto, but seems to do the trick for now. :)

irssi proxy

Thursday, September 10th, 2009

I initially tried using znc (which worked well), but noticed the version on my Ubuntu Hardy box was old and had some security issues which hadn’t been addressed. A colleague suggested using irssi’s proxy which I have since done, and so far it’s working well (though no back log like znc has). In irssi, I had to:

/network add freenode
/server add -auto -network freenode irc.freenode.net 6667

I then configured the proxy itself:

/load proxy
/set irssiproxy_password <password>
/set irssiproxy_ports freenode=<port>

(replacing <password> and <port> appropriately)

I then connected to that network and joined my channels:

/server irc.freenode.net
/join <#channel>

Finally, I saved the irssi configuration:

/save

Using Colloquy, I then set up a new connection pointing to this server and using the password and port specified. Colloquy automatically opened up the channels I was in in irssi which confirmed that the proxy was working correctly.

Enabling UTF-8 on Ubuntu Hardy

Wednesday, September 9th, 2009

I noticed that I wasn’t able to type the £ character in alpine on my Ubuntu Hardy virtual machine, even after exporting LANG=”en_GB.UTF-8″. A quick google search returned this page, and although it outlines how to disable UTF-8 I was able to use the information provided to add the en_GB.UTF-8 locale.

First off, you can see which locales are available by issuing the following:

# locale -a

As en_GB.UTF8 was not available on this machine, the first thing I needed to do was to append the following line to /var/lib/locales/supported.d/local:

en_GB.UTF-8 UTF-8

As root, I then ran:

# locale-gen

Finally, I added the following to /etc/environment:

LANG="en_GB.UTF-8"

This saves me having to set $LANG on a user-by-user basis.

Once I logged out and back in again, I was able to type the £ character correctly. You may also need to verify that your terminal client is set to use UTF-8.

On a side note, I’ve seen some other articles that suggest to use alternative methods, so mileage may vary.