← All posts

Including Sphinx Config Files

sphinx

I ran into the problem of combining Sphinx configuration files. After Googling around, I couldn’t find an application-level solution, so I decided to make my own.

Let’s create a directory called “sphinx”, where we’ll keep all the Sphinx configuration files:


mkdir /usr/local/etc/sphinx

Next, we put all the config files from different hosts in there, for example:


/usr/local/etc/sphinx/adw0rd.ru.conf
/usr/local/etc/sphinx/pyha.ru.conf

and remove the “indexer” and “searchd” directives from them.

Now we create an “indexer.conf” file there to configure the indexer, and a “searchd.conf” file to configure the Sphinx daemon:


/usr/local/etc/sphinx/indexer.conf
/usr/local/etc/sphinx/searchd.conf

Sample contents of “indexer.conf”:


indexer
{
        mem_limit = 32M
}

Sample contents of “searchd.conf”:


searchd
{
        address = 127.0.0.1
        port = 3312
        log = /var/log/sphinxsearch/searchd.log
        query_log = /var/log/sphinxsearch/sphinx-query.log
        read_timeout = 5
        max_children = 30
        pid_file = /var/run/sphinxsearch/searchd.pid
}

Next, we write a script that combines our config files:


#!/bin/sh
/bin/cat /usr/local/etc/sphinx/*.conf

and specify this file as the Sphinx configuration file in “/usr/local/etc/rc.d/sphinxsearch”:


: ${sphinxsearch_conffile="/usr/local/etc/sphinx.conf.sh"}

Usage Examples

Indexing:


indexer --config /usr/local/etc/sphinx.conf.sh --all

indexer --config /usr/local/etc/sphinx.conf.sh --rotate

Starting the daemon


searchd --config /usr/local/etc/sphinx.conf.sh

/usr/local/etc/rc.d/sphinxsearch start

Comments are closed. Read the original discussion in Russian →