ubuntu 16.04 64位 coreseek
操作系统:ubuntu 14.04 64位
数据库:mysql
安装环境:
sudo apt-get install gcc g++ automake libtool mysql-client libmysqlclient-dev libxml2-dev libexpat1-dev mysql-server-5.6
安装升级autoconf
因为coreseek需要autoconf 2.65以上版本,所以需要升级autoconf,不然会报错
./bootstrap: 25: ./bootstrap: autoheader: not found
- automake --add-missing --copy
./bootstrap: 26: ./bootstrap: automake: not found - autoconf
./bootstrap: 27: ./bootstrap: autoconf: not found
从https://lists.gnu.org/archive/html/autotools-announce/2012-04/msg00004.html 下载,下载好autoconf-2.69.tar.gz后,安装如下:
tar -zxvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure
make
sudo make install
下载coreseek
新版本的coreseek将词典和sphinx源程序放在了一个包中,因此只需要下载coreseek包就可以了,这里我用的是coreseek 4.1版本
wget http://www.coreseek.cn/uploads/csft/4.0/coreseek-4.1-beta.tar.gz
或者
wget http://files.opstool.com/man/coreseek-4.1-beta.tar.gz
安装mmseg(coreseek所使用的词典)
apt install automake
cd mmseg-3.2.14
./bootstrap
./configure --prefix=/usr/local/mmseg3
make
sudo make install
cd ..
遇到的问题:
error: cannot find input file: src/Makefile.in
或者遇到其他类似error错误时...
解决方案:
依次执行下面的命令,我运行'aclocal'时又出现了错误,解决方案请看下文描述
sudo apt install libtool
aclocal
libtoolize --force
automake --add-missing
autoconf
autoheader
make clean
安装coreseek(sphinx)
ubuntu 16.04及以上版本需要打补丁,否则下面编译的时候会没有configure文件。补丁解决方案如下:
在 csft-4.1/buildconf.sh 文件中,查找
&& aclocal
后加上
&& automake --add-missing
在 csft-4.1/configure.ac 文件中,查找:
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
改为:
AM_INIT_AUTOMAKE([-Wall foreign])
查找:
AC_PROG_RANLIB
后面加上
AM_PROG_AR
在 csft-4.1/src/sphinxexpr.cpp 文件中, 替换所有:
T val = ExprEval ( this->m_pArg, tMatch );
成为:
T val = this->ExprEval ( this->m_pArg, tMatch );
安装libmysqlclient15-dev,否则会报找不到mysql
sudo apt-get install libmysqlclient15-dev
安装coreseek
cd csft-4.1
sh buildconf.sh #输出的warning信息可以忽略,如果出现error则需要解决
./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
make
sudo make install
cd ..
测试mmseg分词及coreseek搜索
cd testpack
cat var/test/test.xml #此时应该正确显示中文
/usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
/usr/local/coreseek/bin/indexer -c etc/csft.conf --all
/usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索
此时正确的应该返回
words:
1.网络: 1 documents, 1 hits
2.搜索: 2 documents, 5 hits
配置coreseek
创建配置文件 /usr/local/coreseek/etc/sphinx.conf,内容示例如下:
source app_source
{
type = mysql
sql_host = localhost # mysql的host
sql_user = user # mysql的账号
sql_pass = password # mysql的密码
sql_db = test # mysql的db
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
sql_query_pre = SET SESSION query_cache_type=OFF
sql_query =
SELECT id, text FROM words WHERE 1; # 需要搜索的数据表内容,此替换为自己的sql语句
}
index app
{
source = app_source # 跟上面定义的app_source对应
path = /usr/local/coreseek/var/log/app_source
docinfo = extern
mlock = 0
morphology = none
exceptions = /usr/local/coreseek/var/log/exceptions.txt
min_word_len = 1
charset_type = zh_cn.utf-8
charset_dictpath= /usr/local/mmseg3/etc
html_strip = 0
}
indexer
{
mem_limit = 512M
}
searchd
{
listen = 9312
log = /usr/local/coreseek/var/log/searchd.log
query_log = /usr/local/coreseek/var/log/query.log
read_timeout = 5
client_timeout = 300
max_children = 30
pid_file = /usr/local/coreseek/var/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 0
unlink_old = 1
mva_updates_pool = 1M
max_packet_size = 8M
max_filters = 256
max_filter_values = 4096
}
启动和管理coreseek
生成索引
sudo /usr/local/coreseek/bin/indexer --config /usr/local/coreseek/etc/sphinx.conf --all
重新生成索引
sudo /usr/local/coreseek/bin/indexer --config /usr/local/coreseek/etc/sphinx.conf --all --rotate
启动守护进程,启动后就不需要关闭
sudo /usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/sphinx.conf
关闭守护进程
sudo /usr/local/coreseek/bin/searchd --stop
加入开机启动
打开 /etc/rc.local ,添加启动代码
/usr/local/coreseek/bin/searchd --config /usr/local/coreseek/etc/sphinx.conf
定时更新索引
加入计划任务,半小时重建一次索引。
crontab -e
加入下面这句代码
*/30 * * * * /bin/bash /usr/local/coreseek/bin/indexer --config /usr/local/coreseek/etc/sphinx.conf --all --rotate