LNMP+coreseek(sphinx+mmseg3)搭建全文索引库_sgk

  1. 云栖社区>
  2. 博客>
  3. 正文

LNMP+coreseek(sphinx+mmseg3)搭建全文索引库_sgk

科技小能手 2017-11-12 02:07:00 浏览735
展开阅读全文

前言,为什么要安装LNMP,这个环境以及常用的MySQL+PHP搭建好了,初学者省去一部分精力调试错误而且LNMP已经很稳定很成熟。

一、 LNMP安装

下载http://lnmp.org/download.html

 

二、 Coreseek(sphinx+mmseg3)安装

注意:输出的warning信息可以忽略,如果出现error则需要解决,正常无回显 。

1. 下载coreseek-4.1-beta.tar.gz解压

http://dl.download.csdn.net/down11/20160530/de90462e2cf8350cbd4ad0f758105c9d.gz?response-content-disposition=attachment%3Bfilename%3D%22coreseek-4.1-beta.tar.gz%22&OSSAccessKeyId=9q6nvzoJGowBj4q1&Expires=1474603028&Signature=rLQ1RFgtXKUJmrbCwDJynFLmRi0%3D

 

# cd 

# wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz  

# tar zxvf coreseek-4.1-beta.tar.gz  

 

2. 安装mmseg3

# cd /opt/coreseek-4.1-beta/mmseg-3.2.14  

# ./bootstrap  

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

# make && make install  

 

遇到的问题:  

error: cannot find input file: src/Makefile.in  

或者遇到其他类似error错误时...  

 

解决方案:  

依次执行下面的命令,我运行'aclocal'时又出现了错误,解决方案请看下文描述

yum -y install libtool  

aclocal  

libtoolize --force  

automake --add-missing  

autoconf  

autoheader  

make clean  

安装好'libtool'继续从'aclocal'开始执行上面提到的一串命令,执行完后再运行最开始的安装流程即可。

 


 

3. 安装coreseek

# cd /opt/coreseek-4.1-beta/csft-4.1

# ./buildconf.sh

//下面参数里mysql路径一定要指定

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

# make && make install  

 

 

遇到的问题:  

at  -L/usr/local/lib -lrt  -lpthread

libsphinx.a(sphinx.o): In function `xmlUnknownEncoding':

/root/coreseek-4.1-beta/csft-4.1/src/sphinx.cpp:22292: undefined reference to `libiconv_open'

/root/coreseek-4.1-beta/csft-4.1/src/sphinx.cpp:22310: undefined reference to `libiconv'

/root/coreseek-4.1-beta/csft-4.1/src/sphinx.cpp:22316: undefined reference to `libiconv_close'

collect2: ld returned 1 exit status

make[2]: *** [indexer] Error 1

make[2]: Leaving directory `/root/coreseek-4.1-beta/csft-4.1/src'

make[1]: *** [all] Error 2

make[1]: Leaving directory `/root/coreseek-4.1-beta/csft-4.1/src'

make: *** [all-recursive] Error 1

 

解决方案:

修改MakeFile文件

#vi /opt/coreseek-4.1-beta/csft-4.1/src

157行左右增加一个-liconv参数,将

LIBS = -lm -lexpat -L/usr/local/lib

改成

LIBS = -lm -lexpat -liconv -L/usr/local/lib

wKiom1fmbtrTPqXCAABgXz71IZM203.png-wh_50 

 

4. 创建编辑配置文件。

# cd /usr/local/coreseek/etc
# cp sphinx-min.conf.dist csft.conf

 

修改下面内容,MySQ连接信息,其他默认。

 

source spdb1

{

    type                   = mysql

    sql_host                = localhost

    sql_user                = test

    sql_pass                = mima

    sql_db                  = test

    sql_port                = 3306

    sql_query_pre           = SET NAMES utf8

    sql_query               = SELECT `id`, 1 AS table_id, `username`, `email`, `password` FROM spdb1

    sql_attr_uint           = table_id         #SQL读取到的值必须为整数

    #sql_attr_timestamp     = date_added  #SQL读取到的值必须为整数,作为时间属性

    sql_query_info_pre      = SET NAMES utf8                                        #命令行查询时,设置正确的字符集

    sql_query_info          = SELECT * WHERE ID=$id #命令行查询时,从数据库读取原始数据信息

}

source spdb2 : spdb1

{

    sql_query = SELECT `id`, 2 AS table_id, `username`, `email`, `password` FROM spdb2

}

 

source spdb3 : spdb1

{

    sql_query = SELECT `id`, 3 AS table_id, `username`, `email`, `password` FROM spdb3

}

 

source spdb4 : spdb1

{

    sql_query = SELECT `id`, 4 AS table_id, `username`, `email`, `password` FROM spdb4

}

 

source spdb5 : spdb1

{

    sql_query = SELECT `id`, 5 AS table_id, `username`, `email`, `password` FROM spdb5

}

#index定义

index spdb1

{

    source            = spdb1    #对应的source名称

    path              = /usr/local/coreseek/var/data/spdb1 #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...

    docinfo           = extern

    mlock             = 0

    morphology        = none

    min_word_len      = 1

    ondisk_dict       = 1

    html_strip        = 0

    #中文分词配置,详情请查看:http://www.coreseek.cn/products-install/coreseek_mmseg/

    #charset_dictpath = /usr/local/mmseg3/etc/ #BSDLinux环境下设置,/符号结尾

    charset_dictpath = /usr/local/mmseg3/etc/ #Windows环境下设置,/符号结尾,最好给出绝对路径,例如:C:/usr/local/coreseek/etc/...

    charset_type        = zh_cn.utf-8

}

index spdb2 : spdb1

{

    source = spdb2

    path =  /usr/local/coreseek/var/data/spdb2

}

 

index spdb3 : spdb1

{

    source = spdb3

    path =  /usr/local/coreseek/var/data/spdb3

}

 

index spdb4 : spdb1

{

    source = spdb4

    path =  /usr/local/coreseek/var/data/spdb4

}

 

index spdb5 : spdb1

{

    source = spdb5

    path =  /usr/local/coreseek/var/data/spdb5

}

#全局index定义

indexer

{

    mem_limit            = 200M   #默认32M,不要太大,否则会报错

}

#searchd服务定义

searchd

{

    listen               = 9312   #查询服务监听端口,开启了才会工作

    read_timeout         = 5      #超时

    max_children         = 30     #最大进程

 

    max_matches          = 1000   #返回1000

    seamless_rotate      = 0

    preopen_indexes      = 0

    unlink_old           = 1

    pid_file = /usr/local/coreseek/var/log/searchd.pid #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...

    log = /usr/local/coreseek/var/log/searchd.log        #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...

    query_log = /usr/local/coreseek/var/log/query.log #请修改为实际使用的绝对路径,例如:/usr/local/coreseek/var/...

    binlog_path =                                #关闭binlog日志

}

5. 一些技巧:

rm -rf /usr/local/coreseek/var/data/*.*      //删除已生成的索引

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --all --rotate //生成所有索引

/usr/local/coreseek/bin/searchd --stop     //停止服务,重新生成前先停止

/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf //启动searchd服务

/usr/local/coreseek/bin/searchd --status   //查看状态

/usr/local/coreseek/bin/search 123456    //本机搜索

rm -rf /var/lock/subsys/mysqld   //Mysql易锁,删除锁定文件

单独生成每个表的索引

 /usr/local/coreseek/bin/indexer mydb6 -c /usr/local/coreseek/etc/csft.conf --rotate

 /usr/local/coreseek/bin/indexer mydb7 -c /usr/local/coreseek/etc/csft.conf --rotate  

更新增量索引

/usr/local/coreseek/bin/indexer delta -c /usr/local/coreseek/etc/csft.conf --rotate

合并2个表索引

/usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft.conf --merge mydb1 mydb2 --rotate --merge-dst-range deleted 0 0



参考文章:

http://www.111cn.net/database/mysql/87753.htm

http://blog.chinaunix.net/uid-20639775-id-3261834.html


本文转自 piazini 51CTO博客,原文链接:http://blog.51cto.com/wutou/1856189


网友评论

登录后评论
0/500
评论
科技小能手
+ 关注