1.到官网下载源代码安装,你也可以根据系统直接下载rpm包安装
我们这里选择源码安装
下载完之后,放到目录/usr/local/src 下
2.解压
tar -xzvf sphinx-2.2.10-release.tar.gz
mv sphinx-2.2.10-release sphinx
cd sphinx
3.编译安装
./configure --prefix=/usr/local/sphinx
make
make install
4.修改配置文件
cd /usr/local/sphinx/etc/
mv sphinx-min.conf.dist sphinx.conf
vim sphinx.conf
下面是里面的内容配置
#
# Minimal Sphinx configuration sample (clean, simple, functional)
#
source src1
{
type = mysql
sql_host = 127.0.0.1
sql_user = root
sql_pass =
sql_db = test //数据库name
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, realname,import_id, account, source ,UNIX_TIMESTAMP(import_time) AS import_timestamp \
FROM contact_list_test
sql_attr_uint = id
sql_attr_timestamp= import_timestamp
}
index test1
{
source = src1
path = /usr/local/sphinx/var/data/test1
}
index testrt
{
type = rt
rt_mem_limit = 128M
path = /usr/local/sphinx/var/data/testrt
rt_field = title
rt_field = content
rt_attr_uint = gid
}
indexer
{
mem_limit = 128M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /usr/local/sphinx/var/log/searchd.log
query_log = /usr/local/sphinx/var/log/query.log
read_timeout = 5
max_children = 30
pid_file = /usr/local/sphinx/var/log/searchd.pid
seamless_rotate= 1
preopen_indexes= 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /usr/local/sphinx/var/data
}
5.生成索引:
cd /usr/local/sphinx/bin
./indexer -c /usr/local/sphinx/etc/sphinx.conf --all
如果此时出现以下错误,
FATAL: failed to lock /usr/local/sphinx/var/data/test1.spl: Resource temporarily unavailable, will not index. Try --rotate option.
请改用命令
./indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate
6.启动spinx搜索服务器:
./usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf
7.更新sphinx
cd /usr/local/sphinx/bin
./indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate
/usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate