CentOS6.4 X64 安装sphinx及sphinx for php扩展(收集)

安装前请先确定安装了常用的组件,然后在官方网站下载最新的Sphinx,

yum install -y python python-devel
http://sphinxsearch.com/downloads/release/  请使用稳定版,线上机器就别玩beta版啦!  安装sphinx
tar zxvf sphinx-2.1.4-release.tar.gz
cd sphinx-2.1.4-release
./configure --prefix=/usr/local/sphinx –-with-mysql
make && make install

在make时如果出现undefined reference to libiconv的错,

错误描述

/usr/local/sphinx/src/sphinx.cpp:20060:undefined reference to `libiconv_open'
/usr/local/sphinx/src/sphinx.cpp:20078: undefined reference to `libiconv'
/usr/local/sphinx/src/sphinx.cpp:20084: undefined reference to `libiconv_close'
collect2: ld returned 1exit status
make[2]:***[indexer]Error1
make[2]:Leaving directory `/home/sphinx/src'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/sphinx/src'
make: *** [all-recursive] Error 1

解决办法:打开configure文件,找到“#define USE_LIBICONV 1”,将注释去掉,并将1改成0。


libsphinxclient 安装(PHP模块需要)
cd api/libsphinxclient
./configure --prefix=/usr/local/sphinx
make &&  make install

安装PHP的Sphinx模块
下载地址:http://pecl.php.net/package/sphinx

wget http://pecl.php.net/get/sphinx-1.3.0.tgz
tar zxf sphinx-1.3.0.tgz
cd sphinx-1.3.0
/usr/local/PHP/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-sphinx=/usr/local/sphinx/
make && make install

安装好后,在安装目录下etc目录下,有份测试数据和配置的样本

cd /usr/local/sphinx/etc
cp sphinx.conf.dist sphinx.conf

将sphinx.conf里面的数据库地址,账号密码改下就好了,再将lvtao.sql导进数据库lvtao
测试执行

/usr/local/sphinx/bin/search lvtao

就可以看到一些查询的相关信息了



创建索引

创建索引命令: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

如果出现下面的报错

"Oops! It seems that sphinx was built with wrong endianess (cross-compiling?)
either reconfigure and rebuild, defining ac_cv_c_bigendian=no in the environment of
./configure script,
either ensure that '#define USE_LITTLE_ENDIAN = 1' in config/config.h"
 
 
  • 1
  • 2
  • 3
  • 4

我是直接把sphinx下面的config/config.h 改成了他提示的这个 #define USE_LITTLE_ENDIAN = 1,之后再make的,


 

(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

以下任务计划的意思是:每隔一分钟执行一遍增量索引,每五分钟执行一遍合并索引,每天1:30执行整体索引。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值