|
##################### 一 mariadb 安装 ##############
使用的是yum安装 略
#####################################################
##################### 二 php 环境搭建 ##############
使用的是yum安装 略
#####################################################
##################### 三 mmseg3 安装 ##############
1) 安装autoconf
[root@D1 software]# tar -jxvf autoconf-2.64.tar.bz2
[root@D1 software]# cd autoconf-2.64
[root@D1 autoconf-2.64]# ./configure
[root@D1 autoconf-2.64]# make
[root@D1 autoconf-2.64]# make install
2) 安装mmseg
[root@D1 software]# tar -zxvf coreseek-3.2.14.tar.gz
[root@D1 software]# cd coreseek-3.2.14
[root@D1 coreseek-3.2.14]# cd mmseg-3.2.14
[root@D1 mmseg-3.2.14]# ./bootstrap # 输出warning信息可以忽略 如果输出error信息则需要解决
[root@D1 mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg3 # 出现一个错误 config.status: error: cannot find input file: 'src/Makefile.in' 则 升级安装一些软件
[root@D1 mmseg-3.2.14]# yum -y install gcc gcc-c++ libtool autoconf automake imake libxml2-devel expat-devel # 升级安装一些软件
[root@D1 mmseg-3.2.14]# aclocal
[root@D1 mmseg-3.2.14]# libtoolize --force
[root@D1 mmseg-3.2.14]# automake --add-missing
[root@D1 mmseg-3.2.14]# autoconf
[root@D1 mmseg-3.2.14]# autoheader
[root@D1 mmseg-3.2.14]# make clean
[root@D1 mmseg-3.2.14]# ./configure --prefix=/usr/local/mmseg3
# 重新编译
[root@D1 mmseg-3.2.14]# make
[root@D1 mmseg-3.2.14]# make install ################################################################
#################### 四 安装coreseek #################
[root@D1 mmseg-3.2.14]# cd ../csft-3.2.14/
[root@D1 csft-3.2.14]# sh buildconf.sh # warning 信息可以忽略 error信息需要解决
[root@D1 csft-3.2.14]# ./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
[root@D1 csft-3.2.14]# make && make install ###########################################################
#################### 五 测试coreseek 分词 #################
[root@D1 coreseek-3.2.14]# cd testpack/
[root@D1 testpack]# cat var/test/test.xml # 此时应该正确显示中文
[root@D1 testpack]# /usr/local/mmseg3/bin/mmseg -d /usr/local/mmseg3/etc var/test/test.xml
[root@D1 testpack]# /usr/local/coreseek/bin/indexer -c etc/csft.conf --all
[root@D1 testpack]# /usr/local/coreseek/bin/search -c etc/csft.conf 网络搜索
words:
1. '网络': 1 documents, 1 hits
2. '搜索': 2 documents, 5 hits
# 返回上面的内容说明拆词成功 ############################################################
################## 六 配置coreseek数据源mysql ######################
1) 创建测试用数据库和数据表,做为coreseek的测试用的数据源
MariaDB [(none)]> create database test;
Query OK, 1 row affected (0.10 sec)
MariaDB [(none)]> use test;
MariaDB [test]> source /root/v9_news.sql; # 其中有两万多条数据 供测试
MariaDB [test]> show create table v9_news\G;
*************************** 1. row ***************************
Table: v9_news
Create Table: CREATE TABLE `v9_news` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`catid` smallint(5) unsigned NOT NULL DEFAULT '0',
`typeid` smallint(5) unsigned NOT NULL,
`title` varchar(120) NOT NULL DEFAULT '',
`style` char(24) NOT NULL DEFAULT '',
`thumb` varchar(100) NOT NULL DEFAULT '',
`keywords` varchar(60) NOT NULL DEFAULT '',
`description` mediumtext NOT NULL,
`posids` tinyint(1) unsigned NOT NULL DEFAULT '0',
`url` char(100) NOT NULL,
`listorder` tinyint(3) unsigned NOT NULL DEFAULT '0',
`status` tinyint(2) unsigned NOT NULL DEFAULT '1',
`sysadd` tinyint(1) unsigned NOT NULL DEFAULT '0',
`islink` tinyint(1) unsigned NOT NULL DEFAULT '0',
`username` char(20) NOT NULL,
`inputtime` int(10) unsigned NOT NULL DEFAULT '0',
`updatetime` int(10) unsigned NOT NULL DEFAULT '0',
`subtitle` varchar(120) NOT NULL DEFAULT '',
`lable` varchar(150) NOT NULL DEFAULT '',
`userid` int(10) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `status` (`status`,`listorder`,`id`),
KEY `listorder` (`catid`,`status`,`listorder`,`id`),
KEY `catid` (`catid`,`status`,`id`)
) ENGINE=MyISAM AUTO_INCREMENT=29471 DEFAULT CHARSET=utf8
1 row in set (0.00 sec) 2) 修改coreseek 的配置文件
[root@D1 testpack]# vim /usr/local/coreseek/etc/csft_mysql.conf
# 源定义
source news_src
{
type = mysql #####数据源类型
sql_host = localhost ######mysql主机
sql_user = root ########mysql用户名
sql_pass = 123456 ############mysql密码
sql_db = test #########mysql数据库名
sql_port = 3306 ###########mysql端口
sql_query_pre = SET NAMES UTF8 ###mysql检索编码,特别要注意这点,很多人中文检索不到是数据库的编码是GBK或其他非UTF8
sql_query = \
SELECT id, catid, keywords, title, description \
FROM v9_news ####### 获取数据的sql
sql_attr_uint = id ######## 无符号整数属性
sql_attr_uint = catid
sql_query_info = SELECT * FROM v9_news WHERE id=$id ######### 用于命令界面端(CLI)调用的测试
}
####### 索引定义 ##########
index news
{
source = news_src ####声明索引源
path = /usr/local/coreseek/var/data/news #######索引文件存放路径及索引的文件名
docinfo = extern ##### 文档信息存储方式
mlock = 0 ###缓存数据内存锁定
morphology = none #### 形态学(对中文无效)
min_word_len = 1 #### 索引的词最小长度
html_strip = 0
charset_dictpath = /usr/local/mmseg3/etc/ #BSD、Linux环境下设置,/符号结尾 分词库路径定义
charset_type = zh_cn.utf-8 #####数据编码
}
######### 全局index定义 ##############
indexer
{
mem_limit = 128M ####### 内存限制
}
###### searchd服务定义 ###
searchd
{
# listen = 9312 ### 监听端口,在此版本开始,官方已在IANA获得正式授权的9312端口,以前版本默认的是3312
log = /usr/local/coreseek/var/log/searchd.log
query_log = /usr/local/coreseek/var/log/query.log ### 客户端查询日志,笔者注:若欲对一些关键词进行统计,可以分析此日志文件
read_timeout = 5 ## 请求超时
max_children = 30 ### 同时可执行的最大searchd 进程数
pid_file = /usr/local/coreseek/var/log/searchd.pid #######进程ID文件
max_matches = 1000 ### 查询结果的最大返回数
seamless_rotate = 1 ### 是否支持无缝切换,做增量索引时通常需要
}
# 注 配置文件中源和索引都可以针对不同的数据库或不同的查询条件配置多个 #############################################################
######################## 七 coreseek服务管理 ###############
1 建立索引
[root@D1 testpack]# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all --rotate
2 启动后台服务
[root@D1 testpack]# /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf
3 执行增量索引
[root@D1 testpack]# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf delta --rotate
4 合并索引
[root@D1 testpack]# /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --merge main delta --rotate --merge-dst-range deleted 0 0
5 后台服务测试
/usr/local/coreseek/bin/search -c /usr/local/coreseek/etc/csft_mysql.conf 北京
6 关闭后台服务
/usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft_mysql.conf --stop
7 自动化管理
crontab -e
*/1 * * * * /bin/sh /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf delta --rotate
*/5 * * * * /bin/sh /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --merge main delta --rotate --merge-dst-range deleted 0 0
30 1 * * * /bin/sh /usr/local/coreseek/bin/indexer -c /usr/local/coreseek/etc/csft_mysql.conf --all --rotate ############ 八 安装php的sphinx扩展 #####################
1 安装libsphinxclient
[root@D1 sphinx-1.0.4]# cd /data/software/coreseek-3.2.14/csft-3.2.14/api/libsphinxclient/
[root@D1 libsphinxclient]# ./configure --prefix=/usr/local/sphinxclient
[root@D1 libsphinxclient]# make
[root@D1 libsphinxclient]# make install
2 安装 sphinx-1.0.4.tgz
[root@D1 sphinx]# cd /data/software/
[root@D1 software]# tar xvzf sphinx-1.0.4.tgz
[root@D1 software]# cd sphinx-1.0.4
[root@D1 sphinx-1.0.4]# yum -y install php-devel # 如果没有phpize则 安装phpize
[root@D1 sphinx-1.0.4]# phpize
[root@D1 sphinx-1.0.4]# ./configure --with-php-config=/usr/bin/php-config --with-sphinx=/usr/local/sphinxclient
[root@D1 sphinx-1.0.4]# make
# 如果出现错误信息 The test-suite requires that proc_open() is available. |
| Please check if you disabled it in php.ini.
出现上述错误信息,解决方法vi /data/conf/php.ini(即php的配置文件)找到disable_functions这一行 把proc_open去除即可 其他出现的错误信息则把相应的函数的禁止去除即可
[root@D1 sphinx-1.0.4]# make test
[root@D1 sphinx-1.0.4]# make install
Installing shared extensions: /usr/lib64/php/modules/ # 这一行显示sphinx.so模块已经被安装到/usr/lib64/php/modules/ 目录下
[root@D1 sphinx-1.0.4]# vi /data/conf/php.ini
添加
extension=/usr/lib64/php/modules/sphinx.so
[root@D1 sphinx-1.0.4]# service httpd restart (重启apache) ###################################################################
############# 九 php程序实现分词 #################################
1 查看当前环境是否已经支持sphinx
[root@D1 sphinx-1.0.4]# vim sphinx.php
通过浏览器访问
是否出现以下信息 (如果出现则说明sphinx的扩展已经安装成功)
sphinx
sphinx support enabled
Version 1.0.3
Revision $Revision: 294591 $
2) 编写测试代码测试
[root@D1 sphinx-1.0.4]# vim sphinx.php
访问后可得到数据
其中["matches"]字段中出现的内容就是在数据库中查找到的内容 查找的数据项如catid是在coreseek的配置文件中定义的。具体如下
[root@D1 testpack]# vim /usr/local/coreseek/etc/csft_mysql.conf
sql_attr_uint = id
sql_attr_uint = catid
其中matches 中每一条数据的下标志为id 是
sql_query = \
SELECT id, catid, keywords, title, description \
FROM v9_news
中select 中后面的第一个值
# 注 如果此时我们想重新建立索引会出现一个问题
FATAL: failed to lock /usr/local/sphinx/var/data/news.spl: Resource temporarily unavailable, will not index. Try --rotate option.
导致这个问题的原因是我在后台启动了coreseek,所以要先停掉 ################################################################
################## 十 sphinx 中类似mysql的一些特性 ##########
1) 限制条数,起始位置和索引源
vim sphinx2.php |
|
|