Sphinx--强大的开源全文检索引擎,Coreseek--免费开源的中文全文检索引擎

软件版本:coreseek-4.1

mmseg-3.2.14

autoconf-2.64

老版本的coreseek-3.2和mmseg-3.2.13安装过程一样。

一、安装前准备编译环境

1.1 yum安装编译环境和mysql开发包

# yum install   libtool gcc-c++

# yum install   mysql-devel libxml2-devel expat-devel

1.2 编译安装autoconf

autoconf automake手工编译安装(因aclocal.m4文件由autoconf 2.64生成)。

# tar xzvf autoconf-2.64.tar.gz

# ./configure

# make

# make install

1.3 编译安装automake

# tar xzvf automake-1.11.2.tar.gz

# cd automake-1.11.2

# ./configure

# make

# make install

二、安装mmseg

# cd coreseek-3.2.13

# cd mmseg-3.2.13

# ./bootstrap    #输出的warning信息可以忽略,如果出现error则需要解决

# ./configure --prefix=/usr/local/mmseg

# make

# make install

三、安装coreseek

# cd csft-3.2.13

检查系统环境

# sh buildconf.sh    #输出的warning信息可以忽略,如果出现error则需要解决

配置时要加上mysql数据源的支持

# ./configure --prefix=/usr/local/coreseek  --without-unixodbc --with-mmseg --with-mmseg-includes=/usr/local/mmseg/include/mmseg/ --with-mmseg-libs=/usr/local/mmseg/lib/ --with-mysql

# make

# make install

# cd ..

四、mmseg中文分词测试,coreseek搜索测试

4.1 mmseg中文分词测试

# cd testpack

此时应该正确显示中文,需要预先设置好字符集为zh_CN.UTF-8,确保正确显示中文。

# cat var/test/test.xml

中文分词测试

# /usr/local/mmseg/bin/mmseg -d /usr/local/mmseg/etc/ /root/coreseek-3.2.13/mmseg-3.2.13/src/t1.txt

# /usr/local/mmseg/bin/mmseg -d /usr/local/mmseg/etc/ /root/coreseek-3.2.13/testpack/var/test/test.xml

配置测试,测试是否可以正确运行

# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/sphinx-min.conf.dist

csft-4.0版显示:ERROR: nothing to do.

4.2 coreseek中文全文检索测试

查看正常索引指定数据时的提示信息

# /usr/local/coreseek/bin/indexer -c /root/coreseek-4.1-beta/testpack/etc/csft.conf

# /usr/local/coreseek/bin/indexer -c /root/coreseek-3.2.13/testpack/etc/csft.conf

查看正常索引全部数据时的提示信息

# /usr/local/coreseek/bin/indexer -c /root/coreseek-3.2.13/testpack/etc/csft.conf  --all

查看正常测试搜索时的提示信息

# /usr/local/coreseek/bin/search  -c /root/coreseek-3.2.13/testpack/etc/csft.conf

# /usr/local/coreseek/bin/search  -c /root/coreseek-4.1-beta/testpack/etc/csft.conf

查看正常测试搜索关键词时的提示信息

# /usr/local/coreseek/bin/search  -c /root/coreseek-3.2.13/testpack/etc/csft.conf -a 提供了搜索服务

# /usr/local/coreseek/bin/search  -c /root/coreseek-4.1-beta/testpack/etc/csft.conf -a 提供了搜索服务

4.3 搜索服务的启动与关闭

开启搜索服务

# /usr/local/coreseek/bin/searchd  -c /root/coreseek-3.2.13/testpack/etc/csft.conf

# /usr/local/coreseek/bin/searchd -c /root/coreseek-4.1-beta/testpack/etc/csft.conf

停止搜索服务

# /usr/local/coreseek/bin/searchd  -c /root/coreseek-3.2.13/testpack/etc/csft.conf --stop

# /usr/local/coreseek/bin/searchd -c /root/coreseek-4.1-beta/testpack/etc/csft.conf --stop

五、配置、测试mysql数据源搜索

5.1 准备mysql环境

sql测试数据路径

/root/coreseek-4.1-beta/testpack/var/test/documents.sql

创建test数据库

mysql>create database test;

导入sql测试数据

mysql -uroot -p123456 test < /root/coreseek-4.1-beta/testpack/var/test/documents.sql

拷贝mysql示例配置文件到coreseek安装目录

# cp /root/coreseek-4.1-beta/testpack/etc/csft_mysql.conf /usr/local/coreseek/etc/

修改上述配置文件的数据库主机地址,账号,密码等。

5.2 启动搜索服务

启动搜索服务,这里选择后台运行的方式

# /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf

以在log中记录每个查询的io和cpu状态的方式启动搜索服务

# /usr/local/coreseek/bin/searchd  --iostats --cpustats -c /usr/local/coreseek/etc/csft_mysql.conf

停止搜索服务

# /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf --stop

查看搜索服务状态

# /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf --status

5.3 本机搜索测试

# /usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/csft_mysql.conf -a 百度成立

停止mysql,观察以上本机搜索测试是否正常

# /etc/init.d/mysqld stop

启动mysql,观察以上本机搜索测试是否正常

# /etc/init.d/mysqld start

5.4 异机php客户端api调用测试

API路径:/root/coreseek-4.1-beta/testpack/api

拷贝test.php 和sphinxapi.php到支持php环境的机器,然后修改数据库地址,账号,密码等配置,测试如下:

# php test.php  中国

PHP Warning:  Module 'redis' already loaded in Unknown on line 0

Query '中国 ' retrieved 1 of 1 matches in 0.016 sec.

Query stats:

'中国' found 17 times in 1 documents

六、后期根据需求自定义返回数据格式

七、安装配置过程可能遇到的问题及解决方法

7.1 编译问题及解决方法

# sh buildconf.sh

aclocal.m4:20: warning: this file was generated for autoconf 2.64.

You have another version of autoconf.  It may work, but is not guaranteed to.

If you have problems, you may need to regenerate the build system entirely.

To do so, use the procedure documented by the package, typically `autoreconf'.

configure.ac:13: error: Autoconf version 2.62 or higher is required

aclocal.m4:518: AM_INIT_AUTOMAKE is expanded from...

configure.ac:13: the top level

autom4te: /usr/bin/m4 failed with exit status: 63

autoheader: /usr/bin/autom4te failed with exit status: 63

我的autoconf版本2.59

# yum list installed|grep autoconf

autoconf.noarch                          2.59-12                       i

解决方法:

手工编译安装autoconf-2.64 ,automake-1.11.2,(因aclocal.m4文件由autoconf 2.64生成)。

7.2 版本3.2.13生成索引的问题及解决方法

# /usr/local/coreseek/bin/indexer -c etc/csft.conf --all

Coreseek Fulltext 3.2 [ Sphinx 0.9.9-release (r2117)]

Copyright (c) 2007-2010,

Beijing Choice Software Technologies Inc (http://www.coreseek.com)

using config file 'etc/csft.conf'...

indexing index 'xml'...

Unigram dictionary load Error

Segmentation fault

解决办法:

# more /root/coreseek-3.2.13/testpack/etc/csft.conf

词典路径不对,修改实际安装字典路径,默认使用相对路径,建议使用绝对路径。

7.3 版本4.1生成索引的问题及解决方法

# /usr/local/coreseek/bin/indexer -c etc/csft.conf --all

Coreseek Fulltext 4.1 [ Sphinx 2.0.2-dev (r2922)]

Copyright (c) 2007-2011,

Beijing Choice Software Technologies Inc (http://www.coreseek.com)

using config file 'etc/csft.conf'...

indexing index 'xml'...

Unigram dictionary load Error

FATAL:  Tokenizer initialization failure.

解决办法:

# more /root/coreseek-3.2.13/testpack/etc/csft.conf

词典路径不对,修改实际安装字典路径,默认使用相对路径,建议使用绝对路径。

7.4 编译安装软件的小建议:编译安装完成后,不要删除源代码,不然无法unnistall

make的原理是执行一个叫Makefile文件里的指令,make的基本用处是自动根据makefile里的指令来编译源文件。它还可以用来做比如安装软件,卸载软件等事情,但前提是作者在makefile里写了。然后用make install的话,make程序就会按照上面install:后面的指令< commands >执行安装,uninstall也是一样的道理,大部分的作者会写有卸载的部分,这时只要简单地执行make unistall就可以,如果作者懒没有写,那就只有根据make install中的步骤,看它把什么文件拷到哪去了,然后分别手动删除。

还有关键的一点是,编译安装完成后,不要删除源代码,不然就算作者写了unnistall目标,你也没有makefile可以执行了。

7.5 make: Nothing to be done for `all' 解决方法

1.这句提示是说明你已经编译好了,而且没有对代码进行任何改动。
若想重新编译,可以先删除以前编译产生的目标文件:
make clean
然后再
make
2.出现这种情况解决方法:
a.make clean 清除安装时留下的文件
b.在运行一下ldconfig
c.再make 可运行出结果

7.6  error while loading shared libraries: xxx.so.x"错误的原因和解决办法

一般我们在Linux下执行某些外部程序的时候可能会提示找不到共享库的错误, 比如:
tmux: error while loading shared libraries: libevent-1.4.so.2: cannot open shared object file: No such file or directory
原因一般有两个, 一个是操作系统里确实没有包含该共享库(lib*.so.*文件)或者共享库版本不对, 遇到这种情况那就去网上下载并安装上即可.
另外一个原因就是已经安装了该共享库, 但执行需要调用该共享库的程序的时候, 程序按照默认共享库路径找不到该共享库文件.
所以安装共享库后要注意共享库路径设置问题, 如下:
1) 如果共享库文件安装到了/lib或/usr/lib目录下, 那么需执行一下ldconfig命令
ldconfig命令的用途, 主要是在默认搜寻目录(/lib和/usr/lib)以及动态库配置文件/etc/ld.so.conf内所列的目录下, 搜索出可共享的动态链接库(格式如lib*.so*), 进而创建出动态装入程序(ld.so)所需的连接和缓存文件. 缓存文件默认为/etc/ld.so.cache, 此文件保存已排好序的动态链接库名字列表.

2) 如果共享库文件安装到了/usr/local/lib(很多开源的共享库都会安装到该目录下)或其它"非/lib或/usr/lib"目录下, 那么在执行ldconfig命令前, 还要把新共享库目录加入到共享库配置文件/etc/ld.so.conf中, 如下:

# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
# echo "/usr/local/lib" >> /etc/ld.so.conf
# ldconfig

3) 如果共享库文件安装到了其它"非/lib或/usr/lib" 目录下, 但是又不想在/etc/ld.so.conf中加路径(或者是没有权限加路径). 那可以export一个全局变量LD_LIBRARY_PATH, 然后运行程序的时候就会去这个目录中找共享库.

LD_LIBRARY_PATH的意思是告诉loader在哪些目录中可以找到共享库. 可以设置多个搜索目录, 这些目录之间用冒号分隔开. 比如安装了一个mysql到/usr/local/mysql目录下, 其中有一大堆库文件在/usr/local/mysql/lib下面, 则可以在.bashrc或.bash_profile或shell里加入以下语句即可:

export LD_LIBRARY_PATH=/usr/local/mysql/lib:$LD_LIBRARY_PATH

一般来讲这只是一种临时的解决方案, 在没有权限或临时需要的时候使用.

4)如果程序需要的库文件比系统目前存在的村文件版本低,可以做一个链接
比如:
error while loading shared libraries: libncurses.so.4: cannot open shared
object file: No such file or directory

ls /usr/lib/libncu*
/usr/lib/libncurses.a /usr/lib/libncurses.so.5
/usr/lib/libncurses.so /usr/lib/libncurses.so.5.3

可见虽然没有libncurses.so.4,但有libncurses.so.5,是可以向下兼容的
建一个链接就好了
ln -s /usr/lib/libncurses.so.5.3 /usr/lib/libncurses.so.4

» 版权所有:YaoLei's Blog » Coreseek安装测试配置指南
» 本文链接:https://www.yaolei.info/archives/294