mdadm recovery speeds

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

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

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

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

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

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

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

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.

MySQL table copy

September 6th, 2009

If you want to duplicate a MySQL table (with data), you can do:

mysql> CREATE TABLE tmpscores LIKE scores;
Query OK, 0 rows affected (0.00 sec)
 
mysql> INSERT INTO tmpscores SELECT * from scores;
Query OK, 116 rows affected (0.02 sec)
Records: 116  Duplicates: 0  Warnings: 0
 
mysql>

Alternatively, you can do this in one step:

mysql> CREATE TABLE tmpscores SELECT * FROM scores;
Query OK, 116 rows affected (0.02 sec)
Records: 116  Duplicates: 0  Warnings: 0
 
mysql>

Note that the first method does create indexes for you while the second doesn’t (see here).

nagios-nrpe-server

September 4th, 2009

I went to install nagios-nrpe-server on a Debian machine so I could use my Nagios server to do local service / resource monitoring on that machine but noticed apt-get tried to pull in a lot of dependencies for stuff that I don’t use:

xen1:~# apt-get install nagios-nrpe-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  fping libmysqlclient15off libperl5.10 libpq5 libradius1 libradiusclient-ng2 libsensors3 libsnmp-base libsnmp15 libtalloc1 libwbclient0 mysql-common
  nagios-plugins nagios-plugins-basic nagios-plugins-standard qstat radiusclient1 samba-common smbclient snmp
Suggested packages:
  lm-sensors nagios3 smbfs
The following NEW packages will be installed
  fping libmysqlclient15off libperl5.10 libpq5 libradius1 libradiusclient-ng2 libsensors3 libsnmp-base libsnmp15 libtalloc1 libwbclient0 mysql-common
  nagios-nrpe-server nagios-plugins nagios-plugins-basic nagios-plugins-standard qstat radiusclient1 samba-common smbclient snmp
0 upgraded, 21 newly installed, 0 to remove and 0 not upgraded.
Need to get 18.4MB of archives.
After this operation, 47.3MB of additional disk space will be used.
Do you want to continue [Y/n]? n
Abort.
xen1:~#

A quick google revealed this link, and I was able to quickly adapt the syntax to apt-get:

xen1:~# apt-get --no-install-recommends install nagios-nrpe-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Recommended packages:
  nagios-plugins nagios-plugins-basic
The following NEW packages will be installed
  nagios-nrpe-server
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 35.8kB of archives.
After this operation, 168kB of additional disk space will be used.
Get: 1 http://debian.uchicago.edu lenny/main nagios-nrpe-server 2.12-1 [35.8kB]
Fetched 35.8kB in 0s (111kB/s)       
Selecting previously deselected package nagios-nrpe-server.
(Reading database ... 25376 files and directories currently installed.)
Unpacking nagios-nrpe-server (from .../nagios-nrpe-server_2.12-1_i386.deb) ...
Processing triggers for man-db ...
Setting up nagios-nrpe-server (2.12-1) ...
Starting nagios-nrpe: nagios-nrpe.
xen1:~#

I don’t know if this will cause problems down the line, but as it stands nrpe is working fine and doing what I need it to do.