您现在的位置是:首页 > 个人博客日记 个人博客日记

sphinx的安装和使用

2017-04-26 00:00:00

1.到官网下载源代码安装,你也可以根据系统直接下载rpm包安装

sphinxsearch官方网站

我们这里选择源码安装

下载完之后,放到目录/usr/local/src 下

2.解压

  1. tar -xzvf sphinx-2.2.10-release.tar.gz
  2. mv sphinx-2.2.10-release sphinx
  3. cd sphinx

3.编译安装

  1. ./configure --prefix=/usr/local/sphinx
  2. make
  3. make install

4.修改配置文件

  1. cd /usr/local/sphinx/etc/
  2. mv sphinx-min.conf.dist sphinx.conf
  3. vim sphinx.conf

下面是里面的内容配置

  1. #
  2. # Minimal Sphinx configuration sample (clean, simple, functional)
  3. #
  4. source src1
  5. {
  6. type = mysql
  7. sql_host = 127.0.0.1
  8. sql_user = root
  9. sql_pass =
  10. sql_db = test //数据库name
  11. sql_port = 3306 # optional, default is 3306
  12. sql_query = \
  13. SELECT id, realname,import_id, account, source ,UNIX_TIMESTAMP(import_time) AS import_timestamp \
  14. FROM contact_list_test
  15. sql_attr_uint = id
  16. sql_attr_timestamp= import_timestamp
  17. }
  18. index test1
  19. {
  20. source = src1
  21. path = /usr/local/sphinx/var/data/test1
  22. }
  23. index testrt
  24. {
  25. type = rt
  26. rt_mem_limit = 128M
  27. path = /usr/local/sphinx/var/data/testrt
  28. rt_field = title
  29. rt_field = content
  30. rt_attr_uint = gid
  31. }
  32. indexer
  33. {
  34. mem_limit = 128M
  35. }
  36. searchd
  37. {
  38. listen = 9312
  39. listen = 9306:mysql41
  40. log = /usr/local/sphinx/var/log/searchd.log
  41. query_log = /usr/local/sphinx/var/log/query.log
  42. read_timeout = 5
  43. max_children = 30
  44. pid_file = /usr/local/sphinx/var/log/searchd.pid
  45. seamless_rotate= 1
  46. preopen_indexes= 1
  47. unlink_old = 1
  48. workers = threads # for RT to work
  49. binlog_path = /usr/local/sphinx/var/data
  50. }

5.生成索引:

  1. cd /usr/local/sphinx/bin
  2. ./indexer -c /usr/local/sphinx/etc/sphinx.conf --all

如果此时出现以下错误,

  1. FATAL: failed to lock /usr/local/sphinx/var/data/test1.spl: Resource temporarily unavailable, will not index. Try --rotate option.

请改用命令

  1. ./indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate

6.启动spinx搜索服务器:

  1. ./usr/local/sphinx/bin/searchd --config /usr/local/sphinx/etc/sphinx.conf

7.更新sphinx

  1. cd /usr/local/sphinx/bin
  2. ./indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate
  3. /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all --rotate


关注TinyMeng博客,更多精彩分享,敬请期待!
 

站点信息