Archiv ‘Linux’

Montag, 4. November 2013

MySQL-Parameter mit Perconas Monitoring Plugins in Cacti überwachen

Wer seine MySQL-Installation mit Cacti überwachen möchte, sei Perconas Monitoring Plugins empfohlen. Die Datei (zum Zeitpunkt des Verfassens dieses Artikels war 1.0.5 aktuell) lädt man sich im Download-Bereich des Anbieters herunter.

$ cd /tmp
$ wget http://www.percona.com/redir/downloads/percona-monitoring-plugins/LATEST/percona-monitoring-plugins-1.0.5.tar.gz

Anschliessend entpackt man das Archiv:

$ tar xvzf percona-monitoring-plugins-1.0.5.tar.gz

Danach wechselt man in das cacti-Unterverzeichnis …

$ cd /tmp/percona-monitoring-plugins-1.0.5/cacti

… wo man folgenden Befehl ausführt:

cp -R . /var/www/cacti/

Dies kopiert alle nötigen Dateien (sprich: das ss_get_mysql_stats.php-Script) in das cacti-Root.

Anschliessend erstellt man sich unter MySQL einen Benutzer, welchen das Percona-Script verwenden wird, um die Parameter auszulesen:

GRANT SUPER, PROCESS ON *.* TO 'mysqlmon'@'localhost' IDENTIFIED BY "sikrit";
FLUSH PRIVILEGES;

Die Zugangsdaten erfasst man nun auch noch im Script ss_get_mysql_stats.php.

Anschliessend importiert man das XML-Template mit dem Namen cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.0.5.xml in cacti — dies geschieht über den Menupunkt Import Templates.

Zu guter letzt richte man sich einen neuen Host ein, gibt in das Adressfeld localhost ein und weist dem Host den Typ Percona MySQL Server HT zu. Anschliessend kann man die Graphen generieren.

Debugging

Bei Problemen hilft es, im Script folgende Zeile anzupassen …

...
$debug = TRUE;
...

… und die Kommandozeile, wie sie im cacti-Log auftaucht, in einer interaktiven Shell auszuführen.

ERROR 2013 (HY000): Lost connection to MySQL server at ‚reading initial communication packet‘, system error: 0

Diesem Fehler stand ich zu Beginn gegenüber. Folgende drei Massnahmen lösten das Problem schlussendlich:

  • In /etc/mysql/my.cnf muss die Zeile mit bind-address = ... auskommentiert und der MySQL-Server neu gestartet werden.
  • Dem MySQL-Benutzer mysqlmon muss in der Tabelle user in der Datenbank im Feld Host localhost eingetragen werden.
  • MySQL muss über localhost und nicht über 127.0.0.1 angesprochen werden.

RRD-Dateien werden nicht aktualisiert …

… obwohl das cacti-Log aufzeigt, dass das PHP-Script Werte zurückliefert? Nach einem Debug-Spagat hatte ich die Lösung gefunden. Im cacti-Log las ich etwas in der Form:

...
/usr/bin/rrdtool update /var/www/cacti/rra/mysql_sort_rows_999.rrd --template Sort_merge_passes:Sort_range:Sort_rows:Sort_scan 1383591127:0:522:13426:951
...

Ich führte den Befehl auf der Kommandozeile aus und sah mich mit folgender Fehlermeldung konfrontiert:

ERROR: /var/www/cacti/rra/mysql_sort_rows_999.rrd: illegal attempt to update using time 1383591127 when last update time is 1383594548 (minimum one second step)

Den Unix-Timestamp 1383590086 konvertierte ich mit Bordmitteln in ein lesbares Kalenderdatum und stellte fest, dass die Uhrzeit eine Stunde zurück lag. Ich hatte es also mit einem ganz klassischen Zeitzonen-Problem zu tun!

Um sicher zu gehen, startete ich in eine interaktive PHP-Session:

$ php -a
Interactive mode enabled

php > date_default_timezone_get();
PHP Warning:  date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in php shell code on line 1
PHP Stack trace:
PHP   1. {main}() php shell code:0
PHP   2. date_default_timezone_get() php shell code:1
php > 

Voila! Nachdem ich in der Datei /etc/php5/cli/php.ini folgende Information eingefügt hatte …

...
date.timezone = Europe/Zurich
...

… klappte es plötzlich mit den Updates.

Tags: , , , , ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Installing mod_bwshare on Debian Linux running Apache 2.0.x

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

Recently, I noticed msnbot was spamming my whole upload bandwidth because it seemed to create a complete dump of my photo gallery – several image requests within a minute! After some googling I discovered several Apache modules which promise to get rid of such bots running amok (although there are some concerns about artificially prolonging download times for leechers – beware!). I finally decided to go on with mod_bwshare. In a temporary „dust of war“, I got the wrong impression that I needed to upgrade to Apache 2.0.x to be able to get a precompiled .deb. Well, haha! There isn’t a debian package available right now. Well, okey, at least I’m running the newest Apache now, although I had to

apt-get remove apache
dpkg-reconfigure php4
dpkg-reconfigure php4-mysql
dpkg-reconfigure php4-curl
dpkg-reconfigure php4-imap
dpkg-reconfigure php4-gd

to get back to my „touched working system“ and make PHP aware of Apache 2. Be aware: Everything starts with untouched config files, so make sure you enable error logging in PHP again. Especially if you’re a web-dev like I am, you know about usefulness of

error_reporting = E_ALL

Okey, now straight back to the task. Since all this stuff is open source, we could at least give it a try with compiling and stuff (honestly, I just now enough about compiling to completly havoc a system, but I was a lucky guy in this case). So download the source files:

cd /tmp
wget http://www.topology.org/src/bwshare/bwshare-0.1.3.zip
unzip bwshare-0.1.3.zip

So, there we had’em now, hundreds of lines of codes. As stated on the developers homepage itself, running

cd src/modules/bwshare
apxs2 -c mod_bwshare.c
apxs2 -i mod_bwshare.la

Should do the trick. Nada, first we needed the developer package:

apt-get install apache2-dev

Once again:

apxs2 -c mod_bwshare.c
apxs2 -i mod_bwshare.la

A lot of warnings were displayed, but finally, I read

...
chmod 644 /usr/lib/apache2/modules/mod_bwshare.so

After having succesfully compiled mod_bwshare, I had to create two text-files in /etc/apache2/mods-available/

bwshare.load
bwshare.conf

and pasted the following contents:

LoadModule bwshare_module /usr/lib/apache2/modules/mod_bwshare.so
# Some bandwidth control parameters.
BW_tx1cred_rate         2
BW_tx1debt_max          10
BW_tx2cred_rate         1000
BW_tx2debt_max          1000000

<Location /bwshare-info>
SetHandler bwshare-info
</Location>

<Location /bwshare-trace>
SetHandler bwshare-trace
</Location>
</IfModule>

That was it (if you got that far, you surely know now what comes next – putting symlinks in mods-enabled/ and doing a

apache2ctl graceful

(Thanks to our solaris master Aeschlimann at the University for the graceful hint some time ago – greetz).

Tags: , ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Installing SNMP-Daemon (snmpd) on IPCop for remote monitoring

The Task

After some days of testing I finally found out a relative simple solution to run a SNMP-Daemon on my IPCop-Router.

Package management under Mac OS X

First of all, I had to deal with Debian-packages. This posed some problems to me, because I don’t have any linux box here except the one running IPCop, which hasn’t package-managers installed. After I dived into manuals for dpkg i was able to extract the files on my PowerMac running Mac OS X. Before you can execute the shell command below, you need to download and install Fink. After that, continue:

dpkg-deb -x <package>.deb <destination-dir>

Installation

You now do have the required files on your workstation, but yet they need to be put on the IPCop-box. Make use of an SFTP-Client, which requires the SSH-Service enabled on the router. With a SSH-connection to the box, I checked the error messages which occured upon start of the snmpd and then went out to look for the additional files required. The ’search file within packages‘-Function of some package-sites helped me a lot!

Packages needed

These 3 Debian-Packages are essential for your success. Download the .debs and extract them to a single folder with the command mentioned above:

  • snmpd (4.2.3-2)
  • libsnmp4.2 (= 4.2.3-2)
  • libwrap0

File locations

I had to copy all files over to IPCop manually, therefore I made this list to monitor all the files necessary.

/lib/libwrap.so.0
/usr/lib/libucdagent-0.4.2.so
/usr/lib/libucdmibs-0.4.2.so
/usr/lib/libsnmp-0.4.2.so

/usr/sbin/snmpd

Caveats

Don’t try to copy snmpd.conf over to the box. In my case, it prevented snmpd to act the way it should. I have no idea where the problem lied, but after deleting snmpd.conf, everything worked fine. I hope this saves you a lot of headaches.

Tags: ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Make Mail.app respect your .mailboxlist when using IMAP

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

Mail.app is a nice, sleek E-Mail-Client which does quite everything you need in everydays use. But there’s one great drawback: Apple engineers sometimes simply miss the point. When accessing IMAP-mailboxes through Mail.app, you’re not only presented all the expected IMAP-folders, but all those crappy dot-hidden-files (.*) in the IMAP-root, even if there is a .mailboxlist, which tells well written (!) Mail-clients which folders to subscribe to (isn’t it even mentioned in a RFC?). Mail.app doesn’t – god knows why. In fact, it seems also to depend on which mail-server your provider uses. If it’s pmdf, you’re most likely to end up the way I am. Another provider I use to store my eMeidi.com-accounts on, there are no such issues at all.

Anyway, while browsing the web I only found some small hints … one worked! There’s some manual work to do, so it’s essential to have SSH-/Telnet-Access to the server where your folders are being stored.

  • Really first, close all your Mail-clients. Safe is safe
  • Second, make a backup-copy of all your IMAP-folders.
  • The clue is to move your IMAP-folders to a subdirectory. I therefore created a folder IMAP/ in my home-directory. Now you can move all folders to IMAP/
  • Configure Mail.app to use „IMAP/“ as folder prefix. This setting is required by all other Mail-clients you use aside
  • Make also sure to update .mailboxlist in your root-directory to point to the new folders
  • If your provider also offers Horde IMP (Webmail), you have to „subscribe“ to the new folders. Don’t forget to point sent-mail and Trash to the new locations. These settings can usually be done under ‚Options‘

I feared to mess it up, so I waited months before I took these steps. Now I wish I had done it earlier. It’s so smooth to see only your mailfolders and all the other .profile, .whatever and .huh being gone forever!

Tags: ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Search & replace stuff in HTML-Files

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

Recently, I had to replace a URL linking to a no longer accurate place in hundreds of HTML-Files (yeah, this sites origin dates even before ST:ENT started. Terrible!).

Well then, I had two choices: Download anything onto my machine, look out for a nice GUI-editor which allows search & replace for whole folders or … well, dive into the web and put a nice shell-script together which does the work for me. Since GUIs are for kids and professors, i chose the second option. Here is the result (you surely notice how much safety measures I took. In the final version, i disabled creation of .tmp-Files, because it would have messed everything even more. I had luck – everything worked out the way I expected it to ;-):

#! /bin/sh
STRSEARCH="www.unibe.ch\/faculties\/humanities_d.html"
STRREPLACE="www.philhist.unibe.ch\/"

if [ -d /var/www/hist ]
then
	# AT HOME
	cd /var/www/hist
else
	# ON UBECX
	cd /u/hist/www
fi

find . -type f -name '*.htm' -print | while read i
do
	cp "$i" "$i.tmp"
	
	if [ -f "$i.tmp" ]
	then
		#echo "s/$STRSEARCH/$STRREPLACE/g"
		sed "s/$STRSEARCH/$STRREPLACE/g" "$i" > "$i.new"
		if [ -f "$i.new" ]
		then
			mv "$i.new" "$i"
		else
			echo "$i.new doesn't exist"
		fi
	else
		echo "$i.tmp wasn't created"
	fi
done

Tags:
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Split MP3 into tracks based on cue-sheet

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

To do this, you need to get Mp3splt and compile it yourself. Don’t worry, it’s easy (otherwise, I couldn’t have made it ‚til here ;-). Check the manual for proper installation steps.

mp3splt -c sheet.cue audio.mp3

Tags: ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) chmod only files/directories

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

Sometimes I’m running amok with

chmod -R 644 .

without thinking it thouroughly. So folders get lost of their execute-flag, and nobody can enter them anymore. Well, here’s the solution:

find . -type d -exec chmod u+x '{}' ';'

Tags: ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Extract single file from a tar.gz-Backup

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

Recently, I accidentally deleted a vital file on my linux server. Thanks to my regular backups by mkcdrec I just needed to have a look for the backup CD. After googling a few minutes, I came out with the appropriate shell command to extract the desired file out of a gzipped tar-archive:

tar -xzv --file=/Volumes/CDrec-29.07.2005/sdb1._var.tar.gz ./www/partyguide/curl/config.txt

This command recreated the directory structure in the current working dir (make sure you’re not cd-ed into the CD mount point, otherwise it can’t write out).

Tags: , ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Download page with all linked files

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

When the end of the semester gets close, I usually get into a rush and try to download all online material of the lectures. Being tired of clicking through thousands of pages, I remembered wget. A very useful tool, not just to download … err … thumbs and their linked close-ups ;-)

The following command will do the trick:

wget -r -np -nd <url>

You end up having all links recursively downloaded -r, but tell wget not the step up a level -np, and finally, we don’t want to have put the files in nested directories -nd. That’s it, alreay, straight and steady.

To just download files of special type, I recommend adding the following switch:

wget -r -np -nd -A *.pdf <url>

Tags: , , ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen

Sonntag, 3. November 2013

(Aus dem Archiv) Batch rename directories

Der vorliegende Artikel habe ich ursprünglich irgendwann einmal ab 2002 auf meinem damaligen Linux-Entwicklungsserver im Web publiziert. Da ich das bloggen erst 2005 entdeckt habe, waren die Tipps in einer grossen HTML-Seite untergebracht. Anlässlich einer Aufräumaktion auf dem Server habe ich mich entschieden, die „Perlen“ über meine heutige Kommunikationsplattform ins Web zu posaunen. Seitdem ich die Artikel verfasst habe, sind viele Tage ins Land gegangen — ob der Artikel noch Gültigkeit hat, entscheidet der geneigte Leser selber.

With this little script, you can batch rename directories in current folder AND subfolders

#!/bin/sh

SEARCH="set"
REPLACE="s"

for ITEMOLD in `find . -type d`
do
	echo "Processing '$ITEMOLD'"
	ITEMNEW=`echo $ITEMOLD | sed "s/$SEARCH/$REPLACE/g"`
	#echo "After search/replace: '$ITEMNEW'"
	
	if [ $ITEMOLD != $ITEMNEW ]
	then
	
		if [ ! -d "$ITEMNEW" ]
		then
			echo "Attempting to rename '$ITEMOLD' to '$ITEMNEW'"
			mv "$ITEMOLD" "$ITEMNEW"
			
			if [ ! -d "$ITEMNEW" ]
			then
				echo "[-] Renaming seems to have failed - '$ITEMNEW' doesn't exist"
				exit 1
			else	
				echo "[+] Success"
			fi
		else
			echo "[-] '$ITEMNEW' already exists"
		fi
	
	else
		echo "[i] '$ITEMOLD' does not match expression, skipping"
	fi
	
	echo ""
done

exit 0

Tags: , ,
Labels: Linux

Keine Kommentare | neuen Kommentar verfassen