Bonjour
Cette aide à l'installation vous présente la mise en place et l'usage de sphinxsearch sur un serveur avec un OS debian.
Quelques informations sur sphinx :
http://www.sphinxsearch.com/docs/current.html#about
http://onlamp.com/pub/a/php/2006/02/...-showdown.html
-> Diaporama de Andrew Aksyonoff (Sphinx Technologies) et Peter Zaitsev (MySQL Performance Blog) (du 17 avril 2008, Santa Clara, Californie)
http://assets.en.oreilly.com/1/event...esentation.ppt
Qui utilise SPHINX ?
- Dailymotion (
http://www.haute-disponibilite.net/2...e-dailymotion/)
- Craiglist,Wikimapia, et d'autres sur cette page :
http://www.sphinxsearch.com/powered.html
Prérequis :
- avoir la main "root" sur le serveur.
- pour ma part j'ai une installation non standard nginx, php 5 (php-fpm), mysql 5, les chemins seront donc certainement différents pour vos installations, mais il n'y a rien de bien compliqué.
La version de sphinx installée ici est la 0.9.9 (r2117) du 2 décembre 2009.
-
http://www.sphinxsearch.com/downloads.html
-
http://www.sphinxsearch.com/download...x-0.9.9.tar.gz
Je me suis appuyé sur les pages suivantes pour rédiger ce tutorial :
http://blog.bigbabou.org/2009/sphinx-on-debian-lenny/
http://www.ibm.com/developerworks/li...-sphinxsearch/
http://www.god-object.com/2009/10/20...earch-and-php/
I/Installation
Il faut avoir g++.
Est-il installé ?
si on a :
OK, on continue, sinon on l'installe :
Connexion root :
Code:
$ aptitude install g++
Puis installation des librairies Mysql nécessaires :
Code:
$aptitude install libmysql++-dev libmysqlclient15-dev checkinstall
Pour postgresql, il faudra installer :
Code:
$aptitude install libpg-dev libmysqlclient15-dev checkinstall
installation normale d'un paquet.
Installer sphinx :
(toujours root)
Code:
cd /tmp
wget http://sphinxsearch.com/downloads/sphinx-0.9.9-rc2.tar.gz
tar zxvf sphinx-0.9.9-rc2.tar.gz
cd sphinx-0.9.9-rc2/
wget http://snowball.tartarus.org/dist/libstemmer_c.tgz
tar zxvf libstemmer_c.tgz
./configure --with-libstemmer
(pour postgresl : ./configure -with-pgsql)
make
make install
Si vous avez un problème à la configuration, " can't find MySQL includes files ", assurez vous que libmysql++-dev libmysqlclient15-dev soient bien installées, et assurez vous que vous utilisez bien g++ plutot que gcc en passant le paramètre CXX=g++ en paramètre de configuration.
A ce stade, on en profite pour faire un paquet .deb (réutilisable ultérieurement)
Checkinstall posera quelques questions, répondez y comme cela par exemple :
Code:
0 - Maintainer: [ endeveit{at}gmail.com ]
1 - Summary: [ Sphinx est un moteur de recherche fulltext. ]
2 - Name: [ sphinxsearch-0.9.9 ]
3 - Version: [ r1112 ]
4 - Release: [ 1 ]
5 - License: [ GPL ]
6 - Group: [ web ]
7 - Architecture: [ i386 ]
8 - Source location: [ sphinx-0.9.8-svn-r1112 ]
9 - Alternate source location: [ http://sphinxsearch.com/downloads.html ]
10 - Requires: [ ]
Sauvegardez le fichier .deb
Maintenant vous pouvez terminer l'installation :
Si tout s'est bien passé, vous devriez avoir les fichiers suivants tels quels :
Code:
/usr/local/bin/indexer
/usr/local/bin/indextool
/usr/local/bin/search
/usr/local/bin/searchd
/usr/local/bin/spelldump
/usr/local/etc/exemple.sql
/usr/local/etc/sphinx-min.conf.dist
/usr/local/etc/sphinx.conf.dist
Pour tester l'installation :
Code:
/usr/local/bin/search
qui donnera :
Code:
> /usr/local/bin/search
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff
Usage: search [OPTIONS]
Options are:
-c, --config use given config file instead of defaults
-i, --index search given index only (default: all indexes)
-a, --any match any query word (default: match all words)
-b, --boolean match in boolean mode
-p, --phrase match exact phrase
-e, --extended match in extended mode
-f, --filter only match if attribute attr value is v
-s, --sortby sort matches by 'CLAUSE' in sort_extended mode
-S, --sortexpr sort matches by 'EXPR' DESC in sort_expr mode
-o, --offset print matches starting from this offset (default: 0)
-l, --limit print this many matches (default: 20)
-q, --noinfo don't print document info from SQL database
-g, --group group by attribute named attr
-gs,--groupsort sort groups by
--sort=date sort by date, descending
--rsort=date sort by date, ascending
--sort=ts sort by time segments
--stdin read query from stdin
This program (CLI search) is for testing and debugging purposes only;
it is NOT intended for production use.
Si c'est bon, on continue.
Créez le fichier de conf :
Code:
cp /usr/local/etc/sphinx.conf.dist /usr/local/etc/sphinx.conf
et éditez le pour modifier dans un premier temps les paramètres de "searchd" (à la fin de sphinx.conf) :
(Personnellement, j'ai créé des PATH spécifiques dans /home/logs/sphinx, mais chacun fait ce qu'il veut. N'oubliez pas de créer les répertoires spécifiques !!!)
Code:
searchd
{
log = /home/logs/sphinx/searcd.log
query_log = /home/logs/sphinx/query.log
read_timeout = 5
client_timeout = 300
max_children = 30
pid_file = /home/logs/sphinx/searchd.pid
# max amount of matches the daemon ever keeps in RAM, per-index
# WARNING, THERE'S ALSO PER-QUERY LIMIT, SEE SetLimits() API CALL
# default is 1000 (just like Google)
max_matches = 1000
# seamless rotate, prevents rotate stalls if precaching huge datasets
# optional, default is 1
seamless_rotate = 1
# whether to forcibly preopen all indexes on startup
# optional, default is 0 (do not preopen)
preopen_indexes = 0
# whether to unlink .old index copies on succesful rotation.
# optional, default is 1 (do unlink)
unlink_old = 1
# instance-wide ondisk_dict defaults (per-index value take precedence)
# optional, default is 0 (precache all dictionaries in RAM)
# ondisk_dict_default = 1
mva_updates_pool = 1M
# max allowed network packet size
# limits both query packets from clients, and responses from agents
# optional, default size is 8M
max_packet_size = 8M
# crash log path
# searchd will (try to) log crashed query to 'crash_log_path.PID' file
# optional, default is empty (do not create crash logs)
# crash_log_path = /var/log/crash
crash_log_path = /home/logs/sphinx/crash
# max allowed per-query filter count
# optional, default is 256
max_filters = 256
# max allowed per-filter values count
# optional, default is 4096
max_filter_values = 4096
# socket listen queue length
# optional, default is 5
# listen_backlog = 5
# per-keyword read buffer size
# optional, default is 256K
#
# read_buffer = 256K
# unhinted read size (currently used when reading hits)
# optional, default is 32K
#
# read_unhinted = 32K
}
Ensuite, pour pouvoir l'utilsier avec PHP, il faut le "daemoniser", créez un nouveau fichier sphinx dans /etc/init.d :
/etc/init.d/sphinx qui contiendra :
Code:
#! /bin/sh
# /etc/init.d/sphinx: start the sphinx search daemon.
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
PIDFILE=/home/logs/sphinx/searchd.pid
BINPATH=/usr/local/bin/searchd
SPHINX="--config /usr/local/etc/sphinx.conf"
NAME=searchd
DESC="sphinx search daemon"
test -f $BINPATH || exit 0
# Debian/Ubuntu style
# test ! -r /etc/default/sphinx || . /etc/default/sphinx
running()
{
# No pidfile, probably no daemon present
#
if [ ! -f $PIDFILE ]
then
return 1
fi
pid=`cat $PIDFILE`
# No pid, probably no daemon present
#
if [ -z "$pid" ]
then
return 1
fi
if [ ! -d /proc/$pid ]
then
return 1
fi
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1`
# No syslogd?
#
if [ "$cmd" != "$BINPATH" ]
then
return 1
fi
return 0
}
case "$1" in
start)
echo -n "Starting sphinx search daemon: searchd"
start-stop-daemon --start --quiet --chuid www-data:www-data --exec $BINPATH -- $SPHINX
echo "."
;;
stop)
echo -n "Stopping sphinx search daemon: searchd"
start-stop-daemon --stop --chuid www-data:www-data --retry TERM/1/TERM/1/TERM/4/KILL --quiet --exec $BINPATH --pidfile $PIDFILE
#start-stop-daemon --stop --chuid www-data:www-data --retry TERM/1/TERM/1/TERM/4/KILL --pidfile $PIDFILE
echo "."
;;
restart|force-reload)
echo -n "Restarting sphinx search daemon: searchd"
start-stop-daemon --stop --chuid www-data:www-data --retry TERM/1/TERM/1/TERM/4/KILL --quiet --exec $BINPATH --pidfile $PIDFILE
#start-stop-daemon --stop --chuid www-data:www-data --retry TERM/1/TERM/1/TERM/4/KILL --pidfile $PIDFILE
start-stop-daemon --start --chuid www-data:www-data --quiet --exec $BINPATH -- $SPHINX
echo "."
;;
*)
echo "Usage: /etc/init.d/shpinx {start|stop|restart|force-reload}"
exit 1
esac
exit 0
Et testez votre installation :
Code:
> /etc/init.d/sphinx start
Starting sphinx search daemon: searchd[Tue Jan 26 16:09:44.698 2010] [26409] using config file '/usr/local/etc/sphinx.conf'...
[Tue Jan 26 16:09:44.723 2010] [26409] listening on all interfaces, port=9312
Arrêtez le :
Code:
/etc/init.d/sphinx stop
Stopping sphinx search daemon: searchd.
La prochaine étape :
préparation d'une table à indexer et test dans cette table, et intégration dans PHP.
Vos commentaires seront les bienvenus.
@+
Arnaud