码迷,mamicode.com
首页 > 系统相关 > 详细

linux配置sphinx

时间:2017-06-26 22:49:11      阅读:423      评论:0      收藏:0      [点我收藏+]

标签:lib   tmp   密码   dex   htm   distrib   大小限制   list   调整   

 

1. 配置索引

cd /usr/local/sphinx/etc/

cp sphinx.conf.dist sphinx.conf  //备份配置文件,防止改错

vim sphinx.conf

 

配置文件结构:

# 主数据源,(main名字可更改)
source main{
  type     = mysql    #数据库类型
  sql_host  = localhost  #MySQL主机IP
  sql_user  = test     #MySQL用户名
  sql_pass  =        #MySQL密码
  sql_db   = test     #MySQL数据库
  sql_port  = 3306     #MySQL端口
  sql_sock  = /tmp/mysql.sock    #Linux下需要开启,指定sock文件
  sql_query_pre = SET NAMES utf8   #MySQL检索编码
  sql_query_pre = SET SESSION query_cache_type=OFF #关闭缓存
  sql_query = \             #获取数据的SQL语句
    SELECT id, title, content FROM post

  # 以下是用来过滤或条件查询的属性,这里列出的字段将可以进行条件查询,同时不参与全文检索
  #sql_attr_uint = group_id
  #sql_attr_timestamp = date_added
  
}

# 增量数据源(inherited source), 继承主数据源
source src1throttled : main{

}

# 主索引(local index),(main名字可更改)
index main{
  source  = main  # 指定主数据源
  path   = /usr/local/sphinx/var/data/main  # 索引路径
}

# 增量索引(inherited index)
index test1stemmed : test1{

}

# 分布式索引(distributed index)
index dist1{

}

# 实时索引(realtime index)
index rt{

}

# 索引器设置,(调整最小内存到最佳)
indexer{
  mem_limit = 256M  #内存大小限制,默认128M,推荐256M
              #其它用默认即可
}

# 服务进程设置,(监听端口号)
searched{
  #全部默认即可,默认端口号就是9312
}

# 公共配置
common{

}

  

2. 创建索引

创建索引命令:indexer

-c     指定配置文件

--all    对所有索引重新编制索引

--rotate  用于轮换索引,在不停止服务的时候(searchd运行时)增加索引;searchd运行时不加会报错。

--merge  合并索引,增量索引合并到主索引的时候用

 

生成全部索引: /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf --all

或指定索引(例如main): /usr/local/sphinx/bin/indexer -c /usr/local/sphinx/etc/sphinx.conf main

 

(1)如果这里出现报错:

【ERROR: index ‘main‘: sql_connect: Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘】

没找到/tmp/mysql.sock, 通过find / -name mysql.sock -print查找到位置,在配置sphinx.conf里更改正确。

如:mysql_sock = /var/lib/mysql/mysql.sock 保存退出。

 

(2)继续创建索引,警告:

【WARNING: Attribute count is 0: switching to none docinfo】

改sphinx.conf里的docinfo = none就没有警告了。(http://sphinxsearch.com/docs/current.html#conf-docinfo)

 

创建索引出现如下提示,表示生成成功:

技术分享

 

3. 启动Sphinx

技术分享

重建索引:./searchd -c /usr/local/sphinx/etc/sphinx.conf

轮换索引: ./searchd -c /usr/local/sphinx/etc/sphinx.conf goods_list --rotate

      ./searchd -c /usr/local/sphinx/etc/sphinx.conf store_list --rotate

停止服务:./searchd -c /usr/local/sphinx/etc/sphinx.conf --stop

linux配置sphinx

标签:lib   tmp   密码   dex   htm   distrib   大小限制   list   调整   

原文地址:http://www.cnblogs.com/freespider/p/7082604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!