This Howto covers some SNMP Basics and examples how you can read some values
Introduction
The “Simple Network Management Protocol” is a powerful possibility to query network-devices for information, or even to manage them. It’s often also a security risk. As SNMP is a bit difficult to use at the beginning some administrators just skip over it. This can lead to security holes, when SNMP is activated by default on devices. For example on some HP-Switches I configured the default setting for SNMP was set to “read + write” for “public”. SNMP was limited to the local network, but still this enables all connected servers to shutdown ports and have other fun as they wanted. Often the configuration is like that to enable some configuration tools to control the switches.
You can find more information in the wikipedia article
http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol
What can I do with it?
So what excactly can I do with it? Here some examples
- Manage all your switches over a nice gui – major producers of network hardware often provide some management gui which is based on SNMP
- Automatically query your hardware for some information, like sent packets, packet-loss, printer cartridge status, etc.
- Automatically set some values, or change configurations, e.g. disable ports which are source of a DOS-attack
Basic Principles
MIBs
SNMP is a database with a tree structure. The nodes and leafes of the tree are represented by numeric values. The “Management Information Database” (MIB) translates these numeric values into human understandable values. The tool to manually translate values is “snmptranslate”. Here an example:
Let’s assume you want to check automatically how full are your printercartridges to order new supplies, when they’re used up to 70%. So you need information about which cartridge has which fillstand. Let’s start with the name of the cartridges. In the SNMP-Database the path for the black cartridge would be:
.1.3.6.1.2.1.43.11.1.1.6.1.1 = STRING: "Black Cartridge HP CB540A"
pretty intuitive, hu? But let’s look at the same example using the proper MIB:
.iso.org.dod.internet.mgmt.mib-2.printmib.prtMarkerSupplies.prtMarkerSuppliesTable.prtMarkerSuppliesEntry.prtMarkerSuppliesDescription.1.1 = STRING: "Black Cartridge HP CB540A"
Like this it’s a lot easier to figure out the meaning of the SNMP-Entry’s. Of course with string-values often you can figure out the meaning, just by the value (Black Cartridge HP CB540A is pretty unique), but take integer values and you are lost and really need the MIB.
There are various sites in the net, where you can get MIBs for almost every device out there, one example is this:
http://www.oidview.com/mibs/detail.html
SNMP communities
In protocol version 1 (all I used) the privileges are managed over so called “communities”. With every SNMP-Request you have to provide a community. The SNMP-Server then checks if this community has the necessary rights (read, write) to complete the operation. Otherwise it returns nothing, the request times out. Basically i use the default “public”-community, which normally gives read-rights to quite a lot of values. If you want to enable a more strict security policy, disable the rights for the “public” community and create a new community with a cryptic name, like “Cie5fie9ei” (<- this is an example, create your own). Then you grant the rights to this hard guessable community. Community-names like "read" or "write" are not so smart, because they can be figured out easily.
Programs
SNMP comes with a bunch of programs, which are easy to use (if you know how).
snmpwalk
At the beginning, normally you don’t know exactly which values you can query. So it’s a good idea to just query everything. snmpwalk does exactly this. It walks all tree nodes and leafes and echos them.
snmpwalk -m ALL -Os -c public -v 1 192.168.1.15
- -m ALL : query all MIBs in the default directory (/usr/share/snmp/mibs under my system)
- -Os : some output formatting, for details look in “man snmpcmd”
- -c public : query the public community
- -v 1 : use SNMP-Protocol Version 1 , most simple devices (like printers) just support this version
There are echoed 1180 lines similar like these:
... more lines ...
prtMarkerSuppliesType.1.1 = INTEGER: toner(3)
prtMarkerSuppliesType.1.2 = INTEGER: toner(3)
prtMarkerSuppliesType.1.3 = INTEGER: toner(3)
prtMarkerSuppliesType.1.4 = INTEGER: toner(3)
prtMarkerSuppliesDescription.1.1 = STRING: "Black Cartridge HP CB540A"
prtMarkerSuppliesDescription.1.2 = STRING: "Cyan Cartridge HP CB541A"
prtMarkerSuppliesDescription.1.3 = STRING: "Magenta Cartridge HP CB543A"
prtMarkerSuppliesDescription.1.4 = STRING: "Yellow Cartridge HP CB542A"
... more lines ...
to get the full path use:
snmpwalk -m ALL -Osf -c public -v 1 192.168.1.15
snmpget
just get some specific values
snmpget -OQ -v 1 -c public 192.168.1.15 sysLocation.0
snmptranslate
translate “named” path values into numeric values and vice versa
example, translate the named path to numeric:
snmptranslate -m ALL -On .iso.org.dod.internet.mgmt.mib-2.printmib.prtMarkerSupplies.prtMarkerSuppliesTable.prtMarkerSuppliesEntry.prtMarkerSuppliesDescription.1.1
the output:
.1.3.6.1.2.1.43.11.1.1.6.1.1
January 21st,2010
Misc |
No Comments
I was struggling some time compiling the asuro-Software under Linux 64bit. It simply did not recognise my installed qt3 libs. Some of these steps may not be necessary, but it’s how i got it to work.
Links to the arexx homepage
Sourcecode direct link
http://www.arexx.com/downloads/asuro/asuro_flash_linux_source.zip
Sourcecode Download-Site (if direct link doesn’t work)
http://www.arexx.com/arexx.php?cmd=system&cparam=set_pg_lang(p_asuro_downloads.dat%7CDE%7Ctrue)
Process
apt-get install libqt3-mt libqt3-mt-dev libqt3-headers libqt3-compat-headers
mkdir compile_qtflash
cd compile_qtflash
wget http://www.arexx.com/downloads/asuro/asuro_flash_linux_source.zip
unzip asuro_flash_linux_source.zip
tar -zxvvf QT_Flash.tar.gz
cd qt_flash
export CFLAGS="-DLINUX -D_QT -D_LINUX"
export CPPFLAGS="-DLINUX -D_QT -D_LINUX"
export CXXFLAGS="-DLINUX -D_QT -D_LINUX"
aclocal
automake
./configure --with-qt-includes=/usr/include/qt3 --with-qt-libraries=/usr/lib/qt3
./configure --with-qt-includes=/usr/include/qt3 --with-qt-libraries=/usr/lib/qt3
make
cd qt_flash
qmake -project
qmake
make
December 29th,2009
Misc |
No Comments
The rpm-packages for CentOS can easily be downloaded from http://otrs.org/download/ . Install with yum
wget http://ftp.otrs.org/pub/otrs/RPMS/fedora/4/otrs-2.4.5-01.noarch.rpm
yum install --nogpgcheck otrs-2.4.5-01.noarch.rpm
Don’t forget to disable selinux.
call in your browser http://yourserver.com/otrs/installer.pl and setup the database.
Now install the otrs cronjobs
sudo -u otrs /opt/otrs/bin/Cron.sh
this installs the otrs cronjobs in /var/spool/cron/otrs
Now you just have to setup basic otrs-stuff, like queues and Postmaster-configs. But everything over the otrs web interface.
December 26th,2009
Misc |
No Comments
This backup2l driver encrypts and decrypts backups on the fly with a single password-key found in the file /backup_key/backup_key.txt. Of course you should save the file in some other space or rembember it, because if your harddisk fails and you don’t have the key you can’t restore your backups. Beware: the filelists are not encrypted.
Add this lines to your backup2l conf
CREATE_DRIVER="DRIVER_TAR_BZIP2_ENCRYPT"
USER_DRIVER_LIST="DRIVER_TAR_BZIP2_ENCRYPT"
DRIVER_TAR_BZIP2_ENCRYPT ()
{
case $1 in
-test)
require_tools tar bzip2 mcrypt
test -f /backup_key/backup_key.txt
echo "ok"
;;
-suffix)
echo "tarbz2_encrypt"
;;
-create) # Arguments: $2 = BID, $3 = archive file name, $4 = file list file
tar cj -T $4 --no-recursion | mcrypt -a rijndael-256 -f /backup_key/backup_key.txt > ${3}
;;
-toc) # Arguments: $2 = BID, $3 = archive file name
cat ${3} | mdecrypt -a rijndael-256 -f /backup_key/backup_key.txt | tar tj | sed 's#^#/#'
;;
-extract) # Arguments: $2 = BID, $3 = archive file name, $4 = file list file
cat ${3} | mdecrypt -a rijndael-256 -f /backup_key/backup_key.txt | tar xj --same-permission --same-owner -T $4 2>&1
;;
esac
}
December 2nd,2009
Misc |
No Comments
Until now this page is just a reminder for myself. Explanation of the parameters may follow some time.
# firstpass
ffmpeg -an -pass 1 -threads 4 -i inputfile.mpg -vcodec libx264 -b 1000k -flags +loop+mv4 -cmp 256 \
-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
-me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
-flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 \
-qmax 51 -qdiff 4 \
temp.mp4
# second pass
ffmpeg -i inputfile.mpg -acodec libfaac -ar 44100 -ab 128k -pass 2 -threads 4 \
-vcodec libx264 -b 1000k -flags +loop+mv4 -cmp 256 \
-partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 \
-me_method hex -subq 7 -trellis 1 -refs 5 -bf 3 \
-flags2 +bpyramid+wpred+mixed_refs+dct8x8 -coder 1 -me_range 16 \
-g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qmin 10 \
-qmax 51 -qdiff 4 \
temp.mp4
#rename
mv temp.mp4 outfile.mp4
November 29th,2009
Misc |
No Comments
In diesem Artikel möchte ich kurz meine Erfahrungen während meiner Ausbildung zum Fachinformatiker Systemintegration mitteilen.
Berufsbild
Nähere Informationen zum Berufsbild (=was macht man eigentlich so als Fachinformatiker) findet ihr unter den Links am Ende des Posts. Generell kommt es stark drauf an, was für ein Ziel ihr habt und in welcher Firma ihr die Ausbildung macht, bzw. später arbeitet. In der Ausbildung werden die Grundlagen gelegt, das eigentliche Wissen muss sich jedoch jeder selbst aufbauen. Wer ein Rundum-zurücklehn-wohlfühl-Programm sucht ist mit diesem Beruf sicher falsch bedient oder wird bald frustriert sein.
Voraussetzungen
Berufsschule
Die Ausbildung ist so ausgelegt, dass man in der Berufsschule ALLES von der Pike auf beigebracht wird und zwar in einem sehr gemächlichen Tempo. Das wichtigste ist deshalb eigentlich die Motivation und die Bereitschaft im Unterricht aufzupassen oder zumindest zu erscheinen, schon damit haben genügend Leute Probleme. Dann sollte die Berufsschule auch ohne große Vorkenntnisse zu schaffen sein.
Firma
Hier sind die Voraussetzungen grundverschieden. Während man bei der einen Firma als “professioneller” PC-Träger und Windows-Install-CD-Wechsler beschäftigt wird, darf man bei anderen Firmen schnell ans Linux-Live-System und bekommt eigenständige Aufgaben. Generell ist die Betreuung bei großen Firmen meist strukturierter und “schulähnlicher”. Wem diese Lernform liegt und wer sich eher nicht traut von sich aus loszulegen (weil wenig Vorwissen) sollte sich eher so eine Firma suchen. Ich hatte das Glück meine Ausbildung bei einer etwas kleineren Firma zu machen. Dort war die Ausbildung zwar gelinde gesagt schlecht organisiert, aber dafür wurden mir schnell eigene Projekte übertragen, sobald ich gezeigt hatte, dass ich Ahnung von der Materie habe. Also für Leute mit viel Vorwissen ist sowas auch sehr motivierend. Für mich war der Ausbildungsteil in der Firma wesentlich befriedigender und wichtiger als die Berufsschule. Ich kann daher nur jedem empfehlen sich seine Ausbildungsfirma gut auszusuchen. Also vielleicht nicht bei der erstbesten Stelle bewerben, sondern zunächst bei den vom Themengebiet für einen selbst interessanten Firmen.
Qualität der Ausbildung
Schule
Die Berufsschule München ist technisch gut ausgestattet, leider gibt es einige grundsätzliche und einige hausgemachte Probleme. Ich war 20 als ich die Ausbildung begonnen habe und hatte bereits 13 Jahre Schule hinter mir. Mein Vorwissen in Java war leidlich und ich hatte auch schonmal in anderen Sprachen programmiert außerdem war ich in Linux relativ fit und hatte ein gutes allgemeines PC-Vorwissen (Nickles Büchern sei Dank
). Wer mit ähnlichen Voraussetzungen in die Ausbildung startet wird sich in der Schule rein inhaltlich vor allem in den ersten Jahren ziemlich langweilen. Das Tempo ist gemächlich und das Klassenklima ist oft laut, was natürlich auch nicht unbedingt zur Beschleunigung beiträgt. Trotzdem ist es ganz schön sich immer wieder mit den anderen Klassenkameraden zu treffen und auszutauschen. Gegen Ende des zweiten Schuljahrs und im dritten Schuljahr wird der Stoff dann langsam interessanter. Was auch teilweise frustrierend ist: das erschreckend geringe Fachwissen der Lehrer. Beim Großteil der Lehrer hat man das Gefühl sie wissen genau soviel wie sie wissen müssen, haben sich aber eigentlich nie so richtig mit der Materie auseinander gesetzt. Das frustriert auch viele Schüler, da dadurch oft sehr strenge Vorgaben bei den Übungsaufgaben (z.B. gerade beim Programmieren) herrschen. Das muss man einfach als Methode zur leichteren Korrektur akzeptieren und sollte sich keine großen Gedanken darüber machen.
Firma
Wie schon weiter oben geschrieben unterscheidet sich das von Firma zu Firma sehr extrem. In manchen Firmen wird man als Trage-Muli missbraucht und lernt so gut wie nichts dazu, in anderen Firmen bekommt man sofort ein eignes Projekt und muss sich dann per google mehr oder weniger selbst ausbilden (was durchaus auch ein Vorteil sein kann), in wieder anderen Firmen läuft die Ausbildung dagegen sehr strukturiert ab (was auch ein Nachteil sein kann). Generell würde ich mal sagen:
- macht die Firma Support für große Unternehmen und setzt Windows ein? -> Mit etwas Glück reichts zu Active Directory und Automatisierung, mit Pech wird es dann doch eher PC’s schleppen
- kleinere Firma die Linux einsetzt? -> bei kleinen Firmen ist es oft so, dass sie jeden Mann brauchen. Die Ausbildungsbetreuung ist oft schlecht. Hat man allerdings schon Ahnung darf man oft nach einer kurzen Einarbeitungszeit richtig loslegen und lernt sehr viel, allein durch die Praxiserfahrung. Ideal für doityourself-Lerner und Linux-Freaks.
- größere Firmen wie z.B. die Telekom -> hier ist die Ausbildung oft gut strukturiert und betreut. Allerdings habe ich gehört, dass sehr viele Präsentationen gehalten werden müssen und man eher selten bis garnicht ein Live-System vor die Finger kriegt. Die Ausbildung ist etwas schulischer gehalten.
Was lernt man eigentlich?
Schule
In der Schule lernt man generell nur die Grundlagen und schnuppert in viele Themengebiete hinein, das klappt aber relativ gut und man bekommt einen Überblick. Vertiefen muss man das ganze dann selbst noch.
- Linux-Grundlagen: man, ls, mount, cd, etc. also alles um sich zumindest ein bisschen auf einer Linuxkiste zurecht zu finden
- Windows Active Directory: Ein kleines AD-Netzwerk mit 4 Clients aufsetzen. Alles ganz Basic, aber ein guter Einstieg für Leute die sowas noch nie gemacht haben (wie ich z.B.)
- Elektrotechnische Grundlagen: Wie werden die Daten im Kabel übertragen, Multiplexing, etc. man erfährt einiges interessantes Grundwissen
- Wirtschaft: Kostenkalkulation, Marketing, etc. das volle Programm
- Allgemeines IT-Wissen: Mainboard, SCSI, wie ist ein Prozessor aufgebaut, CD-ROM, etc.
- Allgemeine Kenntnisse: Aufbau einer einfachen HTML-Seite, Organisation von Projekten
- IT-Sicherheit: Sniffen, iptables, etc.
Firma
Kommt ganz drauf an wo man ist und wie man sich anstellt. Generell: je mehr man kann/macht, desto mehr lernt man. Mir wurde eigentlich nichts konkret beigebracht in dem von Schülern gewohnten Sinn (Vortrag von einem Lehrer/Ausbilder). Stattdessen bekam ich eine Aufgabe, bzw. es gab ein zu lösendes Problem. Wie ich das dann anpackte und wo ich die Informationen hernahm, war dem Betrieb relativ egal. Es musste am Schluss halt einfach funktionieren. Wenn ich mal nicht mehr weiter wusste konnte ich aber immer auch meine Kollegen fragen. Hier ein Tipp gerade an Auszubildende: Bitte immer erstmal selbst versuchen und erst an den Ausbilder/Kollegen wenden, wenn garnichts mehr weiter geht. Als Ausgelernter/Ausbilder nervt es furchtbar Fragen zu beantworten, die der Azubi sich auch in 10 Sekunden selbst per google beantworten hätte können. Eine Frage reisst nämlich immer aus dem aktuellen Arbeitsfluss heraus, egal wie einfach und schnell sie zu beantworten ist.
Tipps
!!! Wichtig: Verkürzen der Ausbildung auf 2 Jahre !!!
Dies ist ein wichtiger Punkt auf den teilweise vom Betrieb/von der Schule nicht hingewiesen wird. Normalerweise dauert die Ausbildung 3 Jahre lang. Als Umschüler oder Abiturient kann man gleich von Anfang die Ausbildung in 2 Jahren durchziehen. Man kommt dann in extra Verkürzer-Klassen, die den Stoff etwas zügiger behandeln und in denen auch das Durchschnitts-Alter höher ist. Man hat dann als z.B. 30 jähriger Umschüler nicht den nervigen Zustand mit 17 jährigen in einer Klasse zu sein. Oft ist es auch später möglich auf Grund guter Leistungen zu verkürzen. Ich kann das jedem nur empfehlen, der wirklich das Wissen und die Leistung hat, da die Schule für gute Schüler meist recht frustrierend, weil langsam, ist. Zum Verkürzen noch ein Tipp: Immer mehrere Quellen/Personen befragen. Oft sagt der eine: Verkürzen ist auf keinen Fall möglich und der andere kennt eine Möglichkeit/Lücke wie man es dann doch noch hinkriegt.
Befreiung vom Deutschunterricht, Religionsunterricht
Dies betrifft oft eher die Leute, die mitten im Jahr eine Ausbildung beginnen. Als Abiturient oder mit abgeschlossener Berufsausbildung muss man den Deutschunterricht nicht mehr besuchen. Man muss sich allerdings formell davon abmelden (Formular gibts beim Deutschlehrer). Das gleiche gilt für den Religionsunterricht. Allerdings muss man statt Religion trotzdem einen sogenannten “Pluskurs” besuchen. Eine Art Beschäftigungstherapie (Filme schauen, diskutieren), deren Sinn mir bis heute nicht einleuchtet. Deutsch ist komplett frei.
Klassenliste
Es bietet sich an eine Klassenliste mit e-mail-Adressen/evtl. Telefonnummern anzulegen. So kann bei Fehlstunden schnell die gesamte Klasse informiert werden. So kann der Klassensprecher am Abend noch informieren, dass am nächsten Tag die ersten 3 Stunden frei sind oder ähnliches.
Wenn man was von Lehrern/Schule/Betrieb/IHK will: dranbleiben
Wer erwartet, dass der Betrieb, die Schule oder die Lehrer um die Einhaltung z.B. von Verkürzungsfristen etc. bemühen, der irrt sich. Wer was will muss sich schon früh informieren und selbst darum kümmern. Oft muss man die Informationen den Lehrern buchstäblich aus der Nase ziehen, bzw. sich von einem zum anderen durchfragen. Also wenn man was gehört hat (sei es über Verkürzungsregelungen, etc.) und von der ersten Person abgewimmelt wird immer noch jemand anderes fragen, bzw. an anderer Stelle informieren.
Bewerbung
Wir erhalten immer wieder Bewerbungen, in denen als Kenntnisse so Sachen wie “Computerkenntnisse” oder “Windows, Office” angegeben sind. Das ist so ungenau und allgemein, dass man sich mit solchen Angaben gleich disqualifiziert. Falls Vorkenntnisse vorhanden sind: Bitte konkret nennen (ohne zu schwadronieren und ewige Listen zu verfassen). Falls nicht: Unbedingt aneignen, vor der Bewerbung. z.B. in der Freizeit während des letzten Schuljahres, etc.. Ganz ohne Vorkenntnisse oder zumindest ein gut begründetes Interesse, sollte man sich fragen ob der Beruf überhaupt das richtige für einen ist.
Gehalt
Es gibt wohl wenig nebulösere Sachen als das zu erwartende Gehalt. Oft findet man nur sehr unkonkrete Aussagen dazu und teils werden die Leute in Foren mit niedrigen/hohen Gehaltserwartungen regelrecht nieder gebasht. Naturgemäß unterscheiden sich die Gehälter je nach Arbeitgeber drastisch. In vielen Gesprächen und langer Internet-Recherche habe ich meiner Meinung nach folgende realistische Werte gefunden.
Wichtig, diese Werte gelten für München und sind auch nur meine persönliche Einschätzung. Regional gibt es da oft starke Unterschiede.
Ausbildung (Stand 2007)
Alle angegebenen Werte sind Brutto-Werte. Etwaige Vergünstigungen durch Fahrtkosten-Zuschuss, etc. sind nicht eingerechnet. Meist sind die Gehälter progressiv, so dass man pro Ausbildungsjahr ca. 50€ mehr erhält. Also wenn man mit 500 € beginnt hört man mit 600€ im dritten Lehrjahr auf. Folgende Werte sind Einstiegswerte. Eine Progression von 50-70 € sollte man erwarten. Oft kann man auch mit dem Arbeitgeber über einen Fahrkostenzuschuss verhandeln. z.B. MVV-Monatskarten werden teilweise übernommen.
- wenig – unter 480 Euro pro Monat
- Durchschnitt – 480 bis 550 Euro pro Monat
- viel – über 550 Euro pro Monat
Einstiegsgehalt (Stand 2009)
Alle angegebenen Werte sind Brutto-Werte. Etwaige Vergünstigungen durch Fahrtkosten-Zuschuss, etc. sind nicht eingerechnet.
- wenig – unter 2000 Euro pro Monat
- Durchschnitt – 2000 bis 2600 Euro pro Monat
- viel – über 2600 Euro pro Monat
Linksammlung
November 8th,2009
Misc |
1 Comment
Often when a web-application seems slow it’s not (or not only) the parse time, but also or mayorly database speed. Most scripting-languages don’t act “intelligent” in parsing as it would be best for user experience, but go through the code line by line (whom would expect it otherwise?). So if you have a website containing some slow MySQL-Queries it seems as if all the page just takes a eternity to load. One step would be to put all the page loading into some seperate code-piece and load it later with ajax-technology. This gives a great boost in user-experienced speed, because the most parts of the website load and are already usable before the database content pops in. But otherwise often not the database is the problem, but bad written querys. But how to find them? Luckily mysql already provides us with a feature called slow-query-log which can be activated easily through my.cnf. So just look for this:
vi /etc/mysql/my.cnf
........
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
...........
uncomment these lines and you will have a nice log showing which queries take longer than 2 seconds which is a quite good value. Of course you can set it to what you want. It’s the time in seconds it takes mysql to qualify a query as slow. A plus is the option “log-queries-not-using-indexes” which does exactly this. It’s good to find queries which do a full table scan, but would (perhaps) be more performant if they would use an index. Actually using an index not everytime is better. You have to test this practically. In some cases it is faster to do the full table scan (and have some of the result already in buffers). So just try-and-error. In some cases it gives a huge performance boost. Read this to get more information:
http://dev.mysql.com/doc/refman/5.1-maria/en/mysql-indexes.html
So what to do if you logged some queries which take long? Try to find why the queries are slow. Sometimes there are tables used in a SELECT which data isn’t needed at all at this point (often happens through copy&paste by developers) in other cases perhaps the information would be better retrieved once and stored in memory to be used again. See memcache in this case:
http://php.net/manual/en/book.memcache.php
Perhaps also the data isn’t important for displaying the inital page and can be loaded with ajax, as mentioned above.
A simple Online-Slow-Query Logger
Often in a production environment the slowquery-Log is disabled. Now there’s a problem, you want to enable it, but you can’t restart the database. That’s why I wrote a little php-script which connects to the database and shows slow-queries.
Command:
The only argument is the slow-query-threshold in seconds.
php slow-query-logger.php 2
<?php
if( $argc != 2) die("Wrong number of arguments, just give number of seconds");
$time = $argv[1];
$db = @new mysqli('localhost', 'root', 'somepw', 'somedb');
if (mysqli_connect_errno()) {
die ('could not connect to database: '.mysqli_connect_error().'('.mysqli_connect_errno().')');
}
while(1)
{
$sql = "SELECT * FROM information_schema.PROCESSLIST WHERE time >= ".$time." AND info IS NOT NULL";
$result = $db->query($sql);
if (!$result) {
die ('query error: '.$db->error);
}
while($data=$result->fetch_assoc())
{
echo implode(" ", $data)."\n";
}
sleep(1);
}
$db->close();
?>
October 14th,2009
Misc |
No Comments
Credits
This very good article is written by Marcus Redivo.
http://www.eclectica.ca/howto/openbsd-software-raid-howto.php
I added a warning to stress one point (see red font) which took me 5 hours to find the error, the rest is the orginal tutorial, have fun.
Installing OpenBSD 64Bit on a Software Raid 1 (Mirroring)
This document describes how to set up RAID mirroring on OpenBSD with the RAIDframe driver built into the kernel.
Overview
This procedure assumes OpenBSD 4.5, the amd64 architecture (should work with any other architecture too), and two 320GB sata disks; wd0 and wd1. The steps involved are:
* Install OpenBSD on wd0
* Compile a kernel that supports RAID
* Reboot into RAID-enabled kernel
* Configure RAID partitions on wd1 as half of a broken mirror
* Copy all files onto the RAID partitions
* Reboot into broken mirror
* Reallocate wd0, hot-add it, and reconstruct the broken mirror
* Reboot into complete RAID environment
OpenBSD will not boot from a RAIDframe RAID set at present, so wd0a and wd1a will be set aside as partitions to boot from. Kernel RAID autoconfiguration will prepare the RAID set at boot time, and mount the RAID partitions as per /etc/fstab.
Disk Preparation
I like to start with completely clean disks. If they have been used before, I wipe them before doing anything else, using dd(1). Boot from the OpenBSD distribution CD to get a shell, and execute:
dd if=/dev/zero of=/dev/rwd0c bs=1024000 &
dd if=/dev/zero of=/dev/rwd1c bs=1024000 &
This will take a while. To keep busy, you can set up the Master Boot Record and the BSD disklabel on each disk.
wd0 will get a temporary installation of OpenBSD, but we will only keep the first partition when we are done. We will use this installation to configure and compile a kernel with RAID support. The following sizes will work:
Part Size FS Type Purpose
---- ----- ------- -------------------------------
a: 512M 4.2BSD / (becomes boot partition)
c: ----- unused Entire drive
d: 1024M 4.2BSD /usr
e: 512M 4.2BSD /tmp
f: 1024M 4.2BSD /var
g: 512M 4.2BSD /home
On wd1, we need two partitions; a boot partition, and a partition to contain the RAID set:
Part Size FS Type Purpose
---- ----- ------- -------------------------------
a: 512M 4.2BSD Boot partition
c: ----- unused Entire drive
d: * RAID Everything except boot kernel
It’s important to set the FS Type to RAID for the wd1d Partition, otherwise the System won’t boot !
If later during boot you get the following error, check the FS Type with “disklabel wd1″ and set it to RAID, if this not the case
Kernelized RAIDframe activated
softraid0 at root
root on wd1a swap on wd1b dump on wd1b
warning: /dev/console does not exist
init: not found
panic: no init
Stopped at Debugger + 0x5 .... and so on
Use the following commands to implement this:
fdisk -i wd0
disklabel -E wd0
...
fdisk -i wd1
disklabel -E wd1
...
Reboot from media, and follow the normal installation procedure to install OpenBSD onto wd0. If you followed the steps above, all partitions will already be set up; simply quit disklabel(8) and move on to assigning partitions to their mount points. If you started here, use the instructions above while in disklabel.
Make a RAID-Capable Kernel
To build a kernel, we need the source code, and a configuration. Source code is on the CD:
mount /dev/cd0a /mnt
cd /usr/src
tar xzpf /mnt/src.tar.gz
cd sys/arch/i386/conf
If you don’t have the cd available you can get it also per FTP
for name enter “anonymous”, for password just press ENTER
cd /usr/src
ftp mirror.roothell.org
Connected to mirror.roothell.org.
220 blog.roothell.org FTP server ready.
Name (mirror.roothell.org:user123): anonymous
331 Guest login ok, send your email address as password.
Password:
230 Guest login ok, access restrictions apply.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> get /pub/OpenBSD/4.5/src.tar.gz ./src.tar.gz
ftp> get /pub/OpenBSD/4.5/sys.tar.gz ./sys.tar.gz
tar xzvvf src.tar.gz
tar xzvvf sys.tar.gz
The configuration is the same as GENERIC, with two additions. Create a file called GENERIC.RAID in /usr/src/sys/arch/amd64/conf with the following contents:
---Begin---
#
# GENERIC.RAID - Add kernelized RAIDframe driver
#
include "arch/amd64/conf/GENERIC"
option RAID_AUTOCONFIG # Automatically configure RAID at boot
pseudo-device raid 4 # RAIDframe disk driver
----End----
The following steps will build and install the new kernel:
config GENERIC.RAID
cd ../compile/GENERIC.RAID
make depend && make
mv /bsd /bsd.original
cp bsd /bsd
chmod 644 /bsd
Now reboot into the RAID-enabled kernel.
Second Disk Setup – Make A Broken Mirror
To prepare the second disk, we need to accomplish the following:
* Make it bootable
* Create a RAID configuration
* Apply the configuration to the disk
* Create a disklabel for the RAID device
* Create filesystems in the RAID device partitions
* Make the RAID device autoconfigurable
* Copy our installation onto the new partitions
* Update fstab to refer to the RAID device
* Reboot into the RAID environment
Make the second disk (wd1) bootable:
newfs /dev/rwd1a
mount /dev/wd1a /mnt
cp /bsd /mnt/bsd
cp /usr/mdec/boot /mnt/boot
/usr/mdec/installboot -v /mnt/boot /usr/mdec/biosboot wd1
Create /etc/raid0.conf, which should look like this:
START array
# rows (must be 1), columns, spare disks
1 2 0
START disks
/dev/wd2d
/dev/wd1d
START layout
# sectPerSU SUsPerParityUnit SUsPerReconUnit RAID_level
128 1 1 1
START queue
# queue mode, outstanding request count
fifo 100
Notice that under disks, a (non-existent) wd2 is specified. When the RAID set is created, this serves as a placeholder, and will appear as failed. Once we are ready, we will hot-add wd0 as a spare and reconstruct the mirror on it. Once that is done, this configuration file will be updated to reflect the actual disk assignments.
Now that you have this configuration file, implement it with:
raidctl -C /etc/raid0.conf raid0
raidctl -I 20050900 raid0
raidctl -iv raid0
The argument to -I is a unique identifier that permits RAIDframe to determine which disks belong to which RAID sets; I used the year and month, plus ‘00′ to indicate the first RAID set.
It is time to define the partitions on the RAID device. For my purposes, I used the following:
Part Size FS Type Purpose
---- ----- ------- -------------------------------
a: 512M RAID /
b: 1024M swap swap
c: ----- unused Entire drive
d: 5G RAID /usr
e: 5G RAID /tmp
f: 42G RAID /var
g: * RAID /home
Again, we use disklabel(8) to put this into effect. Once that is done, create filesystems in the partitions that need them, and make the RAID set auto-configurable as a root filesystem:
disklabel -E raid0
...
newfs /dev/rraid0a
newfs /dev/rraid0d
newfs /dev/rraid0e
newfs /dev/rraid0f
newfs /dev/rraid0g
raidctl -A root raid0
Copy the data from the initial installation over to the RAID partitions, making certain to preserve permissions:
mount /dev/raid0a /mnt
(cd /; tar -Xcpf - .) | (cd /mnt; tar -xpf -)
tar: Ustar cannot archive a socket ./dev/log
umount /mnt
mount /dev/raid0d /mnt
(cd /usr; tar -cpf - .) | (cd /mnt; tar -xpf -)
umount /mnt
mount /dev/raid0f /mnt
(cd /var; tar -cpf - .) | (cd /mnt; tar -xpf -)
tar: Ustar cannot archive a socket ./cron/tabs/.sock
tar: Ustar cannot archive a socket ./empty/dev/log
umount /mnt
mount /dev/raid0g /mnt
(cd /home; tar -cpf - .) | (cd /mnt; tar -xpf -)
umount /mnt
(You can ignore the errors; the sockets will be recreated.)
Update /etc/fstab on the broken mirror to point to the raid0 partitions instead of the old wd0 partitions, and reboot:
mount /dev/raid0a /mnt
sed 's/wd0/raid0/g' /mnt/etc/fstab > /mnt/etc/fstab.tmp
mv /mnt/etc/fstab.tmp /mnt/etc/fstab
umount /mnt
reboot
boot> boot wd1a:/bsd
Complete the Mirror Pair
The last step is to integrate the first disk into the mirror pair. We need to update the wd0 disklabel to match wd1, which is easily done by copying:
disklabel wd1 >disklabel.wd1
disklabel -R wd0 disklabel.wd1
There is no need to put a disklabel into the RAID partition, as this will be taken care of when the mirror is reconstructed.
To reconstruct the array, hot add wd0 as a new spare, and then start reconstruction. When reconstructions is complete, rebuild the parity.
Note: Reconstruction and parity rewrite can take a long time. Do not reboot while this is in progress, or you may lose everything and need to start over.
raidctl -a /dev/wd0d raid0
raidctl -vF component0 raid0
raidctl -vP raid0
One last step remains; the RAID configuration file must be updated to remove the bogus wd2 entry and replace it with an entry for wd0:
sed 's/wd2/wd0/g' /etc/raid0.conf > /etc/raid0.conf.tmp
mv /etc/raid0.conf.tmp /etc/raid0.conf
Reboot, and check the RAID status:
reboot
...
raidctl -s raid0
raid0 Components:
/dev/wd0d: optimal
/dev/wd1d: optimal
No spares.
Parity status: clean
Reconstruction is 100% complete.
Parity Re-write is 100% complete.
Copyback is 100% complete.
September 27th,2009
Misc |
4 Comments
Until now when I wrote some scripts I always copied them directly to the Servers .I always thought: “It would be really cool if this were a Debian Package”. I played with the thougth of creating my own packages but it seemed to be very complicated (reading the Debian Standard Howto). Lately I discovered, that the Debian Howto covers a lot more than I actually needed and to create a simple binary package you actually need almost only your scripts. So let’s start.
Package-Folder-Structure
Every Debian Package has to contain at least a directory named “DEBIAN” and this has to contain the files “control”, “postinst” and “prerm”.
“postinst” and “prerm” are scripts which are executed “post installation” or “pre removal”. So you can figure out what they’re for
. The control-file contains information about the package e.g. the name, version, etc.
Folder-Structure
mypackage/
|-- DEBIAN
| |-- control
| |-- postinst
| `-- prerm
Basic control file
A basic control-file could look like this:
Package: mydebianpackage
Version: 0.1
Priority: optional
Architecture: all
Essential: no
Depends: perl
Maintainer: Jonas Garcia Koehel
Provides: mydebianpackage
Description: Some scripts used to do something
detailed description of the fields: http://www.debian.org/doc/debian-policy/ch-controlfields.html
Basic postinst and prerm scripts
They do nothing but have to exist to build the package
Create the folder structure including own scripts
Lets say you want your scripts “script1.pl”, “script2.pl”, and “script3.pl” in the folder /usr/bin and you want “myscripts.conf” in /etc, so you create the following structure inside a build-directory (which can be named freely).
mydebianpackage/
|-- DEBIAN
| |-- control
| |-- postinst
| `-- prerm
|-- etc
| |-- myscripts.conf
|
`-- usr
|-- bin
|-- script1.pl
|-- script2.pl
`-- script3.pl
That’s all
Speaking the magic spell
And Abrakadabra:
dpkg -b ./mydebianpackage/ mydebianpackage_0.1.deb
Ready is your own debian package
Install it on a system
To install it just copy it to a server and type:
dpkg -i mydebianpackage_0.1.deb
to remove it again
apt-get remove mydebianpackage
July 8th,2009
Linux |
1 Comment
Intro
Who isn’t impressed by all these real cool computers in the sciene fictions movies which can be controlled by voice commands, and which talk back. So am I and I thought about how cool it would be if this would be possible today. Totally aware that this is way out of my skill range I thought about an easier solution to make the computer actually talk to me. Remembering an article about chatterbots I searched a bit the net and found AIML ( http://en.wikipedia.org/wiki/AIML ) the “Artificial Intelligence Markup Language”. It’s a xml dialect for creating chatterbot databases. And luckily some programmers already put together some tools. I decided to use “PyAIML” because it seems to be really easy to use. But I can still hear no talking, you think? Just wait a bit, here it comes: espeak. It’s a speech synthesizer which reads out text you pass to it. So let’s get started!
Getting the tools
espeak
I have ubuntu linux and used apt-get to install some tools, it surely works almost the same on other systems with their package systems.
apt-get install espeak espeak-data
PyAIML
Download it here and extract to a directory
http://pyaiml.sourceforge.net/
Some Basic AIML files
Just download and extract as well. I started with the “Standard” AIML file.
http://aitools.org/Free_AIML_sets
A little chatterbot
The PyAIML Page gives pretty clear instructions how to create your own chatbot. Here is mine:
#!/usr/bin/python
import aiml
import commands
k = aiml.Kernel()
# load the aiml file
k.learn("firsttry.aiml")
# set a constant
k.setBotPredicate("name", "Chatty")
while True:
input = raw_input("> ")
response = k.respond(input)
# print out on the shell
print response
# and as speech
print commands.getoutput("/usr/bin/espeak -v en+f4 -p 99 -s 160 \"" + response + "\"")
and here the firsttry.aiml
<?xml version="1.0" encoding="utf-8"?>
<aiml version="1.0.1" xmlns="http://alicebot.org/2001/AIML-1.0.1"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://alicebot.org/2001/AIML-1.0.1 http://aitools.org/aiml/schema/AIML.xsd">
<category>
<pattern>*</pattern>
<template>Hello, I'm glad to see you</template>
</category>
<category>
<pattern>WHAT IS YOUR NAME</pattern>
<template>My name is <bot name="name"></bot></template>
</category>
</aiml>
Invoking the bot
Now you just have to start the program
And it already gives some answers.
Loading jgk.aiml... done (0.02 seconds)
> Hello
Hello, I'm glad to see you
Of course you have to add additional patterns to really let the bot talk a bit. The example files (look in the upper section of this tutorial) are a good start.