Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用程序更容易实现专业化的全文检索。Sphinx特别为一些脚本语言设计搜索API接口,如PHP,Python,Perl,Ruby等,同时为MySQL也设计了一个存储引擎插件

1因为sphinx需要mysql客户端进行测试,所以首先确保mysql-client已经安装,可以用rpm -qa|grep mysql-client进行检验

没安装的话挂载光盘安装rpm -ivh安装

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

cd coreseek-4.1-beta 

cd mmseg-3.2.14 

./bootstrap 

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

cd ..

./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 

cd /data/postmall/search/
ln -snf /data/postmall/repository/mmseg3 mmseg 

3下载sphinx,到官网下载并解压./configure --prefix=/data/postmall/repository/sphinx2/sphinx.{版本号} --with-mmseg-includes=/data/postmall/search/mmseg/include/mmseg --with-mmseg-libs=/data/postmall/search/mmseg/lib --enable-id64

make && make install

注意】如果在进行第3步make过程中报错,需要做以下更改,目的是引入mmseg的库文件和lib文件
修改src/Makefile
在以下俩项后添加
LIBS为LIBS=-L/data/postmall/search/mmseg/lib -lmmseg -lrt
CPPFLAGS为 CPPFLAGS=-I/data/postmall/search/mmseg/include/mmseg

4拷贝sphinx配置文件以及 mmseg生成的库文件至新目录
cd /data/postmall/search/sphinx2
cp mmseg.ini uni.lib /data/postmall/repository/sphinx2/sphinx.{版本号}
cp ./etc/* /data/postmall/repository/sphinx2/sphinx.{版本号}/etc/


5 停止API 的JAVA程序以及 增量推送程序searchBox{35 36} (注意 俩组类型不同,这里的操作也不同, 选择当前环境进行执行)
ps -ef|grep RTSE.Interface|awk '{print $2}'|xargs kill -9
ps -ef|grep searchb|awk '{print $2}'|xargs kill -9

5 停止API的TOMCAT以及增量推送程序 RTSE_Indexer (55 58 59)
ps -ef|grep tomcat1|awk '{print $2}'|xargs kill -9
ps -ef|grep RTSE_indexer|awk '{print $2}'|xargs kill -9

6 停止sphinx2 (注意 不同项目sphinx2后面的配置文件不同,主要是在启动命令后加--stop进行停止)
/data/postmall/search/sphinx2/bin/searchd -c /data/postmall/search/sphinx2/etc/psbc_score_mall_listing.conf --stop

7 做软连接 进行版本更新
cd /data/postmall/search,然后 ln -snf /data/postmall/repository/sphinx2/sphinx.{版本号}/ sphinx2


8启动sphinx2

/data/postmall/search/sphinx2/bin/searchd -c /data/postmall/search/sphinx2/etc/psbc_score_mall_listing.conf

9进行sphinx2功能检查

mysql -h0 –P 6906 // 检查连通性
mysql> show LISTING; //检查索引完整、存在
mysql> desc LISTING; // 检查索引结构
mysql> select * from LISTING; // 检查索引数据采样
mysql> select count(*) from LISTING; // 检查索引汇总功能
mysql> select * from LISTING where id = -1; // 选择一个未被占用的数值准备测试插入、删除,推荐-1
mysql> insert into LISTING (id) values(-1); // 检查索引可以insert
mysql> select * from LISTING where id = -1; // 检查索引可以insert后可select
mysql> delete from LISTING where id = -1; // 检查索引可以delete
mysql> select * from LISTING where id = -1; // 检查索引可以insert后可select
mysql>\q // 结束测试

10 启动api进程以及增量推送进程
35,36
====
/usr/local/jdk/bin/java -jar /data/postmall/repository/RTSE.Interface/RTSE.Interface.jar -k startService >/dev/null &

/usr/local/jdk/bin/java -jar /home/web/searchb/searchbox.jar -k maall >/dev/null 2>&1 &
====
55,58,59
~/t1_restart.sh
/usr/local/jdk/bin/java -jar /data/postmall/search/RTSE.Indexer/RTSE.Indexer.jar -k startService > /dev/null 2>&1 &