BaroqueW

BaroqueW

and his sidekick nikkitaa

BaroqueW RSS Feed
 
 
 
 

Posts tagged Linux

Installing LDAP on Gentoo with MySQL support

One week-end, I endeavoured to install LDAP on my server with a hope it would help me keep my contacts synchronized between work and home, computers and phones. I decided to go for the MySQL storage since I already have such a DB running. It wasn’t so easy after all so I kept my life easier and decided to instead improve the way I dealt with my different sources instead of adding a new one. I hope that the notes below will nonetheless be helpful to someone out there!

Requirements

I will be installing phpldapadmin, so we need PHP with PCRE, SESSION, GETTEXT, XML, and LDAP support. SESSION and GETTEXT should be OK, but not the other two. So find your .ebuild and trail to the list of parameters (–with-xsl –with-ssl etc.):

–with-ldap \
–with-pcre-regex \
–with-xml

Update the ebuild’s digest: ebuild whatever.ebuild digest and reinstall: emerge php5 We will also need ODBC connectors, so emerge myodbc. Note that it wanted to install 90 packets on my machine to satisfy the dependencies (not quite sure what audiofile has to do with MySQL connections though…). Some of those packets needed X11, which, well, was not the case here. Solution: I ended up downloading the sources for unixODBC from http://www.unixodbc.org/, untared them, and used ./configure –enable-gui=no to bypass that (for some reason even changing the ebuild for that package did not help). And then run make, sudo make install as usual. Then, you’re left to install myodbc from the sources as well, from the MySQL website (needs registration, though). Note that to install myODBC you will also need the –enable-gui=no flag. Maybe you will hit the following bug:

/usr/include/mysql/my_global.h:318:24: error: asm/atomic.h: No such file or directory

My solution was to comment out the #include in /usr/include/mysql/my_global.h

Installing LDAP

 Easy on gentoo: emerge openldap

Configuring LDAP

A bit more difficult now. First, let’s say we want to configure it all for the domain example.com, that’s what all the tutorials I have found were about and I am sorry to say that making it work for another domain was too hard for me… Let’s also say that it will all reside on the same server: MySQL, LDAP, phpldapadmin.

Configuring MySQL and ODBC

First we need to create a user ldap for MySQL with password ldap and a database called ldap:

mysqladmin -u root -p create ldap

and then in a mysql command-line:

GRANT ALL ON ldap TO ldap@* IDENTIFIED BY ‘ldap’;

Let’s now create the proper structure in the database. This is done by executing the following scripts in order: testdb_create.sql, testdb_data.sql, backsql_create.sql, and finally testdb_metadata.sql:

mysql -u ldap -p ldap < file.sql

The files are located in openldap-2.4.11/servers/slapd/back-sql/rdbms_depend/mysql/ where openldap-2.4.11 is the folder where you uncompressed openldap’s archive.

Put this in /etc/openldap/ldap.conf:

HOST 127.0.0.1
BASE o=sql,c=RU

And in /etc/openldap/slapd.conf (you need to be root to edit this file):

#######################################################################
# sql database definitions
#######################################################################

 database        sql
 # This following is for the sample database as it installs
 suffix          "o=sql,c=RU"
 rootdn          "cn=root,o=sql,2c=RU"
 rootpw          YourPasswordHere
 dbname          ldap
 dbuser          ldap
 dbpasswd        ldap
 subtree_cond    "ldap_entries.dn LIKE CONCAT(’%',?)"
 insentry_query  "INSERT INTO ldap_entries (dn,oc_map_id,parent,keval) VALUES (?,?,?,?)"

Adding data manually

To add data, in command line, just use ldapadd over a ldif file as follow:

ldapadd -x -D "cn=Manager,dc=example,dc=com" -W -f example.ldif

A ldif file will look like the file below:

dn: cn=max,dc=example,dc=com
cn: max
sn: max
objectclass: top
objectclass: person
userPassword: anotherpassword

Now time to start the beast!

/etc/init.d/slapd restart

Installing phpldapadmin

Since now we have a proper PHP engine with the good modules, it should be easy. Get the latest sources from http://phpldapadmin.sourceforge.net/wiki/index.php/Download and untar them in your webroot folder. Copy conf/config.php.example in conf/config.php and change it if necessary. In our case luckily, it isn’t necessary. Now you should be able to connect and play around in an easier way than from command line!

Using your new LDAP

I will use LDAP with “Address Book” from Apple on MacOSX. Here is how to configure it briefly:

  • Open “Address Book”
  • Go in “Preferences”, “LDAP”
  • Click on the “+” sign
  • Enter a “Name” (anything) for your server and its location in the “Server” field (domain name or IP address)
  • “Port” is 389
  • Let the rest to default to search in all LDAP-domains

Resources

Here are the resources I had to use to put this all together (thanks to everyone who contributed to them):

http://linuxreviews.org/gentoo/ebuilds/

http://phpldapadmin.sourceforge.net/wiki/index.php/PreRequisites

http://www.openldap.org/doc/admin24/quickstart.html

http://www.zytrax.com/books/ldap/ch6/#database

http://www.flatmtn.com/article/setting-ldap-back-sql

http://www.yolinux.com/TUTORIALS/LinuxTutorialLDAP-BindPW.html

http://www.openldap.org/faq/data/cache/1322.html http://www.openldap.org/faq/data/cache/978.html

  • Share/Save/Bookmark
Category: Articles in English, Tech >> Computer | Comments (2)

Copies de sauvegarde

Depuis que mon précédent site a subi les affres du piratage et a disparu avec pertes et surtout avec fracas, je me suis penché sur le problème du backup pour mon nouveau serveur.

J’ai trouvé deux pistes intéressantes pour la sauvegarde des fichiers en général et pour la sauvegarde des bases de données. J’ai aussi trouvé un script pour copier les fichiers automatiquement sur un autre serveur via FTP. À quoi bon en effet faire des sauvegardes si c’est pour les stocker au même endroit que les données à préserver ?

Ces scripts sont valables pour une installation de Linux classique et sont facilement paramètrables. Notez que, encore moins que les auteurs originaux, je ne suis en aucun cas responsable de la perte de vos données en cas de problème. Ces scripts marchent très bien dans mon cas mais je ne peux pas garantir qu’ils correspondent à votre configuration et votre usage. Pour plus de détails, je joins la page original sur laquelle j’ai trouvé le script afin que vous puissiez juger sur pièce.

Backup de données

Je ne vais pas mettre le code source ici, il est sur la page liée juste au-dessus. La configuration est aisée et se fait au moyen de 5 champs :

COMPUTER=deep
DIRECTORIES="/home"
BACKUPDIR=/backups
TIMEDIR=/backups/last-full
TAR=/bin/tar

1. donne un nom aux sauvegardes
2. dossiers à sauvegarder, séparés par des espaces
3. où mettre les archives
4. emplacement du fichier contenant la date de la dernière sauvegarde complète
5. emplacement de l’outil ‘tar’, a priori /bin/tar

La démarche du script est de faire des sauvegardes incrémentales quotidiennes, puis tous les dimanches une sauvegarde complète est faite. Enfin, tous les premiers du mois, une sauvegarde complète est faite qui sera conservée (alors que les sauvegardes quotidiennes et hebdomadaires sont supprimées chaque semaine).

À noter donc que si on commence à utiliser le script un autre jour que le premier du mois, il faut recourir à l’astuce suivante :

date +%d%b < /backups/last-full/myserver-full-date

En supposant que /backups/last-full est votre variable TIMEDIR.

Ce script vous permet au final de conserver une copie de vos sites webs, fichiers de configuration, documents divers, etc.

Backup des bases de données

De même, je ne vais pas revenir ici sur le code source du programme, plutôt bien expliqué et fourni sur SourceForge.

La configuration est simple : login de l’utilisateur ayant les droits sur les tables MySQL à sauvegarder, mot de passe, hôte de la base de données (on peut le faire à distance donc), liste des bases de donnés à sauvegarder de façon quotidienne et hebdomadaire, dossier où placer les sauvegardes, niveau de verbosité, taille maximale, adresse email à laquelle envoyer les rapports/données, etc.

Dans les options avancées, il est possible de sauvegarder certaines tables uniquement tous les mois (comme les tables internes de mysql) ou de configurer le style de backup (avec ou sans création de table, grouper les backups ou en faire un par base de données, compression, etc.).

Au final on a un outil très complet et facilement paramètrable.

Transfert vers serveur distant via FTP

#!/bin/bash

filenames="/your/folder/filebackup /another/folder/mysqlbackup"
hostname="IP.address.ofthe.remotehost"
remotefolder="/distant/folder/forthe/backups"
username="login"
password="password"

ncftpput -u $username -p $password -R -S .tmp -V  $hostname $remotefolder $filenames

Je pense que ce script parle de lui même. Dans filenames, mettez la liste des dossiers à copier, avec leur chemin aboslu, séparés par un espace. Vous pouvez préciser le dossier de destination. Enfin renseignez bien les champs hostname/username/password avec le compte FTP à utiliser.

La bonne idée est évidemment d’inclure les dossiers mentionnés plus haut (pour les fichiers et pour MySQL).

Un petit coup de cron

Tous les scripts ci-dessus ne serviront à rien si ils ne sont pas exécutés régulièrement. Pour exécuter des programmes de façon périodique, Linux utilise Cron.

En tant que root, exécutez ‘crontab -e’ et ajoutez les lignes suivantes :

45 0 * * * /bin/bash /scripts/automysqlbackup.sh.2.5
0  1 * * * /bin/bash /scripts/filebackup.sh
30 5 * * 0 /bin/bash /scripts/copytodistantserver.sh

Ce n’est qu’un exemple mais cela exécute tous les matins à 00h45 le script de sauvegarde pour MySQL, assez rapide, puis à 1h00 la sauvegarde des fichiers et enfin, tous les dimanches à 5h30, les sauvegardes sont copiées sur un autre serveur. Attention cependant à ne pas lancer toutes les tâches en même temps pour éviter de faire ramer le serveur.

  • Share/Save/Bookmark
Category: Articles en français, Tech >> Computer | Leave a comment

A GPS on your Mac

I just bought a no-name USB GPS receiver in the Swedish store Teknikmagasinet and it’s up and running on my Mac (Leopard 10.5.1 or Ubuntu via Parallels). Story of an installation.

The device is just a small box, the size of a matchbox, that you can connect using the built-in PS2 cable or using the USB cable extension provided in the package (convenient to place the receiver outside or by the window). The package also contains a CD, note really useful (especially the test application) but it gives a very exhaustive list of the NMEA commands the receiver understands. The GPS chip is a Nemerix (not a Garmin, not a SiRF). For $40 to $60, you can find on Amazon similar USB GPS receivers with various chips and features (waterproof, number of channels, etc.).

UbuntuFirst of all, Ubuntu with Parallels. My install is the installation that can be found on the website of Parallels. Remember to connect the USB port to Parallels (Devices>USB>USB-Serial controller) before going any further. Next, go in System>Administration>Synaptics Package Manager under Ubuntu. You can do a search on the string “GPS” and install the packages you feel interested in. At least, you need to install the GPS daemon gpsd and a client: xgps or gpsdrive. Then, start gpsd with ‘gpsd -n -D 3 -p /dev/ttyUSB0‘. If you want to push the envelope any further, go and visit the gpsd web site, otherwise, I provide all the basic informations here. To check your GPS receiver is working, start xgps or gpsdrive. If you see a sort of constellation in xgps representing the various satellites of the GPS system, or if your position shows up properly in gpsdrive, you’re good. If you have a display in xgps but not coordinates on the left side of the screen, it means the signal is too weak. Get the receiver outside or closer to a window, or try to get a clear horizon. To do some debugging, stop gpsd and start it again with ‘gpsd -n -N -D 3 -p /dev/ttyUSB0} to check the messages exchanged between the receiver and the computer. If you see a message saying “satellite data no good”, it means there is no proper reception. See below to screenshots: first, a screen of xgps with a poor reception (”n/a” on the left of the screen) and a screen of gpsdrive with a proper signal (I removed the bottom of the screen that included my coordinates). I didn’t test but this whole setup should be compatible with Kismet.

xgps

gpsdrive

MacOSXNow, let’s have a look at MacOSX. The easiest is to start installing the driver for PL2303 (the USB controller for many GPS receivers) on Prolific’s website. Then, install gpsdX, the OSX version of gpsd. Then start the start the application called ‘gpsdX Config’ and choose ‘/dev/tty.usbserial’, the peripheral created by the driver downloaded on Prolific (obviously if you GPS receiver is bluetooth-enabled, just select one of the /dev/tty.Bluetooth devices from the list). Apply the new settings and you now have a gpsd server running under MacOSX! Next step, finding a client. You have two options: gps2geX that interfaces gpsd with Google Earth (even in its free version), or the MacOSX port of GpsDrive developed by VASS-Softwareentwicklung. The first one obviously needs to have Google Earth installed on your computer. To use gps2geX, start GE, then start gps2geX, next click on “Start gps2geX” and here you are: Google Earth is kept updated regularly with your position! On the other hand, GpsDrive requires the installation of X11 from your copy of the DVD of MacOSX Leopard (or Tiger). Note that Gpsdrive is a PPC binary (but runs on Intel computers via Rosetta). The rest is just like under Ubuntu. Last precision, the use of gpsX is compatible (tested) with KisMAC (Kismet and KisMAC are two tools for wireless networks).

  • Share/Save/Bookmark
Category: Articles in English, Tech >> Computer | Comments (2)

Un GPS sur votre Mac

Je viens récemment d’acquérir un récepteur GPS USB d’entrée de gamme (comprendre, no-name) chez les Suédois de Teknikmagasinet et il tourne sur mon Mac (Leopard 10.5.1 ou Ubuntu via Parallels). Récit d’une installation.

L’appareil se présente sous la forme d’une petite boîte (taille boîte d’allumettes) qui peut se connecter avec un cable PS2 ou USB via la rallonge fournie (pratique pour laisser le recepteur a la fenetre ou dehors dans le jardin). Il y a aussi un CD d’install, anecdotique au niveau des applications mais avec plusieurs guides qui renseignent sur les commandes NMEA que le récepteur reconnaît. Au passage, la puce GPS est une puce Nemerix (pas Garmin ni SiRF).

UbuntuTout d’abord, sous Ubuntu avec Parallels. Mon installation est celle qu’on trouve à télécharger sur le site de Parallels. Rappelez-vous de connecter le port USB à Parallels (Devices>USB>USB-Serial controller) avant de commencer. Ensuite, allez dans System>Administration>Synaptics Package Manager sous Ubuntu. Faites une recherche sur GPS et installez les packages qui vous intéressent (au moins gpsd pour le daemon GPS indispensable et probablement un client: xgps ou gpsdrive sont une bonne idée). Lancez ensuite gpsd avec ‘gpsd -n -D 3 -p /dev/ttyUSB0‘. Si vous voulez pousser plus loin, regardez sur le site de gpsd, pour une utilisation normale, vous avez toutes les explications ici. Pour vérifier que votre GPS marche, lancez xgps ou gpsdrive. Si vous voyez une espece de constellation dans xgps représentant les satellites du système GPS ou bien si votre position s’affiche sur la carte de gpsdrive, c’est gagné. Si vous avez un affichage dans xgps mais pas de coordonnées (partie gauche de l’écran), cela signifie que le signal est trop faible. Rapprochez-vous d’une fenêtre ou tâchez d’obtenir une ligne d’horizon plus dégagée. Si vraiment vous n’obtenez rien, lancez gpsd avec ‘gpsd -n -N -D 3 -p /dev/ttyUSB0‘ pour avoir l’affichage des messages reçus et échangés par le récepteur et l’ordinateur, ça peut aider (notamment “satellite data no good” qui signifie que la réception est mauvaise). Ci-dessous, un aperçu de xgps avec une mauvaise réception (”n/a” à gauche de l’écran) et un aperçu de gpsdrive en fonctionnement (moins le bas de l’écran qui indique les coordonnées précises du récepteur). Dernière précision, a priori ce montage est compatible avec Kismet mais je ne l’ai pas testé.

xgps
gpsdrive

MacOSXPour MacOSX maintenant. Le plus simple est d’installer le driver pour PL2303 (controleur USB de nombreux récepteurs GPS) depuis le site de Prolific. Ensuite, installez gpsdX, version OSX de gpsd. Lancez le programme appelé ‘gpsdX Config’ et choisissez ‘/dev/tty.usbserial‘, périphérique créé par le driver de Prolific (si votre récepteur USB est bluetooth, pas besoin d’installer le driver de Prolific, sélectionnez juste un des /dev/tty.Bluetooth). Appliquez ce changement et vous avez un serveur gpsd qui tourne sur votre Mac ! Maintenant, pour l’utiliser, deux options : soit gps2geX qui interface gpsd avec Google Earth (même en version gratuite), ou le port pour MacOSX de GpsDrive réalisé par VASS-Softwareentwicklung. Le premier nécessite l’installation de Google Earth au préalable. Ensuite il ne reste plus qu’à installer gps2geX, lancer GE puis gps2geX, cliquer sur “Start gps2geX” et vous voilà avec votre position actuelle (et mise-à-jour régulièrement) dans Google Earth ! L’installation de GpsDrive nécessite l’installation de X11 depuis votre DVD de MacOSX Leopard (ou pas Leopard d’ailleurs). À noter que GpsDrive tourne sur PPC (et donc sur Intel via Rosetta). Le reste se déroule comme sous Ubuntu. Dernière précision, l’utilisation de gpsX est compatible (testé) avec KisMAC (Kismet et KisMAC sont deux outils de visualisation de réseaux WiFi).

P.S. : Pour aller plus loin, OpenStreetMap qui fournira à terme les cartes de gpsdrive et qui réunit une communauté d’utilisateurs façon Wikipedia autour de l’édition d’une carte du monde.

  • Share/Save/Bookmark
Category: Articles en français, Tech >> Computer | Comments (3)

Status

  • BaroqueW ecoute desproges dans les fjords
    1 day ago
  • BaroqueW : it is in fact NOT funny to point people in the wrong direction when they're lost
    2 days ago
  • BaroqueW : iphone 3gs, July 31st in Sweden - according to Telia
    3 days ago
  • BaroqueW had a quick look at the book keeping of the holidays... gloups
    4 days ago

Popular posts

My Social Networks

DandyID 43 Things Clipmarks coComment Dailymotion Delicious deviantART Digg Diigo Facebook Flickr Get Satisfaction Guitar Hero HelloTxt Hulu ICQ Imdb Imeem Kiva last.fm Linkedin Netvibes orkut PeoplePond Picasa Plaxo PostCrossing RockBand Scribd Stumbleupon Tagged TripAdvisor Twitpic Twitter Xbox LIVE YouTube

Expand the experience

Blogroll

Internet Map

Meta