Veerasundaravel's Ruby on Rails Weblog

June 20, 2008

Installing sphinx in linux environment

Login as root!

apt-get install build-essential gcc

# Add new system user sphinx
adduser –system –home /var/sphinx –uid 999 –disabled-password –disabled-login –group sphinx

# Create the dirs
mkdir /var/sphinx/bin
mkdir /var/sphinx/etc
mkdir /var/sphinx/log
mkdir /var/sphinx/lib
mkdir /var/sphinx/run

# Download and compile sphinx
wget http://sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz

tar -xzvf sphinx-0.9.8-rc2.tar.gz

cd sphinx-0.9.8-rc2

./configure

make

make install

# Install sphinx binaries
cp src/indexer src/search src/searchd /var/sphinx/bin/

# Install sphinx configuration (remember to edit as it needs)
cp sphinx.conf.dist /var/sphinx/etc/

# Copy the startup script attached below, instead of attaching I posted that file as another post (https://veerasundaravel.wordpress.com/2008/06/20/sphinx-startup-script-related-to-sphinx-installtion/)
copy that post content and save as a init script file named sphinx

mv sphinx /etc/init.d/

chmod 755 /etc/init.d/sphinx

# This shows your run level
/sbin/runlevel | cut -b 3

# Lets say it is 2…
ln -s /etc/init.d/sphinx /etc/rc2.d/S92sphinx

# Add the correct ownership to sphinx
chown -R sphinx:sphinx /var/sphinx

# Give some restrictions…
chmod -R 711 /var/sphinx/

# Ok we almost done!!
cd /var/spinx/etc

cp -p sphinx.conf.dist sphinx.conf

# And edit this entries in sphinx.conf to look like this:

sql_host                                = localhost
sql_user                                = root
sql_pass                                = (your password)
sql_db                                  = (your database name)
sql_port                                = 3306  # optional, default is 3306

# In section searchd

pid_file = /var/sphinx/run/searchd.pid

query_log = /var/sphinx/log/query.log

log = /var/sphinx/log/searchd.log

address = 127.0.0.1

# section index
path = /var/sphinx/lib/sphinx

Continue to edit the configuration and when you are ready…

Then start sphinx using the command!

/etc/init.d/sphinx start

now you are ready with sphinx, now you can install plugins like acts_as_sphinx, ultrasphinx etc to easily interact with sphinx using your rails application.

Advertisements

Sphinx startup script related to sphinx installtion

Continuing my last post Installing sphinx – https://veerasundaravel.wordpress.com/2008/06/20/installing-sphinx-in-linux-environment/

Here the startup script for the sphinx search engine.

#! /bin/sh
# /etc/init.d/sphinx: start the sphinx search daemon.

PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin

pidfile=/var/sphinx/run/searchd.pid
binpath=/var/sphinx/bin/searchd

SPHINX=”–config /var/sphinx/etc/sphinx.conf”

NAME=searchd
DESC=”sphinx search daemon”

test -f $binpath || exit 0

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 “00” “\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 999 –group 999  –exec $binpath — $SPHINX
echo “.”
;;
stop)
echo -n “Stopping sphinx search daemon: searchd”
start-stop-daemon –stop –chuid 999 –group 999 –retry TERM/1/TERM/1/TERM/4/KILL –quiet –exec $binpath –pidfile $pidfile
echo “.”
;;
restart|force-reload)
echo -n “Restarting sphinx search daemon: searchd”
start-stop-daemon –stop –chuid 999 –group 999  –retry TERM/1/TERM/1/TERM/4/KILL –quiet –exec $binpath –pidfile $pidfile
start-stop-daemon –start –chuid 999 –group 999  –quiet –exec $binpath — $SPHINX
echo “.”
;;
*)
echo “Usage: /etc/init.d/shpinx {start|stop|restart|force-reload}”
exit 1
esac

exit 0

%d bloggers like this: