Archive for the ‘Linux’ Category

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.

MySQL table copy

Sunday, 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

Friday, 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.

Changing the timezone on Debian

Friday, August 28th, 2009

Although you can probably just symlink /etc/localtime to your timezone file under /usr/share/zoneinfo, this may be a safer bet:

# dpkg-reconfigure tzdata

I know on Red Hat it is preferred to use “system-config-time” as this also updates some configuration files under /etc/sysconfig, and I suspect reconfiguring the tzdata package is similar as it also updates /etc/timezone.

Starting domUs on boot

Tuesday, August 25th, 2009

So, my dom0 mysteriously rebooted and came back up with no domUs running. There is an /etc/init.d/xenddomains service and it was running, but unfortunately that did not suffice. Looking at /etc/default/xendomains (Debian Lenny):

## Type: string
## Default: /etc/xen/auto
#
# This variable sets the directory where domains configurations
# are stored that should be started on system startup automatically.
# Leave empty if you don't want to start domains automatically
# (or just don't place any xen domain config files in that dir).
# Note that the script tries to be clever if both RESTORE and AUTO are 
# set: It will first restore saved domains and then only start domains
# in AUTO which are not running yet. 
# Note that the name matching is somewhat fuzzy.
#
XENDOMAINS_AUTO=/etc/xen/auto

I’ve since created /etc/xen/auto, created symlinks in /etc/xen/auto pointing back to my domU configuration files in /etc/xen, and am hoping for the best. :)

rename

Tuesday, August 18th, 2009

I’ve been using Linux for quite a while, but sadly I’ve never used rename (or even knew of it’s existence) until today. Basically, I had a whack load of munin-related files containing a specific hostname and I wanted to rename/move all files to reflect a new hostname:

# rename 's/lnx1.domaina.com/lnx2.domainb.com/' lnx1.domaina.com*

So nice and easy. The rename command also has some nice switches, like -n for a dry run (which is always worth using before issuing the final command).

XEN Bridging

Tuesday, August 18th, 2009

I’ve been renting a very inexpensive (though adequately equipped) server from CoreNetworks.net for a while now and finally wanted to try switching my XEN installation (which is all this box is used for) from NAT to bridging to allow me to assign public IPs to my domUs. This looked relatively straight-forward (a few changes in xend-config.sxp) but without using some iptables rules I wasn’t able to get the traffic from outside the dom0 to my domUs (but from the dom0 to domU was fine). After a lengthy google session, I stumbled upon this and the following caught my eye:

switch issue: dom0 has network connectivity but domU’s do not

cause: Some mid and high end enterprise class switches support “port security” or “port mode” settings which define the role of individual ports. Some of these switches will restrict the number of MAC (hardware) addresses that are allowed on a single switch port. In these cases a single MAC address, usually the MAC address of Dom0, is able to communicate with the greater network. DomU’s will each have a MAC address which will be seen on the switch port that the bridge is plugged into.

solution: Disable port security on the switch or the individual port. Alternatively, change the port to a “bridge” or a “switch” port. Consult with your switch vendor documentation or support in order to establish whether or not this a match.

I created a quick support ticket for CoreNetworks.net and was informed that this was most likely the cause, and although they wouldn’t disable port security for my server’s switch port they could add my domU MAC addresses to the switch port. Once this was done, I removed all the unnecessary iptables rules, booted the domUs, and found them to be fully accessible. Yahoo!

svn Roll-back

Wednesday, July 29th, 2009

If you have a file in subversion (svn) which you’ve updated (and committed) and need to roll back to the previous (or older) revision, you can do:

$ svn merge -rCURR:PREV

(where CURR is the current revision and PREV is the revision to roll back to)

To obtain CURR:

$ svn info FILE

… and to find PREV:

$ svn log FILE

(replacing FILE w/ the file in question)

EOF

Wednesday, July 1st, 2009

Since I’m always forgetting the specific syntax (which is another issue, as it’s quite straight-forward), I figured I’d write it down:

cat > /tmp/test << "EOF"
this is a test
it does nothing useful
simply to demonstrate and document
EOF

This is handy when you want to bung a configuration file in a shell script and easily write it out to the filesystem. An alternative (but much less succinct way) would be to do:

FILE=/tmp/test
echo "this is a test" > $FILE
echo "it does nothing useful" >> $FILE
echo "simply to demonstrate and document" >> $FILE