1.安装 sphinx
- wget http://www.sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
- [root@localhost src]# tar zxvf sphinx-0.9.9.tar.gz
- [root@localhost local]# cd sphinx-0.9.9
- [root@localhost sphinx-0.9.9]# ./configure –prefix=/usr/local/sphinx #注意:这里sphinx已经默认支持了mysql
- [root@localhost sphinx-0.9.9]# make && make install # 其中的“警告”可以忽略
2.配置sphinx.conf
找到sphinx.conf的位置,vim进行编辑
source src1
{
type = mysql
sql_host = 127.0.0.1
sql_user = root
sql_pass = root
sql_db = test
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
FROM documents
sql_attr_uint = group_id
sql_attr_timestamp = date_added
sql_query_info = SELECT * FROM documents WHERE id=$id
}
index test1
{
source = src1
path = /var/lib/sphinxsearch/data/test1
docinfo = extern
charset_type = sbcs
}
indexer
{
mem_limit = 32M
}
searchd
{
listen = 9312
listen = 9306:mysql41
log = /var/log/sphinxsearch/searchd.log
query_log = /var/log/sphinxsearch/query.log
read_timeout = 5
max_children = 30
pid_file = /var/run/sphinxsearch/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = /var/lib/sphinxsearch/data
}
3. 使用indexer创建索引
indexer test
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff
using config file './sphinx.conf'...
indexing index 'test'...
collected 4 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 4 docs, 193 bytes
total 0.019 sec, 10074 bytes/sec, 208.80 docs/sec
total 1 reads, 0.000 sec, 0.2 kb/call avg, 0.0 msec/call avg
total 5 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg
4.使用cli命令查询
search -c /etc/sphinxsearch/sphinx.conf